Sunteți pe pagina 1din 39

Trc nghim

Dap An

Lam lai

Cu 1:

T(n) s bng bao nhiu ?

A
nlog(n)

B
nlog(2n) n2

D
2nlog(n)

Cu 2: Insertion sort can be expressed as a recursive procedure as follows. In order to sort A[1 n], we recursively sort A[1 n -1] and then insert A[n] into the sorted array A[1 n - 1]. Write a recurrence for the running time of this recursive version of insertion sort.

A
Solution is T(n) = (n2)

B
Solution is T(n) = (n2)

C
Solution is T(n) = (n2)

D
Solution is T(n) = (2n)

Cu 3: Referring back to the searching problem (see Exercise 2.1-3), observe that if the sequence A is sorted, we can check the midpoint of the sequence against v and eliminate half of the sequence from further consideration. Binary search is an algorithm that repeats this procedure, halving the size of the remaining portion of the sequence each time. Write pseudocode, either iterative or recursive, for binary search. Argue that the worst-case running time of binary search is (lg n). T(n)=T(n/2)+(n), whose solution is T(n)=(lg n) T(n)=T(n/2)+(n), whose solution is T(n)=(lg n2)

T(n)=T(n/2)+(1), whose solution is T(n)=(lg n) T(n)=T(n/2)+(n), whose solution is T(n)=(lg n)

Cu 4: Let A[1 n] be an array of n distinct numbers. If i < j and A[i] > A[j], then the pair (i, j) is called an inversion of A. b. What array with elements from the set {1, 2, . . . , n} has the most inversions? How many does it have?

A
There is a inversion (i,j). The number of such inversions is n(n-1)/2

B
There is a inversion (i,j). The number of such inversions is n(n-1)/3

C
There is a inversion (i,j). The number of such inversions is 2n(n-1)/2

D
There is a inversion (i,j). The number of such inversions is n(2n-1)/2

Cu 5:

Dng cu ny ch cn nh ci hoc nh thng c1,c2,n0 l c

To show that (n + a)b =(nb) we want to find constants c1, c2, n0 > 0 such that 0<=c1nb <=(n+a)b <c2nb for all n>= n0. Thus, c1 = (1/3)b, c2=2b and n0 = 2 |a| satisfy the definition. To show that (n + a)b =(nb) we want to find constants c1, c2, n0 > 0 such that 0<=c1nb <=(n+a)b <c2nb for all n>= n0. Thus, c1 = (1/3)b, c2=2b and n0 = 2 |a| satisfy the definition.

To show that (n + a)b =(nb) we want to find constants c1, c2, n0 > 0 such that 0<=c1nb <=(n+a)b <c2nb for all n>= n0. Thus, c1 = (1/3)b, c2=2b and n0 = 2 |a| satisfy the definition. To show that (n + a)b =(nb) we want to find constants c1, c2, n0 > 0 such that 0<=c1nb <=(n+a)b <c2nb for all n>= n0. Thus, c1 = (1/2)b, c2=2b and n0 = 2 |a| satisfy the definition.

Cu 6:

Chn p n ng

A
2n+1 khc O(2n), 22n khc O(2n)

B
2n+1=O(2n), 22n = O(2n)

C
2n+1=O(2n), 22n khc O(2n)

D
2n+1 khc O(2n), 22n = O(2n)

Cu 7:

Chn p n ng

A
lg n! is polynomially bounded. lg lg n! is polynomially bounded.

B
lg n! is not polynomially bounded. lg lg n! is not polynomially bounded.

C
lg n! is not polynomially bounded. lg lg n! is polynomially bounded.

D
lg n! is polynomially bounded. lg lg n! is not polynomially bounded.

Cu 8:

Chn p n ng T(n)=(n lg n) T(n)=(2n lg n) Cu 9:

T(n)=( lg n) T(n)=(n lg 2n)

A C

T(n) = n

T(n) = 2n

C
T(n) = 3n Cu 10:

