Docsity

Practice Final Exam - Data Structures and Algorithms | CECS 328, Exams of Discrete Structures and Graph Theory

Toggle sidebar
bg1
CECS 328 Final, Fall 2002, Professor Ebert
Name:
For multiple choice problems, circle the best answer unless otherwise indicated.
For long problems, show all work to receive full credit. Multiple choice problems
are worth 5 points each unless otherwise stated.
1. Circle all of the following which is true about the growth of the function f(n) = nlogn.
(10 points)
1. linear growth: f(n) = O(n)
2. polynomial growth: f(n) = O(nk) for some positive integer k
3. superpolynomial growth: f(n) = Ω(nk) for every positive integer k
4. Exponential growth: f(n) = Ω(αn) for some α > 1
5. none of the above
2. Same question as problem 1, but now assume the function is S(n), the number of steps
required by the following algorithm: (10 points)
sum=0;
for(i=0; i < n; i++){
j=i;
while(j !=0){
if( j % 2 == 0)
sum++;
j /= 2;
}
}
1. linear growth: f(n) = O(n)
2. polynomial growth: f(n) = O(nk) for some positive integer k
3. superpolynomial growth: f(n) = Ω(nk) for every positive integer k
4. log-linear growth: f(n) = Ø(nlog n)
5. none of the above
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Practice Final Exam - Data Structures and Algorithms | CECS 328 and more Exams Discrete Structures and Graph Theory in PDF only on Docsity!

CECS 328 Final, Fall 2002, Professor Ebert

Name:

For multiple choice problems, circle the best answer unless otherwise indicated. For long problems, show all work to receive full credit. Multiple choice problems are worth 5 points each unless otherwise stated.

  1. Circle all of the following which is true about the growth of the function f (n) = nlog^ n. (10 points)
    1. linear growth: f (n) = O(n)
    2. polynomial growth: f (n) = O(nk) for some positive integer k
    3. superpolynomial growth: f (n) = Ω(nk) for every positive integer k
    4. Exponential growth: f (n) = Ω(αn) for some α > 1
    5. none of the above
  2. Same question as problem 1, but now assume the function is S(n), the number of steps required by the following algorithm: (10 points)

sum=0; for(i=0; i < n; i++){ j=i; while(j !=0){ if( j % 2 == 0) sum++; j /= 2; } }

  1. linear growth: f (n) = O(n)
  2. polynomial growth: f (n) = O(nk) for some positive integer k
  3. superpolynomial growth: f (n) = Ω(nk) for every positive integer k
  4. log-linear growth: f (n) = Ø(n log n)
  5. none of the above
  1. Given the statement “If we are to arrive on time in 4 hours, then it is necessary to take the train”, consider the following proof of the statment. If we drive by car, then it will take at least 5 hours, since highway 101 is partially closed. If we take the bus, then we have the same problem as if we were driving. If we fly, then the next flight does not leave for another 6 hours. Circle all of the proof strategies that are used.
    1. indirect proof.
    2. proof by cases.
    3. proof by contradiction
    4. direct proof
    5. none of the above
  2. Consider the the following recursive definition for defining the set of my favorite binary strings.
    • Basis Step: the string “1” is a favorite.
    • Inductive Step 1: if x is a favorite string, then both 0x0 and 1x1 are favorite strings.
    • Inductive Step 2: If x 01 y is favorite, where x and y are (possibly empty) strings, then xy is a favorite. Circle all of the following strings which are favorites. Note that there may be more than one. (10 points)
    1. λ (the empty string)
    2. 111111
    3. 1010110
    4. 001011000
    5. none of the above
  3. Consider the binary search tree obtained by inserting 16,12,18,10,14,17,20,11,13,8,15 into an initially empty tree. If 12 is deleted from this tree, then the new left child of 16 is
    1. 15
    2. 17
    3. 13
    4. 8
  1. A B tree will contain at most records per leaf, assuming that each record contains one thousand bytes of data and that a single disk read can access 4,096 bytes of data.
    1. 1
    2. 2
    3. 4
    4. 6
    5. none of the above
  2. Given a hash table with load factor λ = .9 match the following operations with the average number of probes/steps needed to complete the operation. (10 points)
    1. successful search (linear probing) a. 50.
    2. insertion (random probing) b. 5.
    3. insertion (linear probing) c. 2.
    4. unsuccessful search (linear probing) d..
    5. unsuccessful search (separate chaining)
  3. The worst-case for deleting each of n elements from a binary heap is
    1. O(n)
    2. O(n log n)
    3. O(n^2 )
    4. O(n^2.^5 )
    5. none of the above
  4. Assume that instead of median-of-three, quicksort used the last array element as the median. In this case circle the following inputs which will force quicksort to execute in Θ(n^2 ) steps. (10 points)
    1. an array of increasing distinct integers
    2. an array of decreasing distinct integers
    3. an array of integers that are all equal
    4. an array which is a random permutation of integers
    5. none of the above
  1. Consider the disjoint set data structure whose universal set has seven elements { 0 , 1 , 2 , 3 , 4 , 5 , 6 }. Assume the array − 1 − 1 5 4 0 − 1 − 1 contains the current set information. Then, assuming union by height and path compression, the updated array after the consecutive operations union(0, 5) and f ind(2) will be
    1. 5 − 1 5 4 0 − 1 − 1
    2. −^1 −^1 0 4 0 −^1 −^1
    3. − 1 − 1 0 4 0 0 − 1
    4. none of the above
  2. The graph in Figure 1 (back page) is classified as a graph.
    1. directed multigraph
    2. undirected simple graph
    3. directed simple graph
    4. undirected general graph
  3. Circle all which is true about the graph in Figure 1 (back page). (10 points)
    1. it is weakly connected
    2. it is strongly connected
    3. it has a vertex with in-degree 2
    4. it has a vertex with out-degree 2
    5. it is acyclic
    6. it can be topologically sorted
  4. True or False? there exists a complete graph which is bipartite.

18a. For the undirected graph below, use Dijkstra’s algorithm to find the distance of each vertex from vertex a. (20 points)

19a. For the bipartite graph G shown below, draw the network graph N G that is associated with it. (5 points)

19b. Now let M = {(1, 1), (2, 2), (3, 3)} be a matching for G. Use this to draw the augmented network A(N G, M ), with respect to N G and M. Indicate a path from s to t in this network. (10 points)

21a. Use Kruskals algorithm to find a minimum spanning tree for the following graph. Show the forest for each stage of the algorithm. (15 points)

21b. Would Prim’s and Kruskal’s algorithms work just as well for finding maximum spanning trees (assuming of course at each stage we choose edges of maximum cost as opposed to minimum cost)? Prove or disprove. (10 points)

21c. For the graph of part a, assuming the adjacency lists are in alphabetical order, give the minimum spanning tree induced by a depth-first traversal starting at vertex a. (10 points)

Figure 1