





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This is the official worksheet for our midterm, which will be on Friday, February 4, 2000. ... ate data structures and algorithms would be.
Typology: Exams
1 / 9
This page cannot be seen from the preview
Don't miss anything!






This is the oÆcial worksheet for our midterm, which will b e on Friday, February 4, 2000. You are strongly encouraged to complete this worksheet. The midterm assumes that you are familiar with the content and style of these questions. You may also wish to lo ok at the unoÆcial worksheet handed out last section (see calendar in course web). It has more questions on op erations with data structures. Some questions on this worksheet may b e more op en-ended than on the midterm (esp ecially since we checked the worksheet a lot less than the midterm!). The midterm will have some op en- ended questions, though. Note that some diagrams may app ear on the next page, in order to keep diagrams in the right place in the text. You might need to lo ok at the next page sometimes to see the whole question.
1
Consider the following pseudo co de: function Erthelliant (int S; Ar r ay [1 : : : N ]) 1: X = 0 2: for i = 1 ; : : : ; N do 3: X = X + Ar r ay [i] 4: if X > S then 5: return i 6: end if 7: end for For the function Erthelliant, what is its:
2
Elsie the Cow is often very hungry. In order to help herself to organize her grazing time, she b ought a PDA (A \Ho of Pilot"). Unfortunately, she found that there isn't any software for the PDA that do es what she wants.
Elsie wants to organize her time by keeping a list of the tastiest grass, which she ranks from 1 to 100 (100 b eing \Mo o o ovelous"). As she discovers more grass, she needs to b e able to enter it into the PDA. One complication is interference from other grazing cows. Most other cows graze at certain lo cations on an hourly schedule. So, some grass may not b e available to her at certain hours of the day (e.g. 4-5 pm). So, she needs to b e able to enter which hours grass is available, and she may have to up date this information as she learns more ab out the schedules of the other cows. Whenever she's hungry, she wants to b e able to tap into her PDA. Her PDA should b e able to tell her the lo cation of the tastiest grass that she hasn't already eaten. The PDA should only tell her ab out grass that is available during the current hour.
3
Supp ose we have two algorithms. The rst algorithm takes o(n^2
n) time, while the second algorithm takes! (n^2 :^51 ) time. How big do es n have to b e b efore we can say anything ab out which algorithm is faster?
4
Give a tight worst case b ound ( notation) on the running time of the following co de: function Heapmin (A[1 : : : n]) : integer 1: Q = new 4-Heap 2: for i = 1 : : : n do 3: Q:Insert(A[i]) 4: end for 5: return Q:DeleteMin
5
Supp ose we wish to merge two Skew heaps.
You should:
ture.
op eration.
Your new data structure diagram should be a valid instance of the data structure you use to label it! Several data structures or op erations may match one picture, but only one assignment puts each data structure and each op eration with exactly one picture. So, use each data structure and op eration exactly once! For example, here is a solution for a 4-Heap picture. I have lab elled the picture as a 4-Heap, circled the problem no de, listed the op eration (p ercolate down) to x the problem, and drawn the new, problem-free 4-Heap.
percolate down
Now, here are the pictures (they start on the next page)...
1
2 1 3
2 5 26 2 5 19 8 2
12 13 15
15
14
7
10
12
3
4
10 Capitalist trees: trees with prop erties
Lab el the no des in the following tree with the following prop erties:
Also, indicate which of the following data structures this tree might represent:
2
(^3 )
6
(^29 )
18
9
29
4
NPL H B
NPL H B
NPL H B
NPL H B
NPL H B
NPL H B
NPL H B
NPL H B
NPL H B
NPL H B
11
Prof. Zara Wolfb one do es research in Comparative Languages at the University of Data in Struc- tures. She wants to nd out what are the most frequent words in di erent languages (like \a" and \the" in English). Then, she will compare the most frequent words in di erent languages. She hop es to discover fundamental similarities b etween di erent human languages. Her plan is to nd the most frequent words in a variety of works in di erent languages, ranging from all known works in electronic form, to individual authors in those languages (e.g. Shakesp eare, Lorca or Sun-Tzu). She also wishes to investigate individual short essays by p eople learning those languages as a second language. All works she will consider are already in electronic form. Prof. Wolfb one's current research grant is ab out to expire, so she needs something to help her quickly. Congratulations! You have b een selected to create a computer application to help in Prof. Wolfb one's research.