CS 1501

Here are some sample problems for the Final Exam. Note that these are by no means the only types of problems that will be on the exam, nor do they cover all of the material that will be on the exam (you should study everything indicated on Syllabus and Algorithms links). Furthermore, since the exam is (partially) cumulative, you should look over the Exam 1 practice questions as well.. Try not to look at the solutions until after you have given each problem a good try.

________________________________________________________________________________

1) Consider the following array that depicts a Max-Heap (highest priority is largest value) implementation of a Priority Queue:

Index

1

2

3

4

5

6

7

8

9

10

Value

100

60

80

20

50

70

30

5

15

40

a) Show the resulting array after a single call of the remove() (deletemax) function.

b) State two algorithms that we have discussed in which a priority queue figures prominently. Explain its role in each of the algorithms.

________________________________________________________________________________

2)

I can represent a graph using either an adjacency list or an adjacency matrix. Explain what each is and when (if at all) each is preferable.

________________________________________________________________________________

3)

The text uses Priority First Search (PFS) for both the MST and Shortest Path algorithms (using an adjacency list). Explain the difference between the algorithms, and why PFS can be used for both.

_________________________________________________________________________

4)

In the Karp-Edmonds algorithms for finding network flow, once an augmenting path is found, the flow values of the edges are updated to reflect the additional flow. Write the C++ code segment that does this update. Assume that the graph has V vertices, that flow[x][y] represents the current flow from vertex x to vertex y, that the val[] array contains the amount that the flow will be augmented, that the dad[] array contains the path from the sink back to the source, and that V is the sink vertex.


5)

Assume you want to save time and (you hope) space with your Huffman code by using a standardized tree, rather that one tailored to each file. In this way you can incorporate the frequencies directly into your algorithm as constants, rather than having to put them in the front of your encoded file. Furthermore, you do not have to count the frequencies in each file, so you can encode in 1 pass rather than two. It seems like this is a great idea, but maybe it isn't. Explain what, if anything, may be bad about your variation.


6)

Fill in the blank

a) The N in NP-complete stands for _____________________.

b) If I use 16-bit codewords in LZW compression, the early codewords will actually cause _____________________, since they will be encoding _______________ character(s) using 16-bits.

c) The Ford-Fulkerson technique to finding maximum flow involves improving a previous flow value by finding a(n) _____________________________ to the flow.

d) The simple exhaustive search Traveling Salesman Problem algorithm must consider all _____________________ of the vertices in the graph, since each represents a different possible tour.

e) Given a TSP tour ABCDEA, the 2-opt heuristic will "swap" edges (A, B) and (C, D) by actually removing (A, B) and (C, D) from the tour and replacing them with _______________ and __________________.