Exam 3: Algorithms

arrow
  • Select Tags
search iconSearch Question
  • Select Tags

Describe an algorithm that takes a list of n integers (n ≥ 1) and finds the average of the largest and smallest integers in the list.

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

procedure avgmaxmin(a1,,an : integers )\operatorname { avgmaxmin } \left( a _ { 1 } , \ldots , a _ { n } \text { : integers } \right)
 max :=a1\text { max } : = a _ { 1 }
min:=a1\min : = a _ { 1 }
for i:=2 to ni : = 2 \text { to } n
if ai>max then max:=aia _ { i } > \max \text { then } \max : = a _ { i }
if ai<min then min:=aia _ { i } < \min \text { then } \min : = a _ { i }
return (max+min)/2( \max + \min ) / 2

In questions find the "best" big-O notation to describe the complexity of the algorithm. Choose your answers from the following: 1, log2n,n,nlog2n,n2,n3,,2n,n!\log _ { 2 } n , n , n \log _ { 2 } n , n ^ { 2 } , n ^ { 3 } , \ldots , 2 ^ { n } , n ! -An algorithm that lists all ways to put the numbers 1, 2, 3, . . . , n in a row.

Free
(Short Answer)
4.9/5
(50)
Correct Answer:
Verified

n!n !

Give a big-O estimate for the number of operations (where an operation is an addition or a multiplication) used in this segment of an algorithm: t:=0 for i=1 to n for j=1 to n t:=(it+jt+1

Free
(Short Answer)
4.8/5
(34)
Correct Answer:
Verified

O(n2)O \left( n ^ { 2 } \right)

Give a big-O estimate for the number of operations (where an operation is an addition or a multiplication) used in this segment of an algorithm: t:=1 for i=n to t:=t+2it

(Short Answer)
4.9/5
(42)

Prove that x3+7x+2 is Ω(x3)x ^ { 3 } + 7 x + 2 \text { is } \Omega \left( x ^ { 3 } \right)

(Short Answer)
4.8/5
(27)

Prove or disprove that the greedy algorithm for making change always uses the fewest coins possible when the denominations available are 1-cent coins, 8-cent coins, and 20-cent coins.

(True/False)
4.9/5
(34)

Arrange the functions n3/2,log(nn),(n100)nn ^ { 3 / 2 } , \log \left( n ^ { n } \right) , \left( n ^ { 100 } \right) ^ { n } and log(n!)\log ( n ! ) in a list so that each function is big- OO of the next function .

(Short Answer)
4.9/5
(37)

Prove or disprove that the greedy algorithm for making change always uses the fewest coins possible when the denominations available are pennies (1-cent coins), nickels (5-cent coins), and quarters (25-cent coins).

(True/False)
4.9/5
(33)

assume that the number of multiplications of entries used to multiply a p × q and a q × r matrix is pqr. -Whatand 7 ×is 3,therespbestectivorderely?to form the product ABC if A, B and C are matrices with dimensions 2 × 5, 5 × 7

(Short Answer)
4.9/5
(32)

Use the definition of big- OO to prove that 3n84n32n1\frac { 3 n - 8 - 4 n ^ { 3 } } { 2 n - 1 } is O(n2)O \left( n ^ { 2 } \right)

(Essay)
4.8/5
(28)

assume that the number of multiplications of entries used to multiply a p × q and a q × r matrix is pqr. -Whatand 6 ×is 12,therespbestectivorderely?to form the product ABC if A, B and C are matrices with dimensions 8 × 3, 3 × 6

(Short Answer)
4.9/5
(31)

In questions find the "best" big-O notation to describe the complexity of the algorithm. Choose your answers from the following: 1, log2n,n,nlog2n,n2,n3,,2n,n!\log _ { 2 } n , n , n \log _ { 2 } n , n ^ { 2 } , n ^ { 3 } , \ldots , 2 ^ { n } , n ! -The number of print statements in the following: i:=1,j:=1 while i\leqn while j\leqi print "hello"; j:=j+1 i:=i+1

(Short Answer)
4.8/5
(31)

Describe an algorithm that takes a list of n integers (n ≥ 1) and finds the location of the last even integer in the list. and returns 0 if there aer no even integers in the list .

(Essay)
4.8/5
(28)

In questions find the "best" big-O notation to describe the complexity of the algorithm. Choose your answers from the following: 1, log2n,n,nlog2n,n2,n3,,2n,n!\log _ { 2 } n , n , n \log _ { 2 } n , n ^ { 2 } , n ^ { 3 } , \ldots , 2 ^ { n } , n ! -  An iterative algorithm to compute n!, (counting the number of multiplications). \text { An iterative algorithm to compute } n ! \text {, (counting the number of multiplications). }

(Short Answer)
4.9/5
(44)

Express a brute-force algorithm that finds the largest product of two numbers in a list a1, a2, . . . , an (n ≥ 2) that is less than a threshold N .

(Essay)
4.9/5
(33)

Describe an algorithm that takes a list of integers a1, a2, . . . , an (n ≥ 2) and finds the second-largest integer in the sequence by going through the list and keeping track of the largest and second-largest integer encountered.

(Essay)
4.8/5
(30)

In questions find the "best" big-O notation to describe the complexity of the algorithm. Choose your answers from the following: 1, log2n,n,nlog2n,n2,n3,,2n,n!\log _ { 2 } n , n , n \log _ { 2 } n , n ^ { 2 } , n ^ { 3 } , \ldots , 2 ^ { n } , n ! -A linear search to find the smallest number in a list of n numbers.

(Short Answer)
4.9/5
(33)

In questions find the best big-O function for the function. Choose your answer from among the following: 1, log2n,n,nlog2n,n2,n3,,2n,n!\log _ { 2 } n , n , n \log _ { 2 } n , n ^ { 2 } , n ^ { 3 } , \ldots , 2 ^ { n } , n ! - f(n)=1+4+7++(3n+1)f ( n ) = 1 + 4 + 7 + \cdots + ( 3 n + 1 )

(Short Answer)
4.7/5
(35)

Use the definition of big_ OO to prove that 6n+4n547n23\frac { 6 n + 4 n ^ { 5 } - 4 } { 7 n ^ { 2 } - 3 } is O(n3)O \left( n ^ { 3 } \right) .

(Essay)
4.8/5
(30)

Use the definition of big- OO to prove that 1.2+2.3+3.4+...+ (n1)( n - 1 ) . nn is O(n3)O \left( n ^ { 3 } \right)

(Essay)
4.9/5
(38)
Showing 1 - 20 of 52
close modal

Filters

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