Question
You are given two sorted lists of size $m$ and $n .$ Give an $O(\log m+\log n)$ time algorithm for computing the $k$ th smallest element in the union of the two lists.
Step 1
First, we need to find the median of each list. We can do this by finding the middle element of each list. If the length of the list is odd, the middle element is the median. If the length is even, we can take the average of the two middle elements as the median. Show more…
Show all steps
Your feedback will help us improve your experience
James Kiss and 55 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Recommended Videos
Assume you are given two linear lists of size n each; consider the problem of determining whether any element of one list is an element of the other (not value, element!!). (a) Derive a lower bound for this problem. (b) Design an algorithm for this problem. Derive its time complexity. It should be as close to your lower bound as possible.
Suppose there are $\log \mathrm{n}$ sorted lists of $[\overline{\log n}]$ elements each. The time complexity of producing sorted lists of all these elements is: (hint: use a heap data structure) (A) $\theta(n \log \log n)$ (B) $\theta(n \log n)$ (C) $\Omega(n \log n)$ (D) $\Omega\left(n^{3 / 2}\right)$
Programming and Data Structures
Sorting Algorithms
Give an $O(n \lg k)$ -time algorithm to merge $k$ sorted lists into one sorted list, where $n$ is the total number of elements in all the input lists. (Hint: Use a minheap for $k$ -way merging.
Heapsort
Priority queues
Transcript
Watch the video solution with this free unlock.
EMAIL
PASSWORD