程序代写案例-COMP 251

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
1
COMP 251 Winter 2017
Online quizzes with answers

Open Addressing (2)
Which of the following assertions are true about open address tables?

A. You cannot store more records than the total number of slots in the table.
B. There are no collisions.
C. We cannot delete elements in open address tables.
D. Families of hash functions must allow a full permutation of the index of the table.

Load Factor (2)
Let n be the number of keys and m the number of slots in a hash tables where collisions are resolved by
chaining. The load factor n/m is:

A. The average number of slots used to store the keys.
B. The maximal number of collisions.
C. The average length of a list.

Search Time (2)
Assuming we can compute the hash value of a key k in O(1) time, the search time in an hash table
where collisions are resolved by chaining is:

A. Always executed in constant time O(1).
B. Determined by the load factor.
C. O(1) if and only if there are no collisions.

Running Time of Heapify (3)
What is the recursive equation giving the best case running time of the function heapify on a heap of
size n (i.e. when n nodes are stored in the heap)?

A. T(n) = O(1)
B. T(n) = T( n/3 ) + O(1)
C. T(n) = T( 2*n/3 ) + O(1)

Heapsort (3)
We want to modify Heapsort algorithm seen in class, to sort integers in decreasing order. What should
you do?

A. After heapify, extract directly the last element of the heap (instead of the first one).
B. After heapify, swap the root with the largest of its two children.
C. Replace Max-Heaps by Min-Heaps.

Heaps as Trees (3)
2
How many leaves has a heap containing n elements?

A. floor( n / 4 )
B. ceil( n / 2 )
C. ceil( n / 3 )

Binary Trees as Arrays (3)
Let i be the index of a node n in a binary tree represented as an array. What is the index of the right
child of the left child of n?

A. 2i+1
B. 4i+1
C. 4i

Insertion in BST Trees (4)
The worst case running time of insertions in BST trees with n nodes is:

A. Ω(logn)
B. O(n)
C. Θ(logn)
D. Θ(n)
E. O(logn)

Rotations (4)
Which assertion(s) are true?

A. AVL properties can be restored using rotations.
B. Rotations preserve BST properties.
C. Rotations preserve AVL tree properties.
D. In the worst case, a rotation has a O( log n ) running time.

BST Sort (4)
How should we modify BST sort to sort numbers in decreasing order?

A. Use post-order traversal.
B. Use an AVL tree instead of a BST.
C. Reverse the order of recursive calls in in-order traversal.

Properties of RB Trees (5)
Let T be a red-black tree and x a node of this tree. Which of the following assertions are true?

A. A leaf can be red if and only if its parent node is black.
B. Half of the nodes on any path from x down to a leaf are black.
C. If the left child of x is red, then its right child is red too.
3
D. The black height of the left and right sub-tree of x are identical.

RB Tree Insert (5)
In RB tree insert, we assign the red color to the new node N being inserted. This allows to:

A. Preserve the black height of the paths traversing N.
B. It does not matter. We can assign a black color instead and keep the same algorithm.
C. Avoid two consecutive black nodes.

Rotations I (5)
Consider the tree shown above and the node x and y. Which operations are allowed around the edge
(x,y)?

A. One right rotation
B. One right rotation followed by another right rotation.
C. One right rotation followed by left rotation.
D. One left rotation.

Rotations II (5)
Assume the tree above is a BST. We note h(A) (resp. h(B) and h(C)) the height of the subtree A (resp. B
and C). We left rotate this tree at the level of x. After this rotation we have:

A. h(x) = max( h(A), h(B) )
B. h(A) = h(B)
C. h(y) = h(x) + 1
D. h(y) = h(A) + 2

Find (6)
Disjoint sets are represented with an array rep[], that stores the representative rep[i] for each element
i. The running time of the function find(i) that returns the representative of the set containing i is:

A. Ω (1)
B. Θ (logn)
C. O (logn)

Union (6)
Let h(A) (resp. h(B)) be the height of the tree A (resp. B) rooted at x (resp. y). We assume that h(B) <=
h(A)+1. After union(x,y), which assertion are true?

A. h(y) = h(B)
B. h(B) < h(y)
C. h(y) = h(A) + 1
D. h(y) = max(h(A)+1, h(B))

4
Greedy Choice (7)
The greedy choice is a property that enable us to make a locally optimal choice at each step of the
algorithm. Which of the following assertions are true?

A. It requires to define optimal sub-structures.
B. The algorithm is usually fast.
C. It always guarantees to return an optimal solution for any problem where it is applied.

Scheduling Problem (7)
Consider the scheduling problem represented in the figure above. What will be the solution returned
by the greedy algorithm introduced in class?

A. a4, a1, a8, a9, a3
B. a4, a5, a2, a9, a6
C. None of these solutions.
D. a4, a5, a6
E. a7, a5, a2, a9, a3

Representation of Graphs (8)
We prefer to use an adjacency matrix vs a adjacency list to represent a graph when:

A. The graph is sparse.
B. The graph is a weighted graph.
C. The graph is dense.
D. The graph is directed.

BFS Algorithms (8)
Let G be a directed graph. We explore G using the BFS algorithm. Which of the following assertions are
true?

A. All vertices of G are visited even if G has disconnected components.
B. The source s can be any vertex of G.
C. All vertices at distance d from the source s are visited before vertices at distance d+1.
D. The best case running time of BFS is Ω(V+E).

Edge Classification (9)
Let G be a directed graph. After DFS, we found that G has a back edge.

A. G is connected.
B. G is a tree.
C. G has one cycle.
D. G is an direct acyclic graph (DAG).

Topological Sort (9)
5
Let G be a DAG. Let u and v be two vertices of G, such that there is a path from u to v in G. During the
execution of topological sort algorithm, we discover u before v. Which following assertion is true?

A. v appears before u in the total order.
B. v appears after u in the total order.
C. We cannot say anything about the order of u and v.

Minimum Spanning Trees (10)
Which assertions are true?

A. A light edge crosses the cut.
B. A MST is unique.
C. A graph that respects the cut has no light edge.
D. A light edge is unique.

Kruskal's Algorithm (10)
How do we decide if an edge (i,j) belongs to a MST during the execution of the Kruskal's algorithm?

A. When the vertices i and j have not been used in the solution under construction (i.e. sub set of
the MST).
B. When the weight of (i,j) is the lowest among all candidate edges.
C. When this edge connects two sets vertices that are not connected.

Prim’s Algorithm (10)
Let G=(V,E) be a connected undirected weighted graph on which we run the Prim's algorithm to
compute a MST. How many iterations the main loop of the algorithm (i.e. while loop in the slides used
in class) will do?

A. |V| ^ 2
B. |E|
C. |V| - 1
D. |E| + |V|

Edge Relaxation (11)
In the figure above, what will be the value of d[v] after relaxation of the edge (u,v)?

A. None of the values proposed
B. 12
C. 17
D. 9
E. 7

Negative Weight Edges (11)
We want to calculate the shortest paths from s in a DAG with negative weight edges. Is it ok?
6

A. Yes because there are no negative weight cycles.
B. This is wrong! Negative weight edges are forbidden even in case of a DAG.
C. Not a problem. Negative weight edges cannot be reached from the source.

Dijkstra's Algorithm (11)
Let u be a vertex extracted from the queue during the execution of the Dijkstra's algorithm. What
would happen if we use a First-In-First-Out queue instead of a min priority queue?

A. It does not matter. We can use a FIFO queue.
B. We cannot guarantee that the shortest-path estimate of u is the shortest path from s to u.
C. Relaxing the outgoing edges of u is useless (i.e. it will not change the shortest path estimates).

Bipartite Decision (12)
Which of the graphs (see Fig. 1) are bipartite?

A. A
B. B
C. C

Unstable edges (12)
Consider the matching and the preferences shown in the figure (see Fig. 2). Which of the following
statement is true?

A. There are no unstable pairs. This is a stable matching.
B. B-Z is an unstable pair.
C. X-C is an unstable edge.
D. Y-A is an unstable pair.

Gale-Shapley Algorithm (12)
Let A and B be two sets such that |A|=|B|=n. What is the best case running time for finding a stable
match between A and B with the Gale-Shapley algorithm?

A. Ω (n)
B. Ω (n^2)
C. O (1)
D. O (n^2)

7
Capacity (13)
What is the capacity c(e) of an edge e?

A. The maximum value of the flow on that edge.
B. The value of the flow on that edge.
C. The maximal value of the flow out of the source.

Residual Graph (13)
Let (u,v) be an edge in G with a flow equal to 3 and a capacity of 5. What will be the residual capacities
of the forward and backward edges?

A. 5 for the forward and 3 for the backward
B. 3 for the forward and 5 for the backward
C. 3 for the forward and 2 for the backward
D. 2 for the forward and 3 for the backward

Augmenting Path (13)
By how much can we increase the flow using the red path in the graph above?

A. 0
B. 1
C. 2
D. 3
E. 4
F. 5

Capacity of Cuts (14)
Let consider the flow network above. Each edge is annotated with its capacity. The blue oval shows a
partition of the vertices. What is the capacity of this cut?

A. 2
B. 6
C. 1
D. 5

Ford-Fulkerson Algorithm (14)
Let G be a flow network, on which we ran the Ford-Fulkerson algorithm. At the end of its execution,
which assertion are true?

A. There are no augmenting paths in the residual graph.
B. It exists at least one path from source s to the sink t in the residual graph.
C. The value of the flow is equal to the sum of the capacities of the outgoing edges from s.
D. The sum of the flow out of the source s is equal to the sum of the flow in the sink t.

8
Minimal Cut (14)
Let consider the flow network above with a cut (shown in blue). All edges have a capacity of 1. Which
assertion is true?

A. This is cut but not a minimal cut.
B. This is a minimal cut.
C. This is not a cut.

Sequence Alignment with Needleman-Wunsch (17)
In the figure above, we use the Needleman-Wunsch algorithm to align
2 sequences. Which value will be stored in the cell colored in red?

A. -1
B. 0
C. 1

Bellman-Ford (17)
Given a graph G = ( V;E ) with positive edge weights, the Bellman-Ford algorithm and Dijkstra’s
algorithm can produce different shortest-path trees despite always producing the same shortest-path
weights.

A. True
B. False

Counting Alignments (17)
We want to determine a recursion to calculate the number of sequence alignments c(m,n) between two
sequences of size m and n, such that insertions are not not allowed. What is this recursion?

A. c(m,n) = c(m-1,n-1) + c(m-1,n)
B. c(m,n) = c(m-1,n) + c(m-1,n-1) + c(m,n-1)
C. c(m,n) = c(m-1,n-1)
D. c(m,n) = c(m-1,n) + c(m,n-1)

Weighted interval scheduling (17)
We use the backtracking technique to retrieve the sequence
of activities with the maximal weight. The dynamic array is
shown in the figure above. Activity 4 has just been selected.
Which one will be selected next?

A. a_1
B. a_2
C. a_3
D. a_5

9
Recurrences (18)
We design an alternate version of Mergesort that divide an array of numbers into 3 sub-arrays instead
of 2. What would be the recursion expressing its running time.

A. T(n) = 3 * T(n/3) + Θ(n^2)
B. T(n) = 2 * T(n/2) + Θ(n)
C. T(n) = 2 * T(n/3) + Θ(n^2)
D. T(n) = 3 * T(n/3) + Θ(n)

Integer Multiplication I (18)
A divide-and-conquer strategy to multiply two n-bytes integers is always more efficient (faster) than
the brute force approach.

A. True
B. False

Integer Multiplication II (18)
The Karatsuba algorithm to multiply 2 integers is asymptotically optimal.

A. True
B. False

Recursion Tree (19)
Let T(n)=2*T(n/5)+n^3 be a recursive equation expressing the running time T(n) of a divide-and-
conquer algorithm. What is the height of the recursion tree?

A. log_3 ( n )
B. log_2 ( n )
C. log_5 ( n )

Master Theorem I (19)
Consider the recurrence T(n) = 3 * T(n/4) + n * log(n). Use the master theorem to determine its
asymptotic behavior.

A. Θ ( n * log^2 n )
B. Θ ( n^log_4(3) )
C. The master theorem cannot be applied
D. Θ ( n * log n )

Master Theorem II (19)
Consider the recurrence T(n) = 4 * T(n/2) + log(n). Use the master theorem to determine its asymptotic
behavior.

A. The master theorem cannot be applied
10
B. Θ ( n^2 )
C. Θ ( log^2 n )
D. Θ ( log n )

"Infinite" Binary Counter (20)
We consider a binary counter that does not limit the number of bits used to represent numbers (i.e. we
can use as many bits as we need). We now consider a sequence of n operation INCREMENT. What is the
amortized cost of INCREMENT?

A. O(log n)
B. O(n)
C. O(1)

Accounting Method (20)
We introduce a new function MULTIPUSH(k) that pushes k object in a stack. We now consider
sequences of PUSH, POP, MULTIPUSH and MULTIPOP operations. Here, k is a fixed value. What would
be the amortized cost of MULTIPUSH(k) in the accounting method?

A. 2*k
B. 2
C. k

Global Min-Cut (21)
The contraction algorithm guarantees to find the global min-cut after at most n^2 log(n) executions.

A. True
B. False

Contraction Algorithm (21)
An execution of the contraction algorithm will find the global min-cut if it never contracts an edge that
crosses a global min-cut.

A. True
B. False

3-SAT (21)
We consider an instance of 3-SAT: (!x OR y OR z) AND (x OR y OR !z), where x, y and z and are boolean
variables and ! the NOT operator. Which assignment(s) satisfy this instance?

A. x=False, y=False, z=False
B. x=False, y=False, z=True
C. x=True, y=False, z=True
D. x=False, y=True, z=True

11
ANSWER SHEET

Open Addressing A D Representations of G C Minimal Cut A
Load Factor C BFS Algorithm B C D Neddleman-Wunsch B
Search Time B Edge Classification C Bellman-Ford Algorithm A
Running Time Heapify A Topological Sort B Counting Alignments A
Heapsort C Minimum Span Trees A C Weighted Interval B
Heaps as Trees B Kruskal’s Algorithm C Recurrences D
Binary Trees Arrays B Prim’s Algorithm C Integer Multiplication I B
Insertion BST Trees B Edge Relaxation D Integer Multiplication II B
Rotations A B Negative Edges A Recursion Tree C
BST Sort C Dijkstra’s Algorithm B Master Theorem I D
RB Tree Properties B Bipartite Decision A B Master Theorem II B
RB Tree Insert A Unstable Edges C Infinite Binary Counter C
Rotations I D Gale-Shapley Algo. A Accounting Method C
Rotations II A Capacity A Global Min-Cut B
Find B Residual Graph D Contraction Algorithm A
Union C D Network Flow B 3-SAT A C D
Greedy Choice A B C Capacity of Cuts D
Scheduling Problem A Ford-Fulkerson Algo. A D


欢迎咨询51作业君
51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468