Algorithms 1 - M1

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

All of the above

Pseudocode is similar to _______________. C Plain French Python Plain Arabic Java Plain English All of the above

n(n-1)/2

Select from the dropdown menu. n−1 ∑ i=1

a sequence (3,10,7,4,200)

Select the best answer. Consider this computational problem: "Sorting a sequence in decreasing order". Check the valid input to this computational problem. a string of characters a sequence (3,10,7,4,200) an algorithm None of these answers an integer

Find the largest number of Sequence A

Select the best answer. Examine the following pseudocode and determine the problem it solves. Procedure(A) n= A.length a = A[1] for j = 1 to n if (a < A[j]) a = A[j] return(a) None of these answers Find the sum of the n first integers Find the largest number of Sequence A Find the smallest number of Sequence A Sort Sequence A

Find the smallest number of Sequence A

Select the best answer. Examine the following pseudocode and determine the problem it solves. Procedure(A) n= A.length a = A[1] for j = 1 to n if (a > A[j]) a = A[j] return(a) Find the smallest number of Sequence A Sort Sequence A None of these answers Find the largest number of Sequence A Find the sum of the n first integers

n

Select the best answer. Examine the following pseudocode. Each line is numbered (leftmost number). We are interested in the number of additions performed. Line 3 performs _________ additions. Procedure(A) 1: n= A.length 2: a = A[1] 3: for j = 1 to n 4: if (a < A[j]) 5: a = A[j] 6: return(a) n+2 n+1 n n-1 None of these answers

Line 4

Select the best answer. Examine the following pseudocode. Each line is numbered (leftmost number). This algorithm must find the smallest number in Sequence A. This algorithm may be flawed. If it is flawed, indicate the line that makes it incorrect (select the option that describes best what is wrong with it), otherwise select "correct". Procedure(A) 1: n= A.length 2: a = A[1] 3: for j = 2 to n 4: if (a < A[j]) 5: a = A[j] 6: return(a) Correct Line 2 Line 4 Line 3 Multiple lines

Line 4

Select the best answer. Examine the following pseudocode. Each line is numbered (leftmost number). This algorithm must find the smallest number in Sequence A. This algorithm may be flawed. If it is flawed, indicate the line that makes it incorrect (select the option that describes best what is wrong with it), otherwise select "correct". Procedure(A) 1: n= A.length 2: a = A[n] 3: for j = 1 to n 4: if (a < A[j]) 5: a = A[j] 6: return(a) Multiple lines Line 2 Line 3 Correct Line 4

n

Select the best answer. Examine the following pseudocode. Each line is numbered (leftmost number). We are interested in the number of comparisons performed. Line 3 performs _________ comparisons. Procedure(A) 1: n= A.length 2: a = A[1] 3: for j = 2 to n 4: if (a < A[j]) 5: a = A[j] 6: return(a)

find the greatest common divisor of two numbers

The Euclid's algorithm is an algorithm to ________________. [] measure the Earth Inclination [] None of these answers [] find the greatest common divisor of two numbers [] find prime numbers [] measure the Earth circumference

find prime numbers

The Sieve of Eratosthenes is an algorithm to ________________.

None of these answers

Which function below has a growth rate higher than a(n) = 1.1^n ? b(n) = 1000n, c(n) = 1,000,000 ln(n), d(n) = 0.001n^3

a(n)

Which function below has a growth rate higher than d(n) = 0.001n^7 ? a(n) = 1.001^n, b(n) = 1000.n, c(n) = 1,000,000 ln(n)

c(n)

Which function below has a growth rate lower than b(n) = 1000n ? a(n) = 3n^2, c(n) = 1,000,000 ln(n), d(n) = 0.001n^3

c(n)

Which function below has a growth rate lower than b(n) = n ? a(n) = n^2, c(n) = ln(n), d(n) = n^3

b(n)

Which function below has a growth rate lower than c(n) = ln(n) ? a(n) = 1.1^n, b(n) = ln(ln(n)), d(n) = n^2

b(n)

Which function below has a growth rate lower than c(n) = ln(n) ? a(n) = 1.1^n, b(n) =1,000,000 ln(ln(n)), d(n) = 0.001n^3

n additions, n + 1 comparisons

