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

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

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
-------------------------------------------------- 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; {inner=outer+1; {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; {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.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/09/2008 for the course CSE 17 taught by Professor Varies during the Spring '08 term at Lehigh University .

Page1 / 6

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

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

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