D
T(n) = 4n

A
T(n)=nlg n + 2n

B
T(n)=nlg n + 3n

C
T(n)=nlg n + n

D
T(n)=nlg n + 4n

Cu 11: a.

b.

Hai cu trn ng hay sai ?

a ng b sai

a sai b ng

C
C hai cng sai

D
C hai cng ng

Cu 12: a.

b.

Hai cu trn ng hay sai ?

A
a ng b sai

B
a sai b ng

C
C hai cng sai

D
C hai cng ng

Cu 13:

Cu trn ng hay sai ?

A
S

Cu 14:

Cu trn ng hay sai ?

A
S

Cu 15:

Cu trn s dng c phng php master hay khng ?

A
c

B
Khng

Cu 16:

ng hay sai ?

A
ng Sai

Cu 17:

Cu trn ng hay sai ?

A
S

Cu 18: a.

b.

c.

Cu no ng ?

A
a-b a-c

C
b-c All

Cu 19: a.

b.

c.

Tt c nhng cu trn u ng. Hc thuc ht. Cu no khng s dng c master method m s dng recursion method?

A
a-b B

C
b-c All

Cu 20: a.

T(n)= b.

c.

d.

e.

f.

g.

Tt c nhng cu trn u ng. Hc thuc ht. Cu no khng s dng c master method m s dng recursion method?

A
a-b b

C
c-d f-g

Cu 21: a.

T(n)= b.

c.

d.

e.

f.

g.

Tt c nhng cu trn u ng. Hc thuc ht. Cu no khng s dng c master method ?

A
Tt c ngoi tr a-b

B
Tt c ngoi tr b

C
Tt c ngoi tr c-d

D
Tt c ngoi tr f-g

Cu 22: What are the minimum and maximum numbers of elements in a heap of height h?

A
At most= 2h+1 -1 and at least =2h

B
At most= 2h+1 and at least =2h-1

C
At most= 2h+1 +1 and at least =2h Cu 23:

D
At most= 2h+1 -1 and at least =2h-1

Cu trn ng hay khng ?

A
Sai hon ton

B
ng

C
Cu 24: The worst-case running time of heapsort is

A
(n lg 3n).

B
(2n lg n).

C
(n lg n). Cu 25:

D
(n lg 2n).

When all elements are distinct, the best-case running time of heapsort is

A
(2n lg 2n).

B
(n lg n).

C
(n lg2n).

D
(2n lg n).

Cu 26:
HEAP-EXTRACT-MAX(A) 1 if heap-size[A] < 1 2 then error "heap underflow" 3 max A[1] 4 A[1] A[heap-size[A]] 5 heap-size[A] heap-size[A] - 1 6 MAX-HEAPIFY(A, 1) 7 return max

The running time of HEAP-EXTRACT-MAX is

A
O(lg 2n)

B
O(lg 3n)

C
O(lg n)

D
O(lg 4n)

Cu 27:
HEAP-INCREASE-KEY(A, i, key) 1 if key < A[i] 2 then error "new key is smaller than current key" 3 A[i] key 4 while i > 1 and A[PARENT(i)] < A[i] 5 do exchange A[i] A[PARENT(i)] 6 i PARENT(i)

The running time of HEAP-INCREASE-KEY on an n-element heap is

A
O(lg 3n),

B
O(lg n),

C
O(lg 4n), Cu 28:
MAX-HEAP-INSERT(A, key) 1 heap-size[A] heap-size[A] + 1 2 A[heap-size[A]] - 3 HEAP-INCREASE-KEY(A, heap-size[A], key)

D
O(lg 2n),

The running time of MAX-HEAP-INSERT on an n-element heap is XXX : In summary, a heap can support any priority-queue operation on a set of size n in XXX time.

A
XXX=O(lg n).

B
XXX=O(lg 3n).

C
XXX=O(lg 2n), Cu 29:

D
XXX=O(lg 4n),

