Offered a maximum focused binary heap, build a formula to determine if the kth largest object is actually higher than or comparable to x
- Max-oriented top priority queue with minute. What is the purchase of growth of the run time to see a minimum type in a maximum-oriented binary pile.
Max-oriented priority queue with min. Layout a data means that helps put and remove-the-maximum in logarithmic time alongside both maximum an min in continual opportunity.
Option. Build a max-oriented binary pile but also put the minimum key put to date (that may never enrich unless this heap gets bare). kth premier item higher than x.
Solution: if the input the node are more than or comparable to x, recursively lookup both left subtree additionally the proper subtree. Quit as soon as the number of node investigated is equal to k (the solution are indeed) or there are not any even more nodes to explore (no). kth minuscule item in a min-oriented digital heap. Layout a k wood k formula to obtain the kth minuscule product in a min-oriented digital heap H containing n products.
Their algorithm should run in opportunity proportional to k
Option. Develop a unique min-oriented heap H’. We will maybe not adjust H. Insert the main of H into H’ together with the pile index 1. Now, continuously remove minimal object x in H’ and put into H’ the 2 kids of x from H. The kth item removed from H’ could be the kth minuscule product in H.
Given an optimum driven digital heap, style a formula to determine perhaps the kth biggest item is greater than or corresponding to x
- Randomized waiting line.