c17f06f

c17f06f - CSE 17 Final Examination Wednesday 20 December...

• Notes
• nizhes
• 6

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

CSE 17 Final Examination Wednesday 20 December 2006 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<SUGGESTED ANSWERS>>>>>>>>>>>>>>>>>>>>>> 1. For each of the questions below, assume the following data are processed in the given order: 11, 26, 64, 63, 76, 50. (a) Assume the data are entered into a binary tree, where balance is maintained using the algorithm discussed in class. Draw the tree after each number is added to the tree. (b) Assume the data are entered into a B-tree of order 1, where the tree is maintained as a B-tree using the algorithm discussed in class. Draw the tree after each number is added to the tree. (c) Assume the data are stored in an array of length 13 using the hash techniques discussed in class, where collisions are handled using a quadratic probe. Assume the number itself is the hash number. Show the status of the array after each number is added to the array. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< (a) 11 11 \ 26 11 26 \ -----> / \ 26 11 64 \ 64 26 / \ 11 64 / 63 26 / \ 11 64 / \ 63 76 26 63 / \ / \ 11 64 -------> 26 64 / \ / \ \ 63 76 11 50 76 / 50 (b) 11 11, 26 11,26,64 ---> 26 / \ 11 64 26 / \ 11 63,64 26 ---> 26 64 / \ / | \ 11 63,64,76 11 63 76 26 64 / | \ 11 50,63 76 (c) 0 1 2 3 4 5 6 7 8 9 10 11 12

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

-------------------------------------------------- 26 50 63 76 11 64 -------------------------------------------------- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 2. Suppose you have the problem of determining whether any two entries in an array are the same. Describe an algorithm for solving this problem and give the details of how to determine its complexity (how quickly the solution grows a function of the number of entries). <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Easy algorithm: boolean dup=false; int outer,inner; outer=0; while(!dup && outer<array.length-1) {inner=outer+1; while(!dup && inner<array.length) {dup=array[inner]==array[ouuter]; innner++; } outer++; } The most frequent operation is !dup. In the worst case, there are no duplicates. Let n=array.length. On the first pass of outer loop we repeat the inner loop n-1 times, the second pass n-2 times, ... Thus we have (n-1) + (n-2) + ... 1 =n(n-1)/2 repetitions. Thus we have O(n*n). Harder algorithm: Mergesort the array. Then apply boolean dup=false; int k=0; while(!dup && k<array,length-1) {dup = array[k]==array[k+1]; k++; } The most frequent operation is !dup, which occurs at most n times. The mergesort is O(n log(n))===> the complete algorithm is O(n log(n) ) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 3. (a) Describe in detail two different ways to implement a stack. Discuss the advantages and disadvantages of each implementation. (b) Assume you are to develop a class for each of the problems below.
This is the end of the preview. Sign up to access the rest of the document.
• Spring '08
• varies
• Array, public String toString

{[ 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