PARTITION(A, p, r) 1 x A[r] 2 ip-1 3 for j p to r - 1 4 do if A[j] x 5 then i i + 1 6 exchange A[i] A[j]

7 exchange A[i + 1] A[r] 8 return i + 1 The running time of PARTITION on a subarray of size n is

A
(2n).

B
(3n).

C
(n). Cu 30:

D
(4n).

ng hay sai ?

A
S

C
Cu 31: Quicksort's best-case running time is

ng hay sai ?

A
(n lg n).

B
(2n lg n).

C
(3n lg n). Cu 32:

D
(4n lg n).

Consider a hash table of size m = 2p = 214 = 16384, w = 32. and a corresponding hash function h(k) = m(k A mod 1) for .A= (-1)/2. Compute the locations to which the key 123456 is mapped

A
h(k) = 67

B
h(k) = 68

C
h(k) = 69 Cu 33:

D
h(k) = 70

What statement about Red-black tree' property is true a. No two reds in a row on a simple path from the root to a leaf b. If a node is black, then both its children are red c. For each node, all paths from the node to descendant leaves contain the same number of red nodes. d. If a node is black, then its parent is red p n no ng ?

Cu 34: A red-black tree with n internal nodes has height at most

A
2 lg(n + 1).

B
2 lg(n + 2).

C
3 lg(n + 1).

D
2 lg(n + 3).

Cu 35: Suppose that we "absorb" every red node in a red-black tree into its black parent, so that the children of the red node become children of the black parent. (Ignore what happens to the keys.) What are the possible degrees of a black node after all its red children are absorbed? What can you say about the depths of the leaves of the resulting tree? p n sau ng hay khng ? After absorbing each red node into its black parent, the degree of each node black node is 2, if both children were already black, 3, if one child was black and one was red, or 4, if both children were red.

A
K

C
Cu 36:

The approach to algorithm design that reuses part of the solution search by storing values in memory is (a) divide and conquer; (b) greedy; (c) brute force; (d) dynamic programming; (e) probabilistic p n no ng ?

A
a b

C
c Cu 37: d

A chain A1, A2, A3 of three matrices. Suppose that the dimensions of the matrices are 10 100, 100 5, and 5 50, respectively. An optimal order for multiplying matrices that has the lowest cost (minimizes the number of scalar multiplications) is ((A1 A2) A3), for a total of 7500 scalar multiplications

An optimal parenthesization of a matrix-chain product whose sequence of dimensions is 30, 35, 15, 5, 10, 20, 25> is ((A1 (A2 A3)) ((A4 A5)A6))., for a total of 15125 scalar multiplications Nhng iu trn ng hay sai ?

A
S

C
Hn xui Cu 38:

D
Ai m bit

If the chain of matrices is A1, A2, A3, A4, the product A1 A2 A3 A4 can be fully parenthesized in ________ distinct ways:

A
(A1 (A2 (A3 A4))) ,

B
(A1 ((A2 A3) A4))

C
((A1 A2) (A3 A4)) Cu 39:

D
(((A1 A2) A3) A4).

Use the substitution method to show that the solution to the recurrence (15.11) is

A
(5 ).
n

B
(2n).

C
(3n).

D
(4n).

Cu 40:

Show that a full parenthesization of an n-element expression has exactly n - 1 pairs of parentheses.

Cu tr li trn ng hay sai ?

A
S

C
Hic Cu 41:

D
Ko bt

Determine an LCS of 1, 0, 0, 1, 0, 1, 0, 1 and 0, 1, 0, 1, 1, 0, 1, 1, 0. Cch nh : 1001 con ch m + 10 con ch m. Hoc 101 con ch m 2 ln.

A
(1,0,0,1,1,0) or (1,0,1,1,0,1)

B
(1,0,0,1,1,0)

C
(1,0,0,1,1,0)

D
(1,0,0,1,1,0)

Cu 42:

Which of the following statements is not true? a) n2 + 2n + 6 b) n2

