Question

In: Computer Science

Write an algorithm for combining two skip lists in O(a + b) time, where a is...

Write an algorithm for combining two skip lists in O(a + b) time, where a is the number of keys in the first list, and b is the number of keys in the second list.

Solutions

Expert Solution


Solution:

Let the two lists to be combined be skip_list1[a],skip_list2[b].

The number of elements are a and b respectively in each list.

The algorithm that combines the two lists is as shown below.

The list 'res' has the combined elements from the lists skip_list1 and skip_list2.

Algorithm:

1. Start
2. Declare 'res' list of size a+b;
3. Declare j <- 0
4. for i = 0 to a
   BEGIN
       res[j] <- skip_list1[i]
       j <- j+1
   END
5. for i = 0 to b
   BEGIN
       res[j] <- skip_list2[i]
       j <- j+1
   END
  
6. Stop

  


Related Solutions

Write an algorithm to check equality of two link lists.(java)
Write an algorithm to check equality of two link lists.(java)
Write the algorithm and code that creates an array of link lists where the user determines...
Write the algorithm and code that creates an array of link lists where the user determines the number of rows and the number of nodes for each row. Needs to be in C++ language. IT IS DUE TONIGHT AT 11:59. HELP PLEASE Two-Dimensional Array Example: [0] [1] [2] [3] [0] 2 4 6 8 [1] 1 3 [2] 8 4 6 [3] 5
How to write Prim's Algorithm with min-Heap and adjacency Lists?
How to write Prim's Algorithm with min-Heap and adjacency Lists?
(15 pts) Describe an O(n)-time algorithm that partitions a doubly linked list L into two doubly...
(15 pts) Describe an O(n)-time algorithm that partitions a doubly linked list L into two doubly linked lists L1 and L2, where L1 contains the odd-number-th elements in L and L2 contains the even-number-th elements in L. Elements in both L1 and L2 should appear in the same order as they appear in L. For example, if L contains the numbers 4, 7, 9, 1, and -3, in that order, then the output L1 should contain 4, 9, and -3,...
Pseudocode and algorithm of merging k sorted list with running time O(Nlogk).
Pseudocode and algorithm of merging k sorted list with running time O(Nlogk).
a) Write Quick Sort and its function algorithm b) Derive the computation time for each statement...
a) Write Quick Sort and its function algorithm b) Derive the computation time for each statement in the algorithm. (You must explain your reason for each statement about how you get the answer of each computation time in at one or two sentences each.)
Given two lists, write python code to print “True” if the two lists have at least...
Given two lists, write python code to print “True” if the two lists have at least one common element. For example, x = [1,2,3], y=[3,4,5], then the program should print “True” since there is a common element 3.
Write a pseudocode function that interchanges two adjacent items of: (a) singly linked lists (b) doubly...
Write a pseudocode function that interchanges two adjacent items of: (a) singly linked lists (b) doubly linked lists if you can make it clean and short that be nice
In DrRacket Write a function, removeAll, which takes two lists, list-a and list-b and returns a...
In DrRacket Write a function, removeAll, which takes two lists, list-a and list-b and returns a list containing only the items in list-a that are not also in list-b. E.g., (remove-all '(a b b c c d) '(a c a)) -> '(b b d)
Describe an O(n)-time algorithm that checks if brackets in a given arithmetic expression is properly placed,...
Describe an O(n)-time algorithm that checks if brackets in a given arithmetic expression is properly placed, i.e., all left brackets are matched with their right counterparts and there are no unmatched brackets between any pair of matched brackets. Note that there are generally more than one types of brackets and only those of the same type can match against each other. For simplicity, you can assume that all operands are represented as ‘a’ and addition, +, is the only available...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT