Exam 11: Analyzing Algorithm Efficiency

arrow
  • Select Tags
search iconSearch Question
  • Select Tags

Draw a careful graph of the function f defined by the formula f(n)=n3f ( n ) = \left\lfloor \frac { n } { 3 } \right\rfloor for all integers n.

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

(a) Consider the following algorithm segment: for i:=1 i:=1 to n n for j:=1 j:=1 to i i x:=5i+8j x:=5 \cdot i+8 \cdot j next j j next i i How many additions and multiplications are performed when the inner loop of this algorithm segment is executed? How many additions and multiplications are performed when the entire algorithm segment is executed? (b) Find an order for this algorithm segment from among the following: log2n,n,nlog2n\log _ { 2 } n , n , n \cdot \log _ { 2 } n , n2,n3n ^ { 2 } , n ^ { 3 } , and n4n ^ { 4 } . Give a reason for your answer.

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

a. Two multiplications and one addition are performed when the inner loop of the given
algorithm segment is executed for a total of three elementary operations for each iteration of
the inner loop. The number of iterations of the inner loop can be deduced from the following
table, which shows the values of i and j for which the inner loop is executed.
 a. Two multiplications and one addition are performed when the inner loop of the given algorithm segment is executed for a total of three elementary operations for each iteration of the inner loop. The number of iterations of the inner loop can be deduced from the following table, which shows the values of i and j for which the inner loop is executed.    Therefore, by Theorem  5.2 .2 , the number of iterations of the inner loop is  n + ( n - 1 ) + \cdots + 2 + 1 = \frac { n ( n + 1 ) } { 2 }  The total number of elementary operations that must be performed when the algorithm is executed is the number performed during each iteration of the inner loop times the number of iterations of the inner loop:  3 \cdot \left( \frac { n ( n + 1 ) } { 2 } \right) = \frac { 3 } { 2 } n ^ { 2 } + \frac { 3 } { 2 } n .  b. By the theorem on polynomial orders,  \frac { 3 } { 2 } n ^ { 2 } + \frac { 3 } { 2 } n  is  \Theta \left( n ^ { 2 } \right) , and so the algorithm segment has order  n ^ { 2 } .
Therefore, by Theorem 5.2.25.2 .2 , the number of iterations of the inner loop is
n+(n1)++2+1=n(n+1)2n + ( n - 1 ) + \cdots + 2 + 1 = \frac { n ( n + 1 ) } { 2 }
The total number of elementary operations that must be performed when the algorithm is executed is the number performed during each iteration of the inner loop times the number of iterations of the inner loop:
3(n(n+1)2)=32n2+32n.3 \cdot \left( \frac { n ( n + 1 ) } { 2 } \right) = \frac { 3 } { 2 } n ^ { 2 } + \frac { 3 } { 2 } n .
b. By the theorem on polynomial orders, 32n2+32n\frac { 3 } { 2 } n ^ { 2 } + \frac { 3 } { 2 } n is Θ(n2)\Theta \left( n ^ { 2 } \right) , and so the algorithm segment has order n2n ^ { 2 } .

Express the following statement using Ω-notation.: x512x5(3x+4)x+2 for all real numbers x>2\left| x ^ { 5 } \right| \leq \left| \frac { 12 x ^ { 5 } ( 3 x + 4 ) } { x + 2 } \right| \quad \text { for all real numbers } x > 2

Free
(Essay)
5.0/5
(36)
Correct Answer:
Verified

12x5(3x+4)x+2 is Ω(x5).\frac { 12 x ^ { 5 } ( 3 x + 4 ) } { x + 2 } \text { is } \Omega \left( x ^ { 5 } \right) .

Explain why the following statement is true. (You may use the theorem on polynomial orders.) 3+6+9++3n is O(n2)3 + 6 + 9 + \cdots + 3 n \text { is } O \left( n ^ { 2 } \right)

(Essay)
4.8/5
(35)

If nn and kk are positive integers and 2kn<2k+12 ^ { k } \leq n < 2 ^ { k + 1 } , what is log2(n)\left\lfloor \log _ { 2 } ( n ) \right\rfloor ? Be sure to justify each step of your answer.

(Essay)
4.7/5
(32)

