Algorithm and DS Sample Exam
Algorithm and DS Sample Exam
1. Show the results of the following sequence of events, by drawing the state of the data structure:
add(4), add(8), add(1), add(6), remove(), remove()
where add and remove are the operations that correspond to the basic operations in the data
structure:
a. Stack
b. Queue (using circular array)
3. For each of the following scenarios choose the “best” data structure from the following list or a
combination of data structures: an unsorted array, linked list, stack, queue. In each case
a. Suppose that a grocery store decided that customers who come first will be served first
b. A list must be maintained so that any element can be accessed randomly
c. A program needs to remember operations it performed in opposite order
d. The size of a file is unknown. The entries need to be entered as they come in. Entries
must be deleted when they are no longer needed. It is important that structure has
flexible memory management
4. Write a pseudocode for an algorithm that determines the size of a linked list
5. What is the total number of swaps needed to sort the list of numbers given below using a
bubble sort?
6, 7, 3, 9, 2, 9, 3, 4, 2, 8, 8
6. Using the graph given above, the distance of node E is 0 and the distance of node A is 3. What is
average number of shortest distance required to find a node chosen at random
7. Determine the big-O of the following operations
a. Removing the 3rd node of a linked list
b. Averaging the values stored in a linked list
8. Write a pseudocode for an algorithm the number of redundant appearance of a given key as an
input if the data structures used is
a. An array
b. A singly linked list