

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


ECS 60 Practice Midterm #1 Key 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? InorderTraversal(). 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)? Both the QueueAr and StackAr constructors would have to be initialized to some value larger than 2,500,000. The skip list would take slightly more than 10 times as long. 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. Justify you choices, using big-O notation where appropriate. First, note that there are only M*N = 10000 entries with 9 chars per entry. This is small enough to fit in RAM, so there is no need for a B-Tree. Second, note that the number of students waiting for each course are so small that the difference between log n and n is negligible. Finally, because of the need to delete from positions other than the first position, queues are eliminated. Based on these facts I would use a splay tree of lists to store the information. The splay tree keys would be the CRNs, and each node would contain a list of waiting mainted in FIFO order. Insertions would be placed at the end of the list and take O(N + log M) time. Deletions for enrolled students would take O(log M) for linked list implementations and O(N + log M) for array implementations. Deletions for students that just give-up would take O(N + log M) time for both implementations. To print a wait list would take O(N + logM) time for both implementations. 3 (10 points) In the following Skip List, draw and number sequentially the path that is checked in order to find(10). 1 2 3 4 Head 1 2 3 4 6 7
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 -- 53 98 19 -- 98 -- 5 53 98 3 19 53 98 19 64 99 5 34 64 99 34 87 87
Pts insert 38 7 3 8
insert 21 7 2 1
insert 3 7 2 1
insert 20 17 3 2 1
delete 21 17 3 2 0
insert 2 17 2 3 2 0
insert 36 17 2 3 3 6