If x is a real number and x>1, is x2>x? Why? Is 5x3>5x > 1 , \text { is } x ^ { 2 } > x ? \text { Why? Is } 5 x ^ { 3 } > 5 Why?

(Essay)
4.9/5
(41)

Use the definition of OO -notation to prove that 2x2+3x+42 x ^ { 2 } + 3 x + 4 is O(x2)O \left( x ^ { 2 } \right) . (Do not use the theorem on polynomial orders.)

(Essay)
4.9/5
(38)

Use the definition of OO -notation to prove that 15x3+8x+415 x ^ { 3 } + 8 x + 4 is O(x3)O \left( x ^ { 3 } \right) .(Do not use the theorem on polynomial orders.)

(Essay)
5.0/5
(36)

Express the following statement using O-notation: 12x5(3x+4)x+236x5 for all real numbers x>2\left| \frac { 12 x ^ { 5 } ( 3 x + 4 ) } { x + 2 } \right| \leq 36 \left| x ^ { 5 } \right| \quad \text { for all real numbers } x > 2

(Essay)
5.0/5
(35)

Use O-notation to express the following statement: 5x+xlog2x6xlog2x for all x>2\left| 5 x + x \log _ { 2 } x \right| \leq 6 \left| x \log _ { 2 } x \right| \text { for all } x > 2

(Essay)
4.9/5
(36)

Describe the operation of the insertion sort algorithm.

(Essay)
4.8/5
(35)

Let h be the function whose graph is shown below. Carefully sketch the graph of 2h. Let h be the function whose graph is shown below. Carefully sketch the graph of 2h.

(Essay)
4.8/5
(37)

Describe the operation of the binary search algorithm.

(Essay)
4.9/5
(37)

(a) Find the total number of additions and multiplications that must be performed when the following algorithm is executed. Show your work carefully.  for i:=1 to n\text { for } i:=1 \text { to } n  for j=i to n\text { for } j=i \text { to } n a:=2(5i+j+1)a:=2 \cdot(5 \cdot i+j+1)  next j\text { next } j  next i\text { next } i (b) Find an order for the algorithm segment of part (a) from among the following: log2n,n\log _ { 2 } n , n , nlog2n,n2,n3n \cdot \log _ { 2 } n , n ^ { 2 } , n ^ { 3 } , and n4n ^ { 4 } . Give a reason for your answer.

(Essay)
4.9/5
(43)

Describe the operation of the sequential search algorithm.

(Essay)
4.8/5
(37)

Consider the statement: 3x2+17x+525x2 for all x>1\left| 3 x ^ { 2 } + 17 x + 5 \right| \leq 25 \left| x ^ { 2 } \right| \quad \text { for all } x > 1 Express this statement using O-notation.

(Essay)
4.7/5
(35)

Describe the operation of the merge sort algorithm.

(Essay)
4.9/5
(33)

Consider the statement: 3x23x2+17x+525x2 for all x>13 \left| x ^ { 2 } \right| \leq \left| 3 x ^ { 2 } + 17 x + 5 \right| \leq 25 \left| x ^ { 2 } \right| \quad \text { for all } x > 1 \text {. } Express this statement using Θ-notation. \Theta \text {-notation. }

(Essay)
4.7/5
(43)

Express the following statement using Θ-notation: x512x5(3x+4)x+236x5 for all real numbers x>2\left| x ^ { 5 } \right| \leq \left| \frac { 12 x ^ { 5 } ( 3 x + 4 ) } { x + 2 } \right| \leq 36 \left| x ^ { 5 } \right| \quad \text { for all real numbers } x > 2

(Essay)
4.8/5
(36)

Define a function F:R+RF : \mathbf { R } ^ { + } \longrightarrow \mathbf { R } by the formula F(x)=log2(x)F ( x ) = \log _ { 2 } ( x ) for all positive real numbers xx . (a) Graph FF , marking units carefully on your axes. (b) What is F(18)F \left( \frac { 1 } { 8 } \right) ? Why? (c) Write the equation 220=1,048,5762 ^ { 20 } = 1,048,576 in logarithmic form.

(Essay)
4.8/5
(34)
Showing 1 - 20 of 22
close modal

Filters

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