Exam 3: Algorithms

arrow
  • Select Tags
search iconSearch Question
  • Select Tags

Describe a brute-force algorithm for determining, given a compound proposition PP in nn variables, whether PP is satisfiable. It is known that this problem is NP\mathrm { NP } -complete. If P=NP\mathrm { P } = \mathrm { NP } , what conclusion can be drawn about the efficiency of your algorithm compared to the efficiency of the best algorithm for solving this problem?

Free
(Essay)
4.9/5
(30)
Correct Answer:
Verified

For each string of length nn of the letters T\mathbf { T } and F\mathbf { F } (representing true and false), evaluate the given compound proposition when the ith i ^ { \text {th } } variable is assigned the truth value given by the ith i ^ { \text {th } } letter in the string. If any of these values of PP is T\mathbf { T } , then PP is satisfiable; otherwise it is not. This will take at least 2n2 ^ { n } steps in the worst case (the case in which PP is not satisfiable), once for each such string. If P=NP\mathrm { P } = \mathrm { NP } , then there is a polynomial worst-case time algorithm, so the brute force algorithm is not the most efficient.

Suppose that A,B\boldsymbol { A } , \boldsymbol { B } , and C\boldsymbol { C } are 3×4,4×53 \times 4,4 \times 5 , and 5×65 \times 6 matrices of numbers, respectively. Is it more efficient to compute the product ABC\boldsymbol { A B C } as (AB)C( \boldsymbol { A B } ) \boldsymbol { C } or as A(BC)\boldsymbol { A } ( \boldsymbol { B } \boldsymbol { C } ) ? Justify your answer by computing the number of multiplications of numbers needed each way.

Free
(Essay)
4.7/5
(39)
Correct Answer:
Verified

To multiply AA by BB , we will need 3.4 5=605 = 60 multiplications. The result is a 3×53 \times 5 matrix. To multiply it by CC will require 356=903 \cdot 5 \cdot 6 = 90 multiplications. This gives a total of 60+90=15060 + 90 = 150 steps. On the other hand, if we multiply B\boldsymbol { B } by C\boldsymbol { C } first, we use 456=1204 \cdot 5 \cdot 6 = 120 multiplications and then another 346=723 \cdot 4 \cdot 6 = 72 to multiply A\boldsymbol { A } by the 4×64 \times 6 matrix BCB C . This method uses a total of 120+72=192120 + 72 = 192 steps. Therefore the first method is a little faster.

(a) Describe an algorithm for finding the second largest integer in a sequence of distinct integers. (b) Give a big- OO estimate of the number of comparison used by your algorithm.

Free
(Essay)
4.9/5
(28)
Correct Answer:
Verified

(a) We first compare the first and second integers in the sequence a1,a2,,ana _ { 1 } , a _ { 2 } , \ldots , a _ { n } , setting the value of the variable firstmax equal to the larger, and the value of the variable secondmax equal to the smaller. For each successive integer aia _ { i } in the sequence, i=3,4,,ni = 3,4 , \ldots , n , we first compare it to firstmax. If ai>a _ { i } > firstmax, then we make the assignments secondmax :=: = firstmax and firstmax :=ai.: = a _ { i } . Otherwise, we compare aia _ { i } to secondmax, and if ai>secondmaxa _ { i } > \operatorname { secondmax } , then we make the assignment secondmax := aia _ { i } . At the end of this procedure the value of secondmax will be the second largest integer in the sequence.
(b) We do one comparison at the beginning of the algorithm to determine whether a1a _ { 1 } or a2a _ { 2 } is larger. Then for each successive term, for i=3,4,,ni = 3,4 , \ldots , n , we carry out at most two comparisons. Hence the largest number of comparisons used is 2(n2)+1=2n32 ( n - 2 ) + 1 = 2 n - 3 , ignoring bookkeeping. This is O(n)O ( n ) .

Describe an algorithm for finding the smallest integer in a finite sequence of integers.

(Essay)
4.8/5
(46)

Determine the worst case complexity in terms of the number of comparisons used for the algorithm you described in problem 1.

(Essay)
4.7/5
(43)

 Show that 13+23+33++n3 is O(n4)\text { Show that } 1 ^ { 3 } + 2 ^ { 3 } + 3 ^ { 3 } + \cdots + n ^ { 3 } \text { is } O \left( n ^ { 4 } \right)

(Essay)
4.8/5
(37)

 Let f(n)=3n2+8n+7. Show that f(n) is O(n2)\text { Let } f ( n ) = 3 n ^ { 2 } + 8 n + 7 \text {. Show that } f ( n ) \text { is } O \left( n ^ { 2 } \right) Be sure to specify the values of the witnesses C and k.

(Essay)
4.7/5
(43)

 Show that the function f(x)=(x+2)log(x2+1)+log(x3+1) is O(xlogx)\text { Show that the function } f ( x ) = ( x + 2 ) \log \left( x ^ { 2 } + 1 \right) + \log \left( x ^ { 3 } + 1 \right) \text { is } O ( x \log x ) \text {. }

(Essay)
4.9/5
(41)
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)