CS Quiz 6
What would be printed if the following instructions were executed? X = 3 while (X > 0): print(3) X = X - 1 X X X 3 2 1 3 2 1 0 3 3 3
3 3 3
What would be printed if the following instructions were executed? X = 3 print(X) Y = 5 if (X < Y): print(6) else: print(7) 3 7 3 6 3 6 7 6 7
3 6
Which of the following lists would not be obtained at some point when applying the insertion sort algorithm to the list below? Sylvia Nancy Lois Alice Alice Lois Nancy Sylvia Nancy Sylvia Lois Alice Lois Nancy Sylvia Alice Alice Sylvia Nancy Lois
Alice Sylvia Nancy Lois
Preconditions, postconditions, and loop invariants are examples of which of the following? Iterative structures Recursion Pseudocode Assertions
Assertions
In general, which search algorithm is more efficient? Binary Search Random Search Linear search Sequential Search
Binary Search
In general, which sorting algorithm is less efficient? Insertion Sort Binary Search Sequential Search Bubble Sort
Bubble Sort
Which of the following is not a component of repetitive control? Initialize Modify Test Comments
Comments
Under the assumption that N takes on only integer values, which of the following is the termination condition in the following recursive function? def xxx(N): if (N < 5): xxx(N + 1) else: print(N) N > 4 N < 5 N < 4 N < 3
N > 4
When searching within the list Lewis, Maurice, Nathan, Oliver, Pat, Quincy, Roger, Stan, Tom which of the following entries will be found most quickly using the sequential algorithm? Tom Pat Stan Nathan
Nathan
Which of the following is a representation of an algorithm? Program Process Algorithm Activity
Program
The technique of applying a program segment within itself if-else statement Recursion Pseudocode Pretest loop
Recursion
Which of the following is a means of repeating a block of instructions? Subtraction Addition Assignment Recursion
Recursion
When searching within the list Lewis, Maurice, Nathan, Oliver, Pat, Quincy, Roger, Stan, Tom which of the following entries will be found most quickly using the binary search algorithm? Roger Ahmad Tom Lewis
Roger
Which of the following is not an approach to problem solving? Stepwise refinment top-down methodology Sidewise refinment bottom-up methodology
Sidewise refinment
Which of the following is not a way of representing algorithms? Programming language Pseudocode Top-down approach Flowchart
Top-down approach
Under the assumption that X takes on only integer values, which of the following is the termination condition for the following loop? repeat: . . . until (X < 5) X > 5 X = 6 X < 5 X > 4
X < 5
Under the assumption that X takes on only integer values, which of the following is the termination condition for the following loop? while (X <= 5): X>5 X<5 X>4 X<4
X>5
A building block used in algorithms construction is called: pyramid programming language process primitive
primitive
The binary search algorithm is an example of an algorithm in which of the following classes? Θ(n2) Θ(n3) Θ(n) Θ(log2n)
Θ(log2n)
In general, an algorithm in which of the following categories is considered more efficient? Θ(n3) Θ(n) Θ(nlog2n) Θ(n2)
Θ(n)