Exam2-Herve-Solutions

.pdf

School

University of Maryland, College Park *

*We aren’t endorsed by this school

Course

351

Subject

Computer Science

Date

Feb 20, 2024

Type

pdf

Pages

11

Uploaded by SargentClover11186

CMSC351 Fall 2022 Exam 2 Herv´ e’s Solutions NAME (Neatly): UID (Neatly): Instructions: Please do all problems on the pages and in the spaces provided. This exam will be scanned into Gradescope and if your answers are not in the correct locations they will not be found or graded!
. THIS PAGE INTENTIONALLY LEFT BLANK! DO NOT USE!
1. Fill in the following as True or False . Any answers that are unclear will be marked as [10 pts] incorrect. Statement True/False Quick Sort is worst-case Θ( n 2 ). True Merge Sort is best-case Θ( n ). False The Master theorem possibly applies to T ( n ) = T ( n 10) + 8 False If T ( n ) = T ( n 1) + 1 and T (0) = 1, then T ( n ) = Θ( n ) True Tree Sort is another comparison-based sorting algorithm; its worst case running time is Θ( n ) False 2. We are trying to apply the Master theorem to T ( n ) = T (3 n/ 4) + n + 7 What are the values [6 pts] for a , b and f ( n )? a 1 b 4/3 f ( n ) n + 7 3. Using a 1-indexed array representing a heap, fill in the 4 values below [8 pts] parent index left child index right child index 22 44 45 2 99 2 100 2 100 + 1
4. An algorithm has the following formula for its running time: T 1( n ) = 3 T 1( n/ 3) + n T 1(1) = 1 (a) If we try to apply the Master theorem, what would be the values of a , b , and f ( n )? [3 pts] Solution: a = 3, b = 3, f ( n ) = n (b) Use the Master theorem to find the Θ of T 1( n ). Show your work. [8pts] Solution: log b a = log 3 3 = 1 Case number 1? Is f ( n ) = n = O ( n c ) for some c < 1? No; we are not in case number 1 Case number 2? Is f ( n ) = n = Θ( n 1 ) ? Yes. We are in case number 2. T ( n ) = Θ( n lg n ).
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help