c) 2n+1 d) n!

Cu 43: LCS-LENGTH(X, Y) 1 m length[X] 2 n length[Y] 3 for i 1 to m 4 do c[i, 0] 0 5 for j 0 to n 6 do c[0, j] 0 7 for i 1 to m 8 do for j 1 to n 9 do if xi = yj 10 then c[i, j] c[i - 1, j - 1] + 1 11 b[i, j] "" 12 else if c[i - 1, j] c[i, j - 1] 13 then c[i, j] c[i - 1, j] 14 b[i, j] "" 15 else c[i, j] c[i, j - 1] 16 b[i, j] 17 return c and b The running time of the procedure is ?

A
O(2mn)

B
O(mn)

C
O(3mn)

D
O(n)

Cu 44: An LCS (Longest common subsequence) of X= A, B, C, B, D, A, B and Y = B, D, C, A, B, A.is ? Cch nh : X=Anh Bn C B Y= B Dt Cng An Bt Anh.

A
BCAB

B
BABA

C
BCBA ( b cua bn anh)

D
BABA

Cu 45: An LCS (Longest common subsequence) of X= 0, 1, 1, 0, 1, 0, 0, 1 and Y = 1, 1, 0, 1, 1, 0.is ?

A
<1, 1, 0, 1, 1>

B
<1, 0, 0, 1, 0>

C
<1, 1, 1, 1, 0>

D
<1, 1, 0, 1, 0> 1 mnh, 1 my, 0 lt ba, 10 im

Cu 46: The length of An LCS (Longest common subsequence) of X= A, B, C, B, D, A, B and Y = B, D, C, A, B, Ais ? tm chiu di. Coi cu trn

A
4 5

C
7 6

Cu 47: The number the number of scalar multiplications in optimal parenthesization of a matrix-chain product whose sequence of dimensions 10, 20, 50, 1, 100> is ? Cch nh : 10 tui cha bt yu, 20 tui yu ln u, 50 tui 1 mnh n 100 tui.

A
2100

B
2300

C
2230

D
2200 hai con ngng v hai trng ht vt

Cu 48: An optimal parenthesization of a matrix-chain product whose sequence of dimensions 10, 20, 50, 1, 100> is ? a.(A1 (A2 (A3 A4))) , b.(A1 ((A2 A3) A4)) , c.((A1 A2) (A3 A4)) , d.((A1 (A2 A3)) A4) , Anh c quonh khng li Anh 2 v Anh 3, Anh 4 ch ngi nhn

Cu 49: CM : The number the number of scalar multiplications in optimal parenthesization of a matrix-chain product whose sequence of dimensions 5, 4, 6, 2, 7> is ?

A
157

B
158

C
159 Cu 50:

D
160

An optimal parenthesization of a matrix-chain product whose sequence of dimensions 5, 4, 6, 2, 7> is Cch nh : hai s u v hai s sau 5+4=2+7 th chn p n l a.(A1 (A2 (A3 A4))) b.((A1 (A2 A3)) A4) tng t cu trn

c.(A1 ((A2 A3) A4)) d.((A1 A2) (A3 A4))

Cu 51:

The number the number of scalar multiplications in optimal parenthesization of a matrix-chain product whose sequence of dimensions 30, 1, 40, 10, 25> is 30 nm 1cuc tnh Hoc 30 tui ly 1 ngi v, n 40 tui c 10 con

A
1400

B
1300

C
1100

D
1200

Cu 52: CM : An optimal parenthesization of a matrix-chain product whose sequence of dimensions 30, 1, 40, 10, 25> is a.(A1 (A2 (A3 A4))) b.(A1 ((A2 A3) A4)) Anh c c n, (Anh 2 v Anh 3) gt anh 4 c.((A1 A2) (A3 A4)) d.((A1 (A2 A3)) A4)

