csi04 sol - CSI2114 Fall 2004 Midterm Exam University of...

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

CSI2114 - Fall 2004 - Midterm Exam University of Ottawa School of Information Technology and Engineering Date: Sunday October 24, 2004 This is a closed books exam. No calculators allowed. You have 2 hours to ﬁnish. Answer in the spaces provided. There are 30 marks available in total. Good Luck! NAME: STUDENT NUMBER: SECTION: Page Marks of each page PAGE 2 out of 7 PAGE 3 out of 8 PAGE 4 out of 6 PAGE 5 out of 6 PAGE 6 out of 3 BONUS TOTAL out of 30 1

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

View Full Document
Some summations you might need: n i =0 i = n · ( n +1) 2 , n i =0 a i = a n +1 - 1 a - 1 , n i =1 log n = O ( n log n ), n i =1 i · 2 - i < 2 Question 1 [1 point] What is the running time complexity of the following Algorithm (in big-Oh notation) ? Algorithm Hello(A). Let A be an array of size n . for i 0 to n - 1 do for j n - 1 to i do A [ i ] A [ i ] + A [ j ] a) O (log n ) b) O ( n ) c) O ( n log n ) ? d) O ( n 2 ) Why? (Here not required for full marks) You can count the number of executions of the inner loop for each step in the outer loop: n +( n - 1)+( n - 2)+ . . . +1 = n k =1 k = n +1 2 n = O ( n 2 ) Or, you could turn the loops directly into sums: n - 1 i =0 n - 1 k = i 1 = n - 1 i =0 n - i = n +1 2 n = O ( n 2 Question 2 [3 points] Fill the blanks below: (for each question, give the best possible big-Oh). 3 n 2 + 2 n + 5 n 3 is O ( n 3 ) 3 n 2 + n log n + 1 n 3 is O ( n 2 ) 30 n 2 + 2 n + n 8 is O (2 n ) Question 3 [1 point] Which of the following functions grows fastest? ? a)
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 6

csi04 sol - CSI2114 Fall 2004 Midterm Exam University of...

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

View Full Document
Ask a homework question - tutors are online