Docsity

CSC 517: Algorithms Midterm Exam October 2006 - Prof. B. Rosenberg, Exams of Computer Science

Partial preview of the text

Download CSC 517: Algorithms Midterm Exam October 2006 - Prof. B. Rosenberg and more Exams Computer Science in PDF only on Docsity!

Burton Rosenberg

Midterm October 9, 2006. 11:15–12:05 PM

There are five problems each worth five points for a total of 25 points. Show all your work, partial credit will be awarded. Space is provided on the test for your work; if you use a blue book for additional workspace, sign it and return it with the test. No notes, no collaboration.

Name:

Problem Credit

Total

  1. Consider the following code,

sum = 0 for i = 1 to length(A) sum = sum + A[i] end for

Write a loop invariant which shows that this code correctly calculates the sum of the values stored in A[1], A[2], ... A[n]. Prove correctness using the invariant.

  1. Show the result of Build-Max-Heap when run on the following array. (Show several intermediate steps.)

13 16 14 15 1 8 7 3 9 10

  1. When you are one year old, one candle is lit for your birthday. When you are two years old, two candles are lit. When three, three candles, and so forth. By your 80-th birthday, what is the total number of candles lit for all your birthdays combined, including the 80 candles for this birthday.