Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We wish to implement a data structure D that maintains the k smallest elements of an array A. The data structure should allow the following

image text in transcribed

We wish to implement a data structure D that maintains the k smallest elements of an array A. The data structure should allow the following procedures: . D -INITIALIZE(A, n, k) that initializes D for a given array A of n elem ents. TRAVERSE(D), that returns the k smallest elements of A in sorted order. PS 4, Page 1 . INSERT(D,x), that updates D when an element r is inserted in the array A We can implement D using one of the following data structures: (i) an unsorted array of size k; (ii) a sorted array of size k; (iii) a max-heap of size k. (a) (4 points) For each of the choices (i)-(iii), show that the INITIALIZE procedure can be per- formed in time O(nklogn procedure you can think of. (In particular, tell your procedure.) procedure you can think of. (In particular, tell your procedure.) b) (3 points) For each of the choices)ii), compute the best running time for the TRAVERSE c (5 points) For each of the choices (i)-(ii), compute the best running time for the INSERT

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

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions