# 15 pts consider sequences of queue operations each

• Notes
• 3

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

5. (15 pts) Consider sequences of queue operations, each operation being an enqueue or a dequeue. We assume that the sequences are such that the empty queue exception is never thrown. Let M be a function that, given such a sequence s of queue operations, computes the minimum initial size of the array in which we implement the queue, such that the whole sequence s of operations can be performed without having to increase the size of the array. Give the pseudocode for M in two cases: (a) The simple array implementation which suffers from the problem of drift. (b) The circular array implementation. 6. (20 points) static int foo(char[] a) { for (int j = 2; j < a.length; j = j*j ) a[j] = ’z’; return (a.length * a.length * a.length); } static void bar(char[] b) { for (int i = 1; i < foo(b); i=2*i) b[i]=’z’; } Analyze the worst-case running time of bar(b) as a function of n = b.length and give a Big-Oh bound. 7. (15 pts) (a) Draw a binary search tree with integer keys such that when we traverse the tree in postorder we obtain 3 , 5 , 6 , 4 , 8 , 9 , 7. (b) Draw an AVL binary search tree with integer keys such that when we traverse the tree in postorder we obtain 3 , 5 , 6 , 4 , 8 , 9 , 7. 8. (20 pts) Consider the following code fragment involving recursive calls: public static long fob (int n) { if (n <= 17) return n; else return fob(n-1) + gob(n-1) + 11; } public static long gob (int n) { if (n <= 13) return n; else return fob(n-1) + 7; } 2

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

This is the end of the preview. Sign up to access the rest of the document.
• Fall '09
• TANNEN

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