{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Exercise1_Solution_Part1

Exercise1_Solution_Part1 - Solutions to Quiz 1 “Points...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Image of page 1

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

View Full Document Right Arrow Icon
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Solutions to Quiz 1 “Points for a problem are generally equally divided among problem parts. Answers needn‘t be as oomplete as here: we give liberal partial credit for showing understanding of ideas.” Problem 1 [2!] points] Give asymptotiosiiy tight upper [big 0] bounds for Tin] in each of the fol- lowing recurrences. Justify your solutions by naming the particular case of the master theorem, by iterating the recurrence, or by using the substitution method. a. Tin] = Tfrt- 2} + 1. Answer: Tm} = 01:11.] by iteration: Gin} terms Tm} = m = om; b. Tin} = 2T{n{2} +_n lg“ :1. Answer: Th} 2 Din [3‘3 n) [or Biznlganjj by master theorem, case 2 {as generalized in Exercise 4.4-2]. c. Tm} = 91"{112'4} + 11*. Answer: flux} = Cling} {or Shah by master theorem, case 3. d. Tin] = 3T{nf2:l + 11.. Answer: Tin} = Din“: a} {or Ei{n'°h 3}} by master theorem, case 1. e. Tin} = lenf'E + fl} + :1. Answer: Tin} = Din} by substitution. {To make the guess, notice that when n is large, 11,52 + q? is close to nil so 0(a) is a reasonable guess, based on master theorem case 3.] Show Th] 5 art by induction: - Initially true {for small a] if .1: large enough. {{Note that you actually have to assume '1" is constant for n 5 4, since TH} = T{4,{2 + oi} + 4 = m} + 4.)} . Assume true for numbers 6. n. Then flu} = This + fl} + n 5 onfl + cfi+ :1 With a little aLg‘ebi-s.1 can see that this is 5 on for large enough a and 4:: (es. e = 4,1: 316}. Problem 2 [20 points] Consider the code for BUILD-HEW. which operates on a heap stored in an array AI]. . .11]: BUTLD- HEAPIEA] 1 heep-eize[A] :— long-tithe] ‘2 for t‘ +— Liertyth[A]g'2] domto l 3 do HEAPIFYIIAJ} a. Show how this procedure can be implemented as a recursive divide-end— conquer procedure BUILD-HEAPIIIA. i}, where Ah] is the root of the suhheep to be built. To build the entire heap1 we would call BUILD~HEAPL£L 1}. Answer: BUILDrHEAPEA. t} Hi 5 [tangmmytj c or :- 5 3:119:ij then EU]LEI-HEAP{A, 2i) ELIILD- HEAPLJL it + 1} HEAPIFYM. t} 1:. Give a recurrence that describes the worst-csse running time of your pro- went-there+ Answer: Tin) = ZTfinffll + G'flgnj o. Solve the recurrence using the master method [or otherwise for partial credit]. Answer: The} = 9(a) by case 1 of master theorem Problem 3 {2D points] Give a short answer for each problem below. The more concise and precise your answer, the more points you will receive. a. Prose that [n + 1]2 = 01:71:} by giving the constants up and c in the definition of {SJ-notation. Justify your answer. Answer: c = 2.1% =3 Need [n+1}25m2fur aJlnEng. {n+1}2 5 seine-n+1; a“. which is true for n :3 a. b. Suppose that you want to sort n numbers, each of which is either [I or 1. Briefly describe an asymptotically eficient algorithm for this problem. What is its running time?I Answer: Counthtg sort. 0(a) time (actually. Biol} Gr partition around any element. c. Briefly describe what we mean by a randomized algorithm, and name two examples. Anstver: Behavior determined in part by random-number generator. E.g. randomised quicksort {Section 5.3} randomised select {Section 10.2] ship lists [Lecture 1E1] universal hashing {Section 12.3.3} randomized partition [Section 3.3] d. Consider a priority queue that supports the operations INssa'r and Earmar— lvllx. Argue that in the worst case. if we perform a rnixturs of r: Insane" and ExTRACT~MIN operations on the priority queue. there is at least one operation that takes flflg n] time. Assume that the order of elements in the priority queue is determined by comparisons only. (Hint: For any est of numbers. at least one number must equal or exceed the average.) Answer: Can sort nfl numbers by doing of? Insssrs and of! ExTRaCT- Mme [n operations all together}. But comparison sorts take flfnlg n} time, in this case n n a (5133) mean} The average time for this set of n operations {and hence for the Worstease mix of r: operations] is thus flflgn). so at least one takes i'tflgn} time. ...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern