quiz1s

quiz1s - 45, -128, 404, -152, 97, 232, 185, 49 (b) You are...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Design and Analysis of Algorithms Sample Quiz I Time: 30 Minutes Points: 10 NAME: Student ID: 1. 3 points What is the runtime of Mergesort on an array A of length n when the input is a worst-case instance? What if the input is already sorted in increasing order? 2. 3 points Suppose that, in a divide-and-conquer algorithm, we always divide an instance of size n of a problem into 2 subinstances of size n/ 4 , and the dividing and combining steps take n 2 time. Write a recurrence equation for the running time T ( n ) , and present your solution for T ( n ) in order notation. Assume that T (1) = 1 . You may assume that n is a power of 4.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3. 4 points (a) What is a heap? What property of a heap is useful for sorting? Arrange the following numbers as a heap. Draw the binary tree representing the heap.
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 45, -128, 404, -152, 97, 232, 185, 49 (b) You are asked to Fnd the k-th largest element among the given numbers, a 1 , , a n . How fast can you Fnd the k-th largest element using a heap? Express worst-case running time in terms of k and n . Assume that your input already satisFes the heap property. 4. Extra Credit: 2 Points Suppose that you are given a sorted sequence of distinct inte-gers { a 1 , a 2 , , a n } in an array representation. Give an O (lg n ) algorithm to determine whether there exists an index i such that a i = i . or example, in {-1 , , 2 , 4 , 6 , 19 } , we have a 4 = 4 for i = 4 . In { 3 , 6 , 9 , 15 , 17 } , there is no such i ....
View Full Document

Page1 / 2

quiz1s - 45, -128, 404, -152, 97, 232, 185, 49 (b) You are...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online