{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

homework01

homework01 - sum(b sum = 0 for(int i=0 i< N;i for(int j=0...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
University of Arizona CSc345 (Fall 2011; B. Moon) CSc 345 Homework Assignment #1 Problems 1. (20 pts) Write a recursive algorithm that returns the number of 1’s in the binary representation of an input integer N . Use the fact that this is equal to the number of 1’s in the representation of N/ 2, plus 1 if N is odd. 2. (20 pts) Let f i be the Fibonacci numbers as de±ned in class ( i.e. , f 0 = 0 , f 1 = 1 , . . . , f N = f N - 1 + f N - 2 ). Prove the following: N - 2 s i =0 f i = f N - 1 3. (20 pts) For each of the following program fragments, give the big-Oh analysis and justify your answer. (a) sum = 0; for(int i=0; i < N ;i++) for(int j=0; j < N*N ;j++)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: sum++; (b) sum = 0; for(int i=0; i < N ;i++) for(int j=0; j < i*i ;j++) for(int k=0; k < j ;k++) sum++; 4. (10 pts) Exercise 3.3 in page 85. 5. (10 pts) Determine the best asymptotic upper ( O ) and lower (Ω) bounds for each of the following functions, and justify your answer. (a) 3 n 5 + 5 n 2 + 3 n-1 (b) 2 n +5 (c) ∑ n i =1 i 2 6. (20 pts) Exercise 3.11 in page 86. Due date This assignment is handed out on Thursday Sep. 08, 2011, and due at 11pm on Monday Sep. 19, 2011. A total of 5 percent of your ±nal grade is allocated for this assignment. 1...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online