Cu 53: OPTIMAL-BST(p, q, n) for i 1 to n + 1 do e[i, i( 1] 0 w[i, i( 1] 0 for l 1 to n do for i 1 to n(l + 1 do j i + l(1 e[i, j ]

w[i, j ] w[i, j(1] + pj for r i to j do t e[i, r(1] + e[r + 1, j ] + w[i, j ] if t < e[i, j ] then e[i, j ] t root[i, j ] r return e and root . The running time of Optimal Binary Search Tree is ?

A
O(2n3)

B
O(2n3)

C
O(n2)

D
O(n3)

Cu 54: phc tp ca thut ton nhn ma trn Strassen ?

A
O(2nlg7)

B
O(nlg6)

C
O(nlg7)

D
O(nlg5)

Cu 55: Thut ton trong th. phc tp ca Kruskal v Prim's algorithm l ? p n sau cho cu hi trn c ng ko? prim = O(E+ V logV). E edge and V vertex. kurskal = O(E lgV ) tng ng vi O(E log E). Where E is the number of edges in the graph and V is the number of vertices

A
S

Cu 56: Function g is an upper bound on function f iff for all x: (a) g(x) f (x); (b) g(x) f (x); (c) g = O( f ); (d) f =(g)

Cu 57: Function g is a lower bound on function f iff for all x: (a) g(x) f (x);

(b) g(x) f (x); (c) f = O(g); (d) g =(f);

Cu 58: Big-Omega notation expresses (a) tight bounds; (b) upper bounds; (c) lower bounds; (d) worst cases;

Cu 59: Big-O notation expresses (a) tight bounds; (b) upper bounds; (c) lower bounds; (d)

best cases

Cu 60: Theta notation expresses (a) tight bounds; (b) upper bounds; (c) lower bounds; (d) worst cases

Cu 61: The theorem, T1(n) ( g1(n)) T2(n) (g2(n)) T1(n) + T2(n) (max{g1(n), g2(n)}) says that (a) the slower and faster parts of an algorithm together set its running time; (b) the faster part of an algorithm dominates in determining running time; (c) the slower part of an algorithm dominates in determining running time; (d) Algorithm T computes functions g1 and g2;

Cu 62: Quadratic time is faster than (a) (1) (b) (lg n) (c) (n2) (d) (n3)

Cu 63: Best case for an algorithm (a) takes the same time forall data (b) assumes the data that the algorithm handles in the greatest time (c) assumes the data that the algorithm handles in the least time (d) is the expected time considering all possible input data

Cu 64: Worst case for an algorithm (a) takes the same time for all data (b) assumes the data that the algorithm handles in the greatest time (c) assumes the data that the algorithm handles in the least time (d) is the expected time considering all possible input data

Cu 65: Average case for an algorithm (a) takes the same time for all data (b) assumes the data that the algorithm handles in the greatest time (c) assumes the data that the algorithm handles in the least time (d) is the expected time considering all possible input data

Cu 66: Bubble sorts worst-case running time function is determined by (a) a single loop (b) nested loops (c) a series of loops (d) the input data

Cu 67: A loop nested to two levels, each with roughly n iterations, has running time (a) O(1) (b) O(n) (c) O(n2) (d) O(n lg n)

Cu 68: The running time function of an algorithm is determined by

(a) the number of operations in a sequence structure (b) the number of branches in a selection structure (c) the time of the slowest of a series of loops (d) the data

Cu 69: Recurrence relations enable us to use _____ to obtain running time (a) empirical tests (b) loop nesting; (c) base-case running time (d) base-case running time and depth of recursion

Cu 70: Brute-force algorithms make use of : (a) a straightforward solution to a problem by examining all possible solutions (Bruteforce) (b) the fact that an optimal solution can be constructed by adding the cheapest next component, one at a time (Greedy) (c) The fact that data is arranged so that at each step, half the remaining input data can disposed of (Divede and conquer) (d) effort can be saved by saving the results of previous effort in a table; (dynamic programming)

Cu 71: The linear search is what kind of algorithm? (a) divide and conquer; (b) greedy (c) brute force (d) dynamic programming

Cu 72: The Binary search is what kind of algorithm? (a) divide and conquer (b) greedy (c) brute force (d) dynamic programming

Cu 73: Inserting an element in a sorted array so that it stays sorted is (a) O(1); (b) O(lg n); (c) O(n); (d) O(n lg n);

Cu 74: Linear search is O(___) (a) 1 (b) lg n; (c) n; (d) n2;

Cu 75: What is the running time of a brute-force algorithm that finds the minimum element of an array? (a) O(1); (b) O(lg n); (c) O(n); (d) O(n lg n);

Cu 76: The BST search uses which approach to algorithm design? (a) divide and conquer (b) greedy (c) brute force (d) dynamic programming;

Cu 77: After each step of the BST search, the quantity of remaining data to be searched is on average (a) 1; (b) lg n; (c) n 2 (d) n;

Cu 78: The height of a BST is on average O(__) (a) 1; (b) lg n; (c) n; (d) n lg n

Cu 79: Hill climbing is a(n) ____ approach (a) divide-andconquer; (b) brute-force; (c) greedy; (d) dynamicprogramming; (e) probabilistic

Cu 80: Let (u, v) be a minimum-weight edge in a graph G. Show that (u, v) belongs to some minimum spanning tree of G. p n sau ng hay khng ? Let A be a subset of some MST T such that (u, v) e A. To choose an edge to be added to A, all the edges on the cut are considered and an edge with lowest weight is selected. Since (u, v) is the minimum weight edge in the graph G, it gets selected on some cut.

A
S

Cu 81: Let e be a maximum-weight edge on some cycle of G = (V, E). Prove that there is a minimum spanning tree of G = (V, E -{e}) that is also a minimum spanning tree of G.

That is, there is a minimum spanning tree of G that does not include e. p n sau ng hay khng ? For simplicity, assume a cycle (C*) in G contains three edges: el = (1,2), e2=(2,3), e3=(l,3), so that wtl = max(wtl, wt2, wt3) A minimum spanning tree on G cannot include all el, e2, e3 as it would form a cycle and violate the tree property During the course of Generic-MST algorithm an edge from C will be considered for inclusion in A if it contains a safe edge According to Theorem 23.1, it can be a light edge crossing a cut (S. V-S) that respects A The cut (S, V-S) therefore does not respect C. (Otherwise, no edge in C crosses the cut) If el crosses the cut, it is easy to see that at least one more edge in C crosses the cut. Since el has the maximum weight, it will not be chosen to be included in A. Note that, this will be true even when some edges from C are already included in A Hence, we can select safe edges in such a way that they will never include el The above proof can be readily generalized to a cycle of any size.

A
S

Cu 82: Let T be a minimum spanning tree of a graph G, and let L be the sorted list of the edge weights of T. Show that for any other minimum spanning tree T of G, the list L is also the sorted list of edge weights of T. Cu ny m c p n chc cng chng ai hc. c v nh thi.

A
S

Cu 83: The length of An LCS (Longest common subsequence) of X= president> and Y = <providence> Chiu di l bao nhiu? -> priden

A
3 4

C
5 6

Cu 84: LCS of Algorithm v Alignment

A
Alim Ali

C
Al

D
Alimt

Cu 86: The length of an LCS (Longest common subsequence) of X= <springtime> and Y =<printing> is

Printi - 6

Print - 5

C
Printim - 7

D
Prin - 4

Cu 87: An LCS (Longest common subsequence) of X= ncaatournament and Y = <northcarolina> is

A
ncarna

B
ncarn

C
ncar Cu 88: nc

An LCS (Longest common subsequence) of X= <basketball> and Y = <krzyzewski> is

A
ke sk

C
Ko c Cu 89: k

An LCS (Longest common subsequence) of X= <basketball> and Y = <snoeyink> is

A
sk se

C
Ko c s

S-ar putea să vă placă și