CS 1501 Previous Final Exam

The following exam was given in a previous term of CS 1501.  Use it as a guide for the types of questions that you may see on this term's final exam, and for the content of some of the questions.  However, since the material is not covered in the same order from term to term, there may be some material on your final exam that is not covered in the exam below (and vice versa). [For example, integer algorithms and encryption are not on this exam – see the Quiz 2 Solution for example problems on these topics].  To ensure that you study all pertinent material, refer to the Online Syllabus, the Online Notes and your hand written notes.  Recall that the exam is cumulative for the ENTIRE TERM.  However, significant emphasis will be placed on the material since the midterm exam (below MIDTERM EXAM on the online syllabus).

 

After giving the questions below a good try, take a look at the solutions to see how you did.

 

For all questions, be sure to show your work.  Answers without work will not receive full credit.

1)      (20 points – 2 points each) Fill in the Blanks. Complete the statements with the MOST APPROPRIATE word(s) and/or phrase(s).

 

a)      In order to save space in the hash table storing dictionary entries for the LZW compression algorithm, rather than storing the entire string in the hash table, we instead store a(n) _________________________  and a(n) _________________________ that together indicate the string with a constant amount of space.

b)      During BFS and PFS, some vertices are on the fringe, which means that __________________________ ________________________________________________________.

c)      DFS on a graph with V vertices and E edges runs in time ___________________________ with an adjacency list and in time __________________________ with an adjacency matrix.

d)      A graph G is said to be biconnected if _____________________________________________________.

e)      The only difference between Prim's MST algorithm using PFS and Djikstra's Shortest Path algorithm using PFS is ______________________________________________________________.

f)       A sequence of N Inserts followed by N DeleteMins on a sorted array will have a total run-time of Theta(_____________________________).

g)      A sequence of N Inserts followed by N DeleteMins on a min-heap will have a total run-time of Theta(_____________________________).

h)      One rule for a valid flow in a network graph is: For All (u,v) in V, f(u,v) =  –f(v,u).  This means ____________________________________________________________________________.

i)        The Ford-Fulkerson solution to the Network Flow problem involves finding a(n) __________________ _________________________ for the network, updating the residual network, and repeating until no ________________________________________ (same answer as first part) can be found.

j)        We can prove a problem is NP-complete either from scratch, or we can use reduction, by which we ________________________________________________________________________________.

 

2)      (10 points – 2 points each) Indicate if each of the following statements is TRUE or FALSE.  For FALSE statements, INDICATE WHY THEY ARE FALSE.

 

a)      An advantage of an adjacency matrix representation of a graph is that all neighbors of a vertex can be found in time Theta(V) (where V is the number of vertices in the graph).

b)      NP-Complete problems are problems that are known to require exponential run-times.

c)      If I discover a true polynomial algorithm that solves the Traveling Salesman Problem, I will have proved that P = NP.

d)      The recursive solution to the Fibonacci Sequence is an example of a algorithm that is both elegant and efficient in its run-time.

e)      The dynamic programming solution to the Subset Sum problem runs in polynomial time.


3)      (16 points – 8 + 8) Consider the LZW compression algorithm that we discussed in lecture. 

a)      Consider a file with 3,000,000 letter As in it (no other characters, except for the end of file character).  How large a codeword size (in terms of bits) will be needed so that we DO NOT run out of codewords in the process of compressing this file?  Justify your answer thoroughly for full credit.  Hint: Trace it for the first few cycles to see the trend, then use some math to determine the answer.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

b)      Consider a file containing the following codewords (stored in binary):

65  66  65  67  256  260

Trace the LZW decoding process for the file (in the same way done in handout lzw2.txt).  Assume that the extended ASCII set will use codewords 0-255.  For each step in the decoding, be sure to show all of the information indicated below.  Note: The ASCII value for 'A' is 65.

 

STEP     CODEWORD INPUT    STRING OUTPUT     (CODE, STRING) ADDED TO DICTIONARY

----     --------------    -------------     ----------------------------------

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

4)      (8 points) An array representation of a min-heap data structure is shown below.  Draw the resulting array after the operation  Insert(20).  Show your work.

1

2

3

4

5

6

7

8

9

10

 

15

25

20

30

60

55

35

45

50

80

 

 

 

 

 

 

 

 

 

 

 

 

 

5)      (10 points – 8 + 2)  Consider the graph below.  Assume the vertices are stored in alphabetical order, and that the edges are stored in alphabetical order for each vertex.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


a)      Complete the table below, as it would look after a Breadth-First Search Spanning Tree (starting from vertex A1) were created for the graph.  val[] is the BFS number for the vertex, and dad[] is the parent vertex in the BFS tree.  Show your work above or in the space below the table for partial credit.

 

 

A1

B2

C3

D4

E5

F6

G7

H8

I9

J10

val

 

 

 

 

 

 

 

 

 

 

dad

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

b)      Identify all of the articulation points in the graph.

6)      (10 points -- 8 + 2)  Consider the complete weighted graph below and an initial tour of the graph ABCDEA of weight 25.

 

 

 

 

 

 

 

 

 

 

 

 


a)      Show ALL POSSIBLE edge swaps in the 2-OPT neighborhood of this tour, listing the potential improvement (if any) for each over the original tour.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

b)      Indicate which of the possible tours above is actually chosen, show the new resulting tour and list its total weight.

 

 

 

 

 

 

 

 

 

 


7)      (8 points) Consider the weighted graph below. The numbers are the edge capacities. S is the source vertex and T is the sink vertex.

 

 

 

 

 

 

 

 

 

 

 

 


Using the Priority First Search implementation of the Ford-Fulkerson algorithm, show EACH AUGMENTING PATH generated (in the correct order that the paths are generated), the amount of flow for each path, and the Maximum Flow for the graph.  For partial credit, be sure to SHOW YOUR WORK.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


8)      (10 points) Consider an unweighted graph that may or may not be connected.  Assume that each VERTEX in the graph is storing a single, positive integer.  Using a modification of the DFS algorithm for adjacency matrices, write C++ or Java code that will indicate and write out the vertex with the minimum data for each connected component in the graph.  For example, given the graph below, the output of your code should be:

C.C. 1: Minimum Element B, 15

C.C. 2: Minimum Element K, 15

C.C. 3: Minimum Element D, 5

 

 

 

 

 

 

 


Below is some (modified) code from the text with comments that you should use as a starting point.

 

Data that is already initialized for you to use:

M[][] – adjacency matrix for the graph

label[] – char array that gives the letter for each vertex (1 is A, 2 is B, etc)

data[] – int array storing the integer data for each vertex

val[] – array to determine if a vertex has been visited or not

 

void search()  // Main search function – all of your output should be done

{              // from here. 

    id = 0;    // Assume id is a global variable

    for (int k = 1; k <= V; k++)  // V is the number of vertices in the graph

           val[k] = unseen;       // Initialize all vertices to unseen

    // Loop here to call find_min for each connected component and output result

 

 

 

 

 

 

 

 

 

 

 

 

}

 

int find_min(int k)     // Recursive DFS, but now with a return int that

{                       // is the index of the minimum data for that call.

    val[k] = ++id;      // val set to DFS number of vertex.  This number

                        // is only important in determining what has been visited

 

 

 

 

 

 

 

 

 

 

 

 

 

}

9)      (8 points – 4 + 4)  Consider a weighted graph with V vertices and E edges

a)      State and thoroughly justify the minimum and maximum values for E in terms of V.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

b)      State, in terms of V and E, the run-time of Prim's MST algorithm using PFS when using an adjacency list and when using an adjacency matrix (2 answers required).