Unit 1: Introduction - Practice Quiz

ECAP538 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 Which principle describes how elements are removed from a stack?

Elementary data structures Easy
A. First In, First Out
B. Smallest Value First
C. Largest Value First
D. Last In, First Out

2 Which principle is normally followed by a queue?

Elementary data structures Easy
A. First In, First Out
B. Random In, Random Out
C. Middle In, First Out
D. Last In, First Out

3 Which data structure stores elements that are commonly accessed using an index?

Elementary data structures Easy
A. Queue
B. Stack
C. Graph
D. Array

4 In the basic Random Access Machine model, how are simple operations usually treated?

Basic computational models Easy
A. As taking quadratic time
B. As taking linear time
C. As taking logarithmic time
D. As taking constant time

5 What is the main purpose of a computational model in algorithm analysis?

Basic computational models Easy
A. To design user interfaces
B. To format program output
C. To choose variable names
D. To define operation costs

6 What does commonly represent when analysing an algorithm?

Basic computational models Easy
A. The name of the algorithm
B. The number of processors
C. The size of the input
D. The value of one instruction

7 What does the best-case running time describe?

Analysis of algorithms: best-case, average-case, and worst-case behaviour Easy
A. The minimum time for an input of size
B. The fixed time for every input of size
C. The expected time across inputs of size
D. The maximum time for an input of size

8 What does the worst-case running time describe?

Analysis of algorithms: best-case, average-case, and worst-case behaviour Easy
A. The exact number of operations
B. The minimum number of operations
C. The maximum number of operations
D. The average number of operations

9 What does average-case analysis estimate?

Analysis of algorithms: best-case, average-case, and worst-case behaviour Easy
A. The longest running time
B. The expected running time
C. The shortest running time
D. The compilation running time

10 What is the worst-case number of element comparisons in a linear search through elements?

Analysis of algorithms: best-case, average-case, and worst-case behaviour Easy
A.
B.
C.
D.

11 What does big notation commonly express?

Asymptotic notations: big O notation Easy
A. An asymptotic lower bound
B. An input probability value
C. An exact instruction count
D. An asymptotic upper bound

12 Which complexity represents linear growth?

Asymptotic notations: big O notation Easy
A.
B.
C.
D.

13 Which notation represents constant-time complexity?

Asymptotic notations: big O notation Easy
A.
B.
C.
D.

14 What is the big complexity of ?

Asymptotic notations: big O notation Easy
A.
B.
C.
D.

15 What is recursion?

Recursion Easy
A. A variable changing its type
B. A function calling itself
C. A loop running without conditions
D. An array sorting its elements

16 What is the purpose of a base case in recursion?

Recursion Easy
A. To increase the input size
B. To repeat the recursive call
C. To remove the return value
D. To stop the recursive calls

17 Which formula correctly defines factorial recursively for ?

Recursion Easy
A.
B.
C.
D.

18 What does a recurrence relation describe in recursive algorithm analysis?

Recurrence relations to analyse recursive algorithms Easy
A. Syntax using language keywords
B. Memory using unrelated programs
C. Running time using smaller inputs
D. Output using random variables

19 What is the asymptotic solution of with ?

Recurrence relations to analyse recursive algorithms Easy
A.
B.
C.
D.

20 What is the asymptotic solution of with ?

Recurrence relations to analyse recursive algorithms Easy
A.
B.
C.
D.

21 A queue initially contains , with at the front. After performing dequeue, enqueue(40), and enqueue(50), what is the queue from front to rear?

Elementary data structures Medium
A.
B.
C.
D.

22 Which data structure is most appropriate for processing nested function calls in the order required for returns?

Elementary data structures Medium
A. A queue
B. A stack
C. A hash table
D. A linked list that always removes its oldest element first

23 A graph has vertices and edges, where is much smaller than . Which representation generally uses less space?