for j = 1 to n How many additions in this line? How many comparisons?

Complete in the smallest amount of time Use the least memory space Correct

Check all that apply. A good algorithm must be ___________. [] Complete in the smallest amount of time [] Use the least memory space [] Correct [] Have the smallest number of lines [] Be elegant

Euclid's method Insertion Sort Sieve of Eratosthenes Pascal's Triangle (also known as Pascal's Rule)

Check all that apply. Check algorithms among these: Euclid's method Insertion Sort Sieve of Eratosthenes Sequence Sorting Pascal's Triangle (also known as Pascal's Rule)

the sequence (3, 10, 7, 4, 200)

Consider this computational problem: "Find the maximum number of a sequence of integers". Check a valid input to this computational problem. the sequence (200.3, 10.1, 3.78, 4, 7) a number None of these answers the sequence (3, 10, 7, 4, 200) the sequence (3, 10, 7, 4.1, 200)

the sequence (200, 10, 7, 4, 3)

Consider this computational problem: "Sorting a sequence in decreasing order". Check a correct output. the sequence (200, 4, 7, 10, 3) None of these answers the sequence (200, 10, 3, 4, 7) the sequence (200, 10, 7, 4, 3) the sequence (3, 10, 7, 4, 200)

Line 4

Examine the following pseudocode. Each line is numbered (leftmost number). This algorithm must find the smallest number in Sequence A. This algorithm may be flawed. If it is flawed, indicate the line that makes it incorrect (select the option that describes best what is wrong with it), otherwise select "correct". Procedure(A) 1: n= A.length 2: a = A[n] 3: for j = 1 to n 4: if (a < A[j]) 5: a = A[j] 6: return(a) Correct Line 2 Multiple lines Line 3 Line 4

Line 4

Examine the following pseudocode. Each line is numbered (leftmost number). This algorithm must find the smallest number in Sequence A. This algorithm may be flawed. If it is flawed, indicate the line that makes it incorrect (select the option that describes best what is wrong with it), otherwise select "correct". Procedure(A) 1: n= A.length 2: a = A[1] 3: for j = 1 to n 4: if (a < A[j]) 5: a = A[j] 6: return(a) Multiple lines Correct Line 2 Line 3 Line 4

Line 4

Examine the following pseudocode. Each line is numbered (leftmost number). This algorithm must find the smallest number in Sequence A. This algorithm may be flawed. If it is flawed, indicate the line that makes it incorrect (select the option that describes best what is wrong with it), otherwise select "correct". Procedure(A) 1: n= A.length 2: a = A[1] 3: for j = 2 to n 4: if (a < A[j]) 5: a = A[j] 6: return(a)

Correct

Examine the following pseudocode. Each line is numbered (leftmost number). This algorithm must find the smallest number in Sequence A. This algorithm may be flawed. If it is flawed, indicate the line that makes it incorrect (select the option that describes best what is wrong with it), otherwise select "correct". Procedure(A) 1: n= A.length 2: a = A[n] 3: for j = 1 to n 4: if (a > A[j]) 5: a = A[j] 6: return(a) Line 3 Line 4 Multiple lines Line 2 Correct

n

Examine the following pseudocode. Each line is numbered (leftmost number). We are interested in the number of comparisons performed. Line 3 performs _________ comparisons. Procedure(A) 1: n= A.length 2: a = A[1] 3: for j = 1 to n-1 4: if (a < A[j]) 5: a = A[j] 6: return(a) n n-1 n+1 n+2 None of these answers

5

Examine the following pseudocode. Each line is numbered (leftmost number). We are interested in the number of comparisons performed. Line 3 performs _________ comparisons. Procedure(A) 1: n= A.length 2: a = A[1] 3: for j = 2 to 5 4: if (a < A[j]) 5: a = A[j] 6: return(a)

5

Examine the following pseudocode. Each line is numbered (leftmost number). We are interested in the number of comparisons performed. Line 4 performs _________ comparisons. Procedure(A) 1: n= A.length 2: a = A[1] 3: for j = 1 to 5 4: if (a < A[j]) 5: a = A[j] 6: return(a)

2

Examine the following pseudocode. We are interested in the space complexity. Using a space unit similar to what was used in class, the sum_nFirstIntegers(n) algorithm will use ___________ space units. sum_nFirstIntegers(n) sum = 0 for j = 1 to n sum += j return(sum) None of these answers n+1 3 2 n + 2

16, -1

Examine this algorithm. Given a sequence A and an element e, this algorithm returns the largest index of e in Sequence A if A contains e. If A does not contain e, this algorithm returns -1. find-Element(e,A) index = A.length while ((index > 0) and (A[index]≠ e)) index = index - 1 if (index <= 0) index = -1 return(index) Given this problem instance [e=4, A=(3, 7, 54, 2, 100, 2, 45)], this algorithm will execute ____comparisons and will return _____.

7, 5

Examine this algorithm. Given a sequence A and an element e, this algorithm returns the largest index of e in Sequence A if A contains e. If A does not contain e, this algorithm returns -1. find-Element(e,A) index = A.length while ((index > 0) and (A[index]≠ e)) index = index - 1 if (index <= 0) index = -1 return(index) Given this problem instance [e=100, A=(3, 7, 54, 2, 100, 2, 45)], this algorithm will execute _____ comparisons and will return _____.

9, 4

Examine this algorithm. Given a sequence A and an element e, this algorithm returns the largest index of e in Sequence A if A contains e. If A does not contain e, this algorithm returns -1. find-Element(e,A) index = A.length while ((index > 0) and (A[index]≠ e)) index = index - 1 if (index <= 0) index = -1 return(index) Given this problem instance [e=3, A=(3, 7, 54, 3, 100, 2, 45)], this algorithm will execute ["2", "8", "9", "3", "None of these answers"] comparisons and will return ["1", "3", "4", "-1", "2"]

n

Examine this algorithm. Given a sequence A and an element e, this algorithm returns the smallest index of e in Sequence A if A contains e. If A does not contain e, this algorithm returns -1. find-Element(e,A) index = 1 while ((index ≤ A.length) and (A[index]≠ e)) index = index + 1 if (index > A.length) index = -1 return(index) Given this problem instance with an n-items sequence and a number e. In the average case, the number of comparisons for this algorithm will grow as _____.

3, 1

Examine this algorithm. Given a sequence A and an element e, this algorithm returns the smallest index of e in Sequence A if A contains e. If A does not contain e, this algorithm returns -1. find-Element(e,A) index = 1 while ((index ≤ A.length) and (A[index]≠ e)) index = index + 1 if (index > A.length) index = -1 return(index) Given this problem instance [e=3, A=(3, 7, 54, 2, 100, 2, 45)], this algorithm will execute ____ comparisons and will return ____

2(n+1)

Examine this algorithm. Given a sequence A and an element e, this algorithm returns the smallest index of e in Sequence A if A contains e. If A does not contain e, this algorithm returns -1. find-Element(e,A) index = 1 while ((index ≤ A.length) and (A[index]≠ e)) index = index + 1 if (index > A.length) index = -1 return(index) Given this problem instance with an n-items sequence and a number e. This algorithm will perform at most _____ comparisons.

3

Examine this algorithm. Given a sequence A and an element e, this algorithm returns the smallest index of e in Sequence A if A contains e. If A does not contain e, this algorithm returns -1. find-Element(e,A) index = 1 while ((index ≤ A.length) and (A[index]≠ e)) index = index + 1 if (index > A.length) index = -1 return(index) Given this problem instance with an n-items non empty sequence and a number e. This algorithm will perform at least ___ comparisons.

n+1

Examine this algorithm. Given a sequence A and an element e, this algorithm returns the smallest index of e in Sequence A if A contains e. If A does not contain e, this algorithm returns -1. find-Element(e,A) index = 1 while ((index ≤ A.length) and (A[index]≠ e)) index = index + 1 if (index > A.length) index = -1 return(index) Given this problem instance with an n-items sequence and a number e. Assuming that e is in A, this algorithm will perform on average ____ comparisons.

15, 7

Examine this algorithm. Given a sequence A and an element e, this algorithm returns the smallest index of e in Sequence A if A contains e. If A does not contain e, this algorithm returns -1. find-Element(e,A) index = 1 while ((index ≤ A.length) and (A[index]≠ e)) index = index + 1 if (index > A.length) index = -1 return(index) Given this problem instance [e=45, A=(3, 7, 54, 2, 100, 2, 45)], this algorithm will execute ["15", "None of these answers", "16", "14", "8"] comparisons and will return ["None of these answers", "7", "5", "-1", "6"]

7, 3

Examine this algorithm. Given a sequence A and an element e, this algorithm returns the smallest index of e in Sequence A if A contains e. If A does not contain e, this algorithm returns -1. find-Element(e,A) index = 1 while ((index ≤ A.length) and (A[index]≠ e)) index = index + 1 if (index > A.length) index = -1 return(index) Given this problem instance [e=54, A=(3, 7, 54, 2, 100, 2, 45)], this algorithm will execute ["3", "7", "None of these answers", "8", "6"] comparisons and will return ["3", "None of these answers", "4", "-1", "2"]

n

Examine this algorithm. Given a sequence A and an element e, this algorithm returns the smallest index of e in Sequence A if A contains e. If A does not contain e, this algorithm returns -1. find-Element(e,A) index = 1 while ((index ≤ A.length) and (A[index]≠ e)) index = index + 1 if (index > A.length) index = -1 return(index) Given this problem instance with an n-items sequence and a number e. In the worst case, the number of comparisons for this algorithm will grow as _____ time

constant

Examine this algorithm. Given a sequence A and an element e, this algorithm returns the smallest index of e in Sequence A if A contains e. If A does not contain e, this algorithm returns -1. find-Element(e,A) index = 1 while ((index ≤ A.length) and (A[index]≠ e)) index = index + 1 if (index > A.length) index = -1 return(index) Given this problem instance with an n-items sequence and a number e. In the best case, the number of comparisons for this algorithm will grow as _____ time.

120

Fill in a numerical answer. 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 +15 = _____________ .

117

Fill in a numerical answer. 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 +15 = _____________ .

(1.2)^n

Let the function f(n) defined as: f(n) = 1,000,000n^100 + 0.000000001 (1.2)^n + 1,000,000 f(n) grows as _______. (1.2)^n n^100 Constant 1,000,000

n

Let the function f(n) defined as: f(n) = 4n + 10.5n + 1,000,000 f(n) grows as _______. n Constant 4n 10.5n None of these answers

4, n, n-1, n-5, n-4, n^2

The objective of this exercise is to determine the time complexity of this algorithm that takes as input a sequence S of numbers and output the same sequence S' sorted in decreasing order. First, this algorithm has a bug on line # ["1", "4", "2", "None of these answers", "3"] . Line # 2 performs ["n+1", "n-1", "n+2", "n"] comparisons and ["n+2", "n-1", "n", "n+1", "None of these answers"] additions during the full execution of this algorithm. When j is equal to 5, the inner loop will execute ["n-4", "None of these answers", "n", "n-5", "n-6"] times. When j is equal to 5, Line # 3 will perform ["n-4", "None of these answers", "n", "n-5", "n-6"] comparisons. This algorithm will most likely grow like ["n^2", "n", "ln(n)", "None of these answers", "a constant"] . sortArrayDecreasing(S) 1: n = S.length 2: for j = 1 to n-1 3: for i = j+1 to n 4: if (S[j] >= S[i]) 5: a =S[j] 6: S[j] = S[i] 7: S[i] = a 8: return

n+1, n, n, n-1, n-2, 2, 1, n(n+1)/2, n^2

The objective of this exercise is to determine the time complexity of this algorithm that takes as input an n x n matrix M and computes its transpose. We assume that the first line starts at i=1 and the first column starts at j =1. Line # 2 performs ["n+1", "n", "None of these answers", "n+2", "n-1"] comparisons and ["n+1", "n+2", "None of these answers", "n-1", "n"] additions during the full execution of this algorithm. Let us call tk the number of times the statement "buffer = M[j][i]" is executed when i=k. t1 is equal to _____ . t2 is equal to ____. t3 is equal to ______. tn-1 is equal to _____ . tn is equal to _______. Let the sum S be: S=∑k=1k=ntk (summation) S is equal to ["n(n+1)", "n(n-1)", "n(n-1)/2", "None of these answers", "n(n+1)/2"]. The sum S grows like ["Constant", "None of these answers", "n", "n^2", "ln(n)"] . transposeMatrix(M) 1: //Transpose a Matrix M 2: for i = 1 to n 3: for j = i to n 4: buffer = M[j][i] 5: M[j][i] = M[i][j] 6: M[i][j] = buffer 7: return

3, n+1, n, n^2, n(n+1), n^2, n^2

The objective of this exercise is to determine the time complexity of this algorithm that takes as input an n x n matrix M and initialize it. We assume that the first line starts at i=1 and the first column starts at j =1. First, this algorithm has a bug on line #["None of these answers", "3", "4", "2", "1"]. Answer all the next questions assuming that the bug is corrected. Line # 2 performs ["n", "None of these answers", "n+2", "n+1", "n-1"] comparisons and ["n-1", "n", "n+1", "None of these answers", "n+2"] additions during the full execution of this algorithm. The assignment statement "M.. = 0.0" will be executed ["n^2", "n^2-n", "n", "(n+1)^2", "None of these answers"] times. In total, the inner loop will perform _______ comparisons. This total number of comparisons of this algorithm grows as ["ln(n)", "Constant", "None of these answers", "n^2", "n"]. This total number of comparisons, additions and assignment (M...=0.0) of this algorithm grows as ["Constant", "n", "(n+1)^2", "n^2", "None of these answers"] . InitializeMatrix(M) 1: //Initialize Matrix to 0.0 for each element 2: for j = 1 to n 3: for i = 1 to n-1 4: M[i][j] = 0.0 5: return

31,536,000,000

The objective of this exercise is to find the largest input size N that an algorithm A with time complexity f(n) can handle in one year. We assume that f(n) is expressed in milliseconds. If f(n) = n, then Algorithm A can handle in one year a problem of size n up to ________.

177,583.78

The objective of this exercise is to find the largest input size N that an algorithm A with time complexity f(n) can handle in one year. We assume that f(n) is expressed in milliseconds. If f(n) = n^2, then Algorithm A can handle in one year a problem of size n up to ________.

24

The objective of this exercise is to find the largest input size N that an algorithm A with time complexity f(n) can handle in one year. We assume that f(n) is expressed in milliseconds. If f(n) = e^n, then Algorithm A can handle in a year a problem of size n up to ________.

Extremely large number

The objective of this exercise is to find the largest input size N that an algorithm A with time complexity f(n) can handle in one year. We assume that f(n) is expressed in milliseconds. If f(n) = ln(n), then Algorithm A can handle in one year a problem of size n up to _________. [] Extremely large number (larger than all other options)) [] 365*24*3600*1,000,000 [] 315,360x10^5 [] 315,360x10^3 [] 315,360 [] None of these answers

3159

The objective of this exercise is to find the largest input size N that an algorithm A with time complexity f(n) can handle in one year. We assume that f(n) is expressed in milliseconds. If f(n) = n3, then Algorithm A can handle in one year a problem of size n up to ________.

177,583

The objective of this exercise is to find the largest input size N that an algorithm A with time complexity f(n) can handle in one year. We assume that f(n) is expressed in milliseconds. If f(n) = n^2, then Algorithm A can handle in one year a problem of size n up to ________.

Al Khawarizimi

The origin of the word Algorithm stems from _____________.

Line 3

This algorithm must find the smallest number in Sequence A. This algorithm may be flawed. If it is flawed, indicate the line that makes it incorrect (select the option that describes best what is wrong with it), otherwise select "correct". Procedure(A) 1: n= A.length 2: a = A[n] 3: for j = 2 to n-1 4: if (a > A[j]) 5: a = A[j] 6: return(a) Line 4 Correct Multiple lines Line 2 Line 3

False

True or False. Examine the following pseudocode. We are interested in the space complexity. The space complexity for the sum_nFirstIntegers(n) algorithm will increase as n increases. sum_nFirstIntegers(n) sum = 0 for j = 1 to n sum += j return(sum)


संबंधित स्टडी सेट्स

CVL-FoSV: Il sistema nervoso centrale

View Set

ECON Chapter 4 --- Before Class Quiz

View Set

Pharmacology: Chapter 34: Drugs Used to Treat Constipation and Diarrhea

View Set

Synonyms and Antonyms (Letter D)

View Set

Chapter 66: Neurologic Dysfunction

View Set