{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Finalb

Finalb - CS 20 Final Exam Fall 2008 Analysis Recursion...

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

CS 20 Final Exam Fall 2008 Analysis /15 Recursion /25 Binary Search Trees /25 BST Implementation /20 Heaps /20 Heap Implementation /20 Sorting /11 Hash Tables /30 General /70 Total /236

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

View Full Document
Analysis: (15) Derive the big-O notation of the following snippets of code. Begin with the summation and end with the big-O notation. If you are unsure of the summation, you will still get partial credit if you give an explanation for your big-O notation answer. If you end up with a summation that is more complicated than what you are responsible for, just leave it in terms of the summation and do not solve for big-O notation. a)(5) for(i=1;i<n; i = i * 2) sum++; b)int recurse(int n) { if (n > 0) return( recurse(n-2) + n); else return 0; } e) int recurse(int n) { for(i = 0; i < n; i++) sum++; if (n > 0) return (recurse (n/2) + sum); else return 0; }
Recursion: (25) Here is the code for a linear search using iteration. Rewrite it below using recursion. int findElement(Comparable item, Comparable[] array) { for(int i=0;i<array.length;i++) if (array[i].compareTo(item) == 0) return i; return -1; } (5) What is the base case? (5) What is the recursive case? (10) Write the code (you may change the interface if necessary) (5) What is the computational complexity of the above solution? Give the big-O notation and the reason.

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

View Full Document
Binary Search Trees a) (5) What is the difference between a binary search tree and a heap, other than the names of the methods in the interface of the ADT?
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 11

Finalb - CS 20 Final Exam Fall 2008 Analysis Recursion...

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

View Full Document
Ask a homework question - tutors are online