Elementary data structures Medium
A. A stack containing all possible vertex pairs
B. An adjacency matrix using space
C. An adjacency list using space
D. A table that stores every absent edge along with every present edge

24 A binary search tree contains the keys inserted in that order. Which key is the left child of ?

Elementary data structures Medium
A.
B.
C.
D.

25 In the unit-cost RAM model, an algorithm executes primitive operations. What running time is assigned to it asymptotically?

Basic computational models Medium
A.
B.
C.
D. because each individual RAM instruction has constant cost

26 In the comparison model, a comparison-based sorting algorithm is represented by a binary decision tree. What does each leaf represent?

Basic computational models Medium
A. The memory location of an input key
B. A single comparison between two keys
C. A possible ordering of the input
D. The complete sequence of machine instructions used by every execution

27 Why can treating arithmetic on arbitrarily large integers as a constant-time operation produce a misleading analysis?

Basic computational models Medium
A. The cost can depend on the number of bits
B. The cost is determined only by how many variables the algorithm declares
C. Integer operations are unsupported by the RAM model
D. Every arithmetic operation requires recursive code

28 For linear search on an array of distinct elements, which situation gives the best-case running time?

Analysis of algorithms: best-case, average-case, and worst-case behaviour Medium
A. The target is the first element
B. The target is the final element
C. The target is absent from the array
D. The target occurs after exactly half of the array has been examined

29 Suppose a successful linear search is equally likely to target any of the array positions. What is the expected number of comparisons?

Analysis of algorithms: best-case, average-case, and worst-case behaviour Medium
A.
B.
C.
D.

30 Quicksort always chooses the first element as its pivot. Which input is most likely to produce its worst-case behaviour?

Analysis of algorithms: best-case, average-case, and worst-case behaviour Medium
A. An array whose first value happens to equal the median on every recursive call
B. An array split into equal unsorted halves
C. An already sorted array
D. A randomly shuffled array

31 An algorithm takes operations with probability and operations with probability . What is its expected operation count?

Analysis of algorithms: best-case, average-case, and worst-case behaviour Medium
A.
B.
C.
D.

32 What is the tightest big O bound among the choices for ?

Asymptotic notations: big O notation Medium
A.
B.
C.
D.

33 Consider a loop where starts at and is doubled after each iteration until . What is the loop's running time?

Asymptotic notations: big O notation Medium
A.
B. because multiplication by two is itself a constant-time operation
C.
D.

34 An outer loop runs times, while an inner loop runs from through the current outer-loop index . What is the total running time?

Asymptotic notations: big O notation Medium
A.
B.
C.
D.

35 What value is returned by the following function when called as ? and for .

Recursion Medium
A.
B.
C.
D.

36 A recursive function reduces its argument from to and performs constant work per call. What is its maximum call-stack depth?

Recursion Medium
A.
B.
C. because every active call stores all results from earlier calls
D.

37 Which change is necessary to prevent infinite recursion in a function that repeatedly calls itself with a smaller positive integer?

Recursion Medium
A. Store the argument in a queue
B. Add a reachable base case
C. Increase the argument before every recursive call so that it eventually overflows
D. Use two recursive calls

38 What is the asymptotic solution of with ?

Recurrence relations to analyse recursive algorithms Medium
A.
B.
C.
D.

39 What is the asymptotic solution of with ?

Recurrence relations to analyse recursive algorithms Medium
A.
B.
C.
D. because the recurrence contains a recursive term for every smaller input

40 What is the asymptotic solution of with ?

Recurrence relations to analyse recursive algorithms Medium
A.
B.
C.
D.

41 A dynamic array starts empty with capacity . Whenever an append finds the array full, its capacity is doubled and all existing elements are copied before the new element is inserted. If , how many existing-element copies occur during the first appends?

Elementary data structures Hard
A.
B.
C.
D.

42 A queue is implemented using input and output stacks. Enqueue pushes onto the input stack; dequeue transfers every item to the output stack only when the output stack is empty. For any sequence of operations starting from empty, which bounds are tight?

