EXAM1_review

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

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

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

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

View Full Document
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.
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.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern