Midterm Study Worksheet | Washington, Exams of Algorithms and Programming

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

2022/2023

Uploaded on 05/11/2023

kalia
kalia 🇺🇸

4

(7)

239 documents

1 / 9

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Midterm Study Worksheet
Monday, Jan 31, 2000
This is the oÆcial worksheet for our midterm, whichwillbeonFriday,February 4, 2000.
You are strongly encouraged to complete this worksheet. The midterm assumes that you are
familiar with the contentandstyle of these questions. You may also wish to look at the unoÆcial
worksheet handed out last section (see calendar in course web). It has more questions on operations
with data structures.
Some questions on this worksheet may be more open-ended than on the midterm (especially
since wechecked the worksheet a lot less than the midterm!). The midterm will havesomeopen-
ended questions, though.
Note that some diagrams may appear on the next page, in order to keep diagrams in the right
place in the text. You might need to look at the next page sometimes to see the whole question.
1
Consider the following pseudocode:
function
Erthelliant(int
S; Array
[1
:::N
])
1:
X
=0
2:
for
i
=1
;::: ;N
do
3:
X
=
X
+
Array
[
i
]
4:
if
X>S
then
5:
return
i
6:
end if
7:
end for
For the function Erthelliant, what is its:
1. Worst-case running time
2. Best-case running time
3. Average-case running time
2
Elsie the Cow is often very hungry. In order to help herself to organize her grazing time, she
boughtaPDA (A \Hoof Pilot"). Unfortunately, she found that there isn't anysoftware for the
PDA that does what she wants.
1
pf3
pf4
pf5
pf8
pf9

Partial preview of the text

Download Midterm Study Worksheet | Washington and more Exams Algorithms and Programming in PDF only on Docsity!

Midterm Study Worksheet

Monday, Jan 31, 2000

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:

  1. Worst-case running time
  2. Best-case running time
  3. Average-case running time

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.

  1. State the requirements of Elsie's application. What data will it store, what op erations do es it need to p erform, and what are the requirements on those op erations?
  2. Describ e 2-3 of the b est ways to design this application for Elsie, and what the appropri- ate data structures and algorithms would b e. Why do you think that these are the most appropriate data structures/algorithms?
  3. Of these options, pick one solution as the b est. Justify your decision in the context of the requirements.
  4. Write pseudo co de for some of the ma jor op erations in the application (you can assume that someone has already implemented the relevant data structures for you).
  5. What if Elsie wanted to b e able to share her information on available grass with her friend Beatrice the Cow? Sketch how this might change things.

3

Supp ose we have two algorithms. The rst algorithm takes o(n^2

p

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.

 Split

 Decrement end p ointer

You should:

 Write exactly one data structure and one op eration from these lists next to each data struc-

ture.

 Circle the problem in each data structure.

 Draw a picture of what each data structure lo oks like after xing its problem with its

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

4-Heap

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:

 NPL, the Null Path Length.

 H, the height.

 B, the balance.

Also, indicate which of the following data structures this tree might represent:

 Binary Search Tree

 AVL Tree

 B-Tree

 Splay Tree

 Stack

 Skew Heap

 Leftist Heap

 Queue

 d-Heap

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.

  1. De ne a set of requirements for Prof. Wolfb one's application. If some of the requirements are vague as describ ed, make an educated guess as to what she wants (justify your guesses).