Elementary data structures Hard
A. Worst-case ; amortized
B. Worst-case ; amortized
C. Worst-case ; amortized
D. Worst-case ; amortized

43 A disjoint-set forest uses both union by rank and path compression. For operations, including Make-Set operations, which asymptotic bound applies to the total running time?

Elementary data structures Hard
A.
B.
C.
D.

44 Which capability is available in a word-RAM with -bit words but not generally in a pure pointer-machine model?

Basic computational models Hard
A. Comparing two stored keys in constant time
B. Following a stored pointer in constant time
C. Accessing array cell from an integer index
D. Updating a constant number of pointer fields

45 An algorithm computes using multiplications. Why does the claim that its running time is fail in the bit-complexity model?

Basic computational models Hard
A. Factorial cannot be represented exactly
B. The number of recursive calls is exponential
C. The algorithm requires comparison sorting
D. Multiplication cost grows with operand length

46 In the deterministic comparison-tree model, an algorithm sorts distinct keys. What lower bound follows directly from the number of possible input orders?

Basic computational models Hard
A. At least comparisons in the worst case
B. At least comparisons on every input
C. At least comparisons in the worst case
D. At least comparisons in the worst case

47 A binary string of length is selected uniformly from all nonzero strings. An algorithm scans left to right and stops at the first . What is the exact expected number of inspected bits?

Analysis of algorithms: best-case, average-case, and worst-case behaviour Hard
A.
B.
C.
D.

48 Randomized Quicksort chooses its pivot uniformly from the current subarray. For any fixed input containing distinct keys, which statement correctly distinguishes expected and worst-randomness behavior?

Analysis of algorithms: best-case, average-case, and worst-case behaviour Hard
A. Expected ; worst choices
B. Expected ; worst choices
C. Expected ; worst choices
D. Expected ; worst choices

49 An algorithm has best-case running time and worst-case running time . Without specifying an input distribution, what can be concluded about its average-case time?

Analysis of algorithms: best-case, average-case, and worst-case behaviour Hard
A. It cannot have any asymptotic bound
B. It must be
C. It must be
D. It lies between and

50 For integers , let . Which statement is true?

Asymptotic notations: big O notation Hard
A.
B.
C.
D.

51 Let . Which asymptotic classification is correct for every fixed and ?

Asymptotic notations: big O notation Hard
A. and
B. and
C. and
D. and

52 Define when is prime and otherwise. Which relation between and is correct?

Asymptotic notations: big O notation Hard
A.
B. and
C. but
D. but

53 Quicksort is modified to recurse only on the smaller partition and to process the larger partition by iteration. What are the tight worst-case time and auxiliary-stack bounds?

Recursion Hard
A. time and stack
B. time and stack
C. time and stack
D. time and stack

54 A top-down recursive Fibonacci algorithm evaluates and memoizes every computed value. Including the memo table and recursion stack, what are its tight time and space bounds?

Recursion Hard
A. time and space
B. time and space
C. time and space
D. time and space

55 Consider a recursive procedure that makes two separate calls on and performs local work, without memoization. What is its total running time?

Recursion Hard
A.
B.
C.
D.

56 For powers of two, solve with .

Recurrence relations to analyse recursive algorithms Hard
A.
B.
C.
D.

57 Assume constant base-case cost. What is the solution of ?

Recurrence relations to analyse recursive algorithms Hard
A.
B.
C.
D.

58 For powers of two and constant base-case cost, solve for .

Recurrence relations to analyse recursive algorithms Hard
A.
B.
C.
D.

59 Given and , which bound is tight?

Recurrence relations to analyse recursive algorithms Hard
A.
B.
C.
D.

60 For sufficiently large , let with a constant-size base case. What is the tight solution?

Recurrence relations to analyse recursive algorithms Hard
A.
B.
C.
D.