Docsity

ECS 60 Midterm 1: Data Structures and Algorithms - Prof. Sean S. Davis, Exams of Computer Science

Toggle sidebar
bg1
ECS 60 Practice Midterm #1 (150 points)
1 (30 points) We expect quite short answers to these questions, i.e., two or three sentences each.
a) (15 points) In programming it is often best to copy an existing function that is similar to your new needs, and
then alter the copy to suit the new requirements. If I wanted a function to print out a range of numbers in reverse
order, which of the four traversals functions would you copy as a basis for the new function?
b) (15 points) This question applies to the timetest program. If File5.dat contained 2,500,000 insertions, how
would you change your program to be able to accommodate File5.dat? Would any ADT take more than ten times
as long on File5.dat as File1.dat (which contained 250,000 inserts)?
2 (46 points) The registrar keeps track of all the students (simply using their SIDs) on the wait lists for each course
(specified by their CRNs). As you know, the wait lists must keep track of the order of arrival of each request. There
are two reasons to be removed from a wait list: 1) The first person on the list is assigned to the class; or 2) A student
withdraws his/her request for the class associated with wait list. Insertions and deletions are frequent. Once a quarter
instructors have the wait list printed for their courses, but the registrar never tries to print out all of the wait list
students at the university. Assume there are M = 1000 courses, and an average of N = 10 students on each wait list.
Describe the data structure(s) you would use to satisfy these specifications most time efficiently. You may not use
hash tables. Justify you choices, using big-O notation where appropriate.
3 (10 points) In the following Skip List, draw and number sequentially the path that is checked in order to find(10).
Head 1 2 3 4 6 7 8 9 10 11 12 Tail
4 (15 points) Given the following 3-ary BTree with L = 3, draw the BTree that would exist after an insert(3).
53 98
5 53 98
19 64 99
34 87
5. (14 points) Assuming double hashing, a hash function h1 of key % TableSize, a hash function of h2 of key % 5 + 1,
and an initial TableSize of 7, show the hash table after each of the operations. Rehash when the load factor would
become greater than 0.5. Remember that the table size must always be a prime. Also fill-in the TableSize column.
Also quadratic probing, and linear probing are possible.
Operation Table
Size
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
insert 38 7
insert 21
insert 3
insert 20
delete 21
insert 2
insert 36
pf2

Partial preview of the text

Download ECS 60 Midterm 1: Data Structures and Algorithms - Prof. Sean S. Davis and more Exams Computer Science in PDF only on Docsity!

ECS 60 Practice Midterm #1 (150 points) 1 (30 points) We expect quite short answers to these questions, i.e., two or three sentences each. a) (15 points) In programming it is often best to copy an existing function that is similar to your new needs, and then alter the copy to suit the new requirements. If I wanted a function to print out a range of numbers in reverse order, which of the four traversals functions would you copy as a basis for the new function? b) (15 points) This question applies to the timetest program. If File5.dat contained 2,500,000 insertions, how would you change your program to be able to accommodate File5.dat? Would any ADT take more than ten times as long on File5.dat as File1.dat (which contained 250,000 inserts)? 2 (46 points) The registrar keeps track of all the students (simply using their SIDs) on the wait lists for each course (specified by their CRNs). As you know, the wait lists must keep track of the order of arrival of each request. There are two reasons to be removed from a wait list: 1) The first person on the list is assigned to the class; or 2) A student withdraws his/her request for the class associated with wait list. Insertions and deletions are frequent. Once a quarter instructors have the wait list printed for their courses, but the registrar never tries to print out all of the wait list students at the university. Assume there are M = 1000 courses, and an average of N = 10 students on each wait list. Describe the data structure(s) you would use to satisfy these specifications most time efficiently. You may not use hash tables. Justify you choices, using big-O notation where appropriate. 3 (10 points) In the following Skip List, draw and number sequentially the path that is checked in order to find(10). Head 1 2 3 4 6 7 8 9 10 11 12 Tail 4 (15 points) Given the following 3-ary BTree with L = 3, draw the BTree that would exist after an insert(3). 53 98 5 53 98 19 64 99 34 87

  1. (14 points) Assuming double hashing, a hash function h 1 of key % TableSize, a hash function of h 2 of key % 5 + 1, and an initial TableSize of 7, show the hash table after each of the operations. Rehash when the load factor would become greater than 0.5. Remember that the table size must always be a prime. Also fill-in the TableSize column. Also quadratic probing, and linear probing are possible. Operation Table Size

insert 38 7 insert 21 insert 3 insert 20 delete 21 insert 2 insert 36

  1. (15 points) Given the following AVL tree, draw a representation of the tree after an insert(10) operation has been executed. (You may wish to write intermediate tree(s) to ensure partial credit.) 5 2 12 3 8 15 7 11 14 19
  2. (20 points) Given the following splay tree, what would the tree look like after the deletion of 11 using a normal splay. (You may wish to write intermediate tree(s) to ensure partial credit. Rather than copying parts of the tree that remain the same from the previous intermediate tree, you may simply use dashed lines from the appropriate node to indicate that either the ancestors or descendants remain the same from the previous intermediate tree. However, your final tree must be complete, and not use any dashed lines.) 5 2 7 1 4 6 13 3 9 14 8 11 10 12