Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello can please kindly help me do these questions thanks you ! 1. [10 marks] Write in pseudo-code the sift down algorithm for a min-heap.

Hello can please kindly help me do these questions thanks you ! image text in transcribed
1. [10 marks] Write in pseudo-code the sift down algorithm for a min-heap. 2. 130 marks] In this problem, we investigate the use of a heap to implement a min-priority min-priority queue is a data structure that keeps track of a set of elements, each with iated key. An element's key is a value that indicates the priority of the element. An application example of a min-priority queue is a task scheduler. The items in the queue are tasks to be executed on a computer. Each task has an associated time of occurrence that serves as its key. The tasks are to be executed in order of their time of occurrence. Specifically, the computer needs to find the task with the minimum key, remove it from the min-priority queue, and execute it. As new tasks are created, the computer needs to insert them into the queue. A min-priority queue appropriately 0) Describe how you would use a min-heap to implement a min-priority queue. (i) A min-priority queue Q needs to support the following operations. For each operation, write its pseudo-code and determine its time complexity. Make sure that Q remains a min-priority queue after a call to each of these functions. (a) GetMin(O) : removes and returns the element of Q with the minimum key. (b) DecKeyValue(Q, i, k) : decreases the key value of element i to the new value k. (c) InsertKey(Q, k): inserts an element with key value k into Q. 3. [10 marks] We want to find the k smallest numbers in sorted order from a set of n numbers. Determine the worst-case complexity of each of the following methods in terms of n and k. (i) Sort all n numbers using heapsort, and list down the k smallest ones. (i) Build a min-priority queue and call GetMin k times

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Autonomous Database In Enterprise Architecture

Authors: Bal Mukund Sharma, Krishnakumar KM, Rashmi Panda

1st Edition

1801072248, 978-1801072243

More Books

Students also viewed these Databases questions