Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

a) If a heap is used to represent a priority queue, and the first element is removed, the heap property is restored by moving the

a) If a heap is used to represent a priority queue, and the first element is removed, the heap property is restored by moving the last element to the root of the tree, and then running MAX-HEAPIFY on the new root element. What is the worst-case complexity of restoring the heap property in this way?

b) The first step of the heapsort algorithm converts the input array into a max heap using a function called BUILD-MAX-HEAP. Surprisingly, the worst- case complexity of this function is linear in the size n of the input array.

c) Consider a large, unsorted file of records that contains many duplicates of the same records. (One record is a duplicate of another if it has the same record number.) Consider the problem of removing all of the duplicates, so that the file contains a unique copy of each record. Describe a simple algorithm that removes all duplicates and runs in O(n log n) time, where n is the number of records in the file.

d) Consider the following recurrence: T (n) = 3T(n/2) + n. Indicate which case b of the Master theorem applies (first, second, or third), and solve the recurrence.

 

The following recursive algorithm finds the sum of all elements in an array using a divide and conquer strategy. func sumArray(A, low, high) if low > high return 0 if low = high %3D return A[low] mid

Step by Step Solution

3.45 Rating (161 Votes )

There are 3 Steps involved in it

Step: 1

Part a The worst case time complexity to restore the heap property is Ologn because at a time it wil... 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

Cambridge IGCSE Computer Science Coursebook

Authors: Sarah Lawrey, Donald Scott

1st Edition

1107518695, 978-1107518698

More Books

Students also viewed these Accounting questions

Question

Copy and complete the statement. 3800 m ? km =

Answered: 1 week ago

Question

Explain what is meant by an automatic backup.

Answered: 1 week ago

Question

What enables a Blu-ray disk to hold more data than a compact disk?

Answered: 1 week ago