EXAM1_review - MORE REVIEW QUESTIONS FOR EXAM#1 1 An array...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
MORE REVIEW QUESTIONS FOR EXAM #1 1. An array contains the elements shown below. Using the binary search algorithm trace the steps followed to find 88. At each iteration, show the contents of low , high and mid . (Remember that mid = (low + high)/2 ) Answer: low = 0 high = 7 mid = 3 compared value: 26 low = 4 high = 7 mid = 5 compared value: 56 low = 6 high = 7 mid = 6 compared value: 88 8 13 17 26 44 56 88 97 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
2. int getvalue(int a, int b, int n) { int c,res; printf(“Entering: a= %d b=%d \n”, a, b); c = (a+b)/2; if (c*c <= n) res =c; else res = getvalue(a,c-1,n); printf(“Leaving: a = %d b=%d \n”,a,b); return res; } Call: getvalue(1,7,7); 3. void unknown1(int num) { printf(“%d”, num%2); if (num>0) unknown(num/2); } void unknown2(int num) { if (num>0) unknown2(num/2); printf(“%d”,num %2); } Try for unknown1(13) and unknown2(13). 4. Write a recursive function (in C) which will correctly print the first n odd integer numbers. You must define this function using only a single numeric parameter to be passed to the procedure. Assume that the initial call has the form: print_odd(n) where n indicates how many odd numbers are to be printed. For example, the call print_odd(6) would produce the following output: 1 3 5 7 9 11. Assume that n > 0.
Background image of page 2
5. You have developed an algorithm which is known to be O(n 2 ) and can solve a problem instance of size n = 40 in 4 minutes. Your boss has just given you a big problem to solve by the time the board of directors meeting begins at 3:00pm. If it is 2:30pm now and the big problem to be solved is of size n = 120, will you
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 06/12/2011.

Page1 / 8

EXAM1_review - MORE REVIEW QUESTIONS FOR EXAM#1 1 An array...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online