Unit 1: Introduction, Arrays, Sorting and Searching - Practice Quiz

CSE205 — Data Structures And Algorithms 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is an algorithm?

Basic concepts and notations Easy
A. A diagram showing only computer hardware
B. A collection of unrelated programming statements
C. A physical device used to store information
D. A finite sequence of steps for solving a problem

2 What does complexity analysis primarily measure?

Complexity analysis Easy
A. The number of programmers required
B. The color scheme of a program
C. The price of the computer system
D. The resources used by an algorithm

3 What does a time-space trade-off mean?

Time-space trade-off Easy
A. Using more memory to reduce execution time
B. Using more comments to reduce program size
C. Using more hardware to increase code length
D. Using fewer variables to increase input size

4 What does Omega notation describe for an algorithm?

Omega notation Easy
A. An asymptotic lower bound
B. An exact memory address
C. An average array value
D. An asymptotic upper bound

5 What does Theta notation represent?

Theta notation Easy
A. Only an asymptotic lower bound
B. A fixed array position
C. Only an asymptotic upper bound
D. A tight asymptotic bound

6 Which notation is commonly used to express an asymptotic upper bound?

Big O notation Easy
A. notation
B. notation
C. notation
D. notation

7 Which of the following is a linear data structure?

Basic data structures Easy
A. Heap
B. Graph
C. Array
D. Tree

8 How are elements organized in a linear array?

Linear arrays Easy
A. In a hierarchical order
B. In a sequential order
C. In a network structure
D. In a random graph

9 How are the elements of a standard one-dimensional array usually stored in memory?

Memory representation of arrays Easy
A. In contiguous memory locations
B. In unrelated memory locations
C. Only inside secondary storage
D. Only inside CPU registers

10 What is array traversal?

Array traversal Easy
A. Removing the first array element
B. Visiting each array element
C. Sorting only duplicate elements
D. Combining two array indexes

11 When an element is inserted at the beginning of an array, what may need to happen?

Array insertion Easy
A. Existing elements shift right
B. The last element becomes first
C. All elements become sorted
D. Existing elements shift left

12 When an array element is deleted from the middle, what commonly fills the empty position?

Array deletion Easy
A. A new array inserted there
B. Earlier elements shifted right
C. The deleted element copied again
D. Later elements shifted left

13 What is the purpose of sorting an array?

Array sorting Easy
A. To increase the array capacity
B. To remove every repeated element
C. To convert elements into indexes
D. To arrange elements in a chosen order

14 What is the main goal of searching an array?

Array searching Easy
A. To duplicate the entire array
B. To reverse all array elements
C. To locate a specified element
D. To change the array data type

15 What does merging two arrays produce?

Array merging Easy
A. Two arrays containing sorted elements
B. One array containing their elements
C. One array containing only duplicates
D. Two arrays containing fewer indexes

16 What is the typical time complexity of accessing an array element by its index?

Complexity analysis of array operations Easy
A.
B.
C.
D.

17 What does bubble sort repeatedly compare?

Bubble sort Easy
A. Elements from separate arrays
B. Randomly selected elements
C. Adjacent elements
D. First and last elements

18 How does insertion sort build the sorted portion of an array?

Insertion sort Easy
A. By swapping only the first and last elements
B. By selecting elements at random positions
C. By repeatedly dividing the array into halves
D. By inserting each element into its proper position

19 In ascending selection sort, which element is usually selected during each pass?

Selection sort Easy
A. The first duplicate element
B. The middle array element
C. The smallest remaining element
D. The largest processed element

20 Which statement correctly distinguishes binary search from linear search?

Linear search Easy
A. Linear search always divides the range
B. Binary search requires sorted data
C. Linear search requires sorted data
D. Binary search checks every element

21 A list ADT specifies operations such as insertion, deletion, and retrieval but does not specify how elements are stored. Which statement best describes this distinction?

Basic concepts and notations Medium
A. The ADT defines hardware details, while an algorithm defines storage size
B. The ADT defines execution time, while a data structure defines correctness
C. The ADT defines memory addresses, while an algorithm provides the values
D. The ADT defines behavior, while a data structure provides an implementation

22 What is the time complexity of the following code?

for i = 1 to n:
for j = 1 to i:
process(A[j])

Complexity analysis Medium
A.
B.
C.
D.

23 An application repeatedly tests whether values occur in a fixed array. Which approach uses extra space to reduce the average lookup time?

Time-space trade-off Medium
A. Apply selection sort separately before every query
B. Store the values in a hash table before processing queries
C. Scan the array from the beginning for every query
D. Copy the array into another unsorted linear array

24 If , which option gives the tightest asymptotic lower bound listed?

Omega notation Medium
A.
B.
C.
D.

25 An algorithm performs exactly primitive operations for sufficiently large . What is its tight asymptotic complexity?

Theta notation Medium
A.
B.
C.
D.

26 For , which option is the tightest Big O bound listed?

Big O notation Medium
A.
B.
C.
D.

27 A linear array has a lower index bound of and an upper index bound of . How many elements can it store?

Linear arrays Medium
A. elements
B. elements
C. elements
D. elements

28 An integer array begins at address , each element occupies bytes, and indexing starts at . What is the address of ?

Memory representation of arrays Medium
A.
B.
C.
D.

29 An algorithm visits each element of an array of size once and performs constant-time work per element. If the array size doubles, what happens asymptotically to the running time?

Array traversal Medium
A. It becomes approximately twice as large
B. It becomes approximately four times larger
C. It becomes approximately logarithmically larger
D. It remains approximately unchanged

30 A linear array currently contains elements at indices through . To insert a new value at index while preserving order, how many existing elements must be shifted?

Array insertion Medium
A. elements
B. elements
C. elements
D. elements

31 An array contains elements at indices through . If the element at index is deleted while preserving order, how many elements must be shifted left?

Array deletion Medium
A. elements
B. elements
C. elements
D. elements

32 A sorting method must preserve the original relative order of records having equal keys. Which property is required?

Array sorting Medium
A. The method must be recursive
B. The method must be stable
C. The method must be in-place
D. The method must be adaptive

33 A fixed unsorted array of elements will receive many search queries. Which strategy has the better asymptotic total time when the number of queries is large?

Array searching Medium
A. Reverse once and then scan backward for each query
B. Sort once and then use binary search for each query
C. Use linear search independently for every query
D. Copy once and then scan both arrays for each query

34 Two sorted arrays contain and elements. Using the standard two-pointer merge, what is the maximum number of element comparisons needed?

Array merging Medium
A.
B.
C.
D.

35 A dynamic array doubles its capacity whenever it becomes full. What are the amortized and worst-case time complexities of appending one element?

Complexity analysis of array operations Medium
A. Amortized and worst-case
B. Amortized and worst-case
C. Amortized and worst-case
D. Amortized and worst-case

36 Using ascending bubble sort, what is the array after one complete left-to-right pass over ?

Bubble sort Medium
A.
B.
C.
D.

37 How many element shifts does insertion sort perform when sorting in ascending order?

Insertion sort Medium
A. shifts
B. shifts
C. shifts
D. shifts

38 What is the array after the first two passes of ascending selection sort on ?

Selection sort Medium
A.
B.
C.
D.

39 A successful linear search is performed on an array of elements. If the target is equally likely to be at any position, what is the expected number of comparisons?

Linear search Medium
A. comparisons
B. comparisons
C. comparisons
D. comparisons

40 Binary search uses on a sorted array indexed from to . How many comparisons are made when searching for the value at index ?

Binary search Medium
A. comparisons
B. comparisons
C. comparisons
D. comparisons

41 An algorithm has best-case time and worst-case time . Its average-case time is under one particular input distribution. Which conclusion is guaranteed independently of the input distribution?

Basic concepts and notations Hard
A. Every input takes time, and some input takes time
B. At least half of all inputs take time for each input size
C. Every input takes time, and some input takes time
D. Every input takes time, except for finitely many input sizes

42 What is the tight asymptotic running time of the following loop nest, assuming the innermost body takes constant time?

for i = 1 to n

for j = 1 to i

for k = 1; k <= j; k = 2*k

constant-time operation

Complexity analysis Hard
A.
B.
C.
D.

43 A static set contains distinct keys from a universe of size . Implementation D uses a direct-address table, while implementation S uses a sorted array. Ignoring the storage of the keys themselves, which comparison correctly describes their worst-case membership queries and auxiliary space?

Time-space trade-off Hard
A. D uses space and query time; S uses space and query time
B. D uses space and query time; S uses space and query time
C. D uses space and query time; S uses space and query time
D. D uses space and query time; S uses space and query time

44 Define when is a power of two and otherwise. Which is the strongest asymptotic lower bound among the following choices that holds for every sufficiently large integer ?

Omega notation Hard
A.
B.
C.
D.

45 For powers of two, let and . What is the tight asymptotic solution?

Theta notation Hard
A.
B.
C.
D.

46 Let for . Which option is the tightest valid Big O bound listed?

Big O notation Hard
A.
B.
C.
D.

47 A circular queue is implemented in an array of capacity , reserving one empty cell. front points to the first element and rear to the next insertion cell. Initially, front = 6 and rear = 2. After three dequeues followed by four enqueues, what are the final indices and number of stored elements, assuming no operation fails?

Linear arrays Hard
A. front = 1, rear = 5, with 4 elements
B. front = 2, rear = 6, with 4 elements
C. front = 1, rear = 6, with 5 elements
D. front = 0, rear = 5, with 5 elements

48 A two-dimensional array is stored in row-major order. Each element occupies bytes, and the address of is . What is the address of ?

Memory representation of arrays Hard
A.
B.
C.
D.

49 A row-major integer array is traversed once. A cache line holds consecutive integers. The cache is initially empty, fully associative, uses LRU, and holds lines. Ignoring all other memory traffic, how many cache misses occur for row-wise and column-wise traversal, respectively?

Array traversal Hard
A. row-wise and column-wise
B. row-wise and column-wise
C. row-wise and column-wise
D. row-wise and column-wise

50 An array initially contains elements. Exactly elements are then inserted one at a time at index , with all existing elements shifted right for each insertion. How many element shifts are performed in total?

Array insertion Hard
A.
B.
C.
D.

51 A contiguous array initially has elements. The first element is deleted times in succession, where , and each deletion shifts every remaining element left. What is the total number of shifts?

Array deletion Hard
A.
B.
C.
D.

52 The array contains each integer from to exactly once. What is the minimum number of arbitrary element swaps required to sort it?

Array sorting Hard
A.
B.
C.
D.

53 A sorted array of length may contain duplicates. An algorithm must return every index whose value equals . If there are matches, what is the optimal worst-case running time in the comparison model?

Array searching Hard
A.
B.
C.
D.

54 Two sorted arrays of lengths and are merged using the standard two-pointer algorithm. What are the minimum and maximum possible numbers of key comparisons?

Array merging Hard
A. Minimum and maximum
B. Minimum and maximum
C. Minimum and maximum
D. Minimum and maximum

55 A dynamic array starts with capacity and doubles whenever an append finds it full. Appending writes the new element once, and resizing copies every existing element once. If exactly elements are appended, how many total element writes, including copies, occur?

Complexity analysis of array operations Hard
A.
B.
C.
D.

56 Standard left-to-right bubble sort uses a shrinking unsorted boundary and stops early after a pass with no swaps. On the input , how many key comparisons and swaps are performed?

Bubble sort Hard
A. comparisons and swaps
B. comparisons and swaps
C. comparisons and swaps
D. comparisons and swaps

57 Insertion sort is run on for . Counting only comparisons between the key and an array element, how many such comparisons and element shifts occur?

Insertion sort Hard
A. comparisons and shifts
B. comparisons and shifts
C. comparisons and shifts
D. comparisons and shifts

58 Selection sort repeatedly finds the minimum of the unsorted suffix and swaps only when that minimum is not already in position. On a reverse-sorted array of distinct elements, how many key comparisons and swaps occur?

Selection sort Hard
A. comparisons and swaps
B. comparisons and swaps
C. comparisons and swaps
D. comparisons and swaps

59 A linear search examines an array of length . The search is successful with probability , and conditional on success, the target position is uniformly distributed among the indices. What is the expected number of key comparisons?

Linear search Hard
A.
B.
C.
D.

60 Consider lower-bound binary search on a sorted array using the half-open interval [low, high). It updates low = mid + 1 when A[mid] < x; otherwise it updates high = mid. Which invariant is sufficient to prove that the final low is the first index whose value is at least ?

Binary search Hard
A. Every index through low has value less than , and every index after high has value at least
B. Every index below low has value at most , and every index above high has value greater than
C. Every index below high has value less than , and every index at or above low has value at least
D. Every index below low has value less than , and every index at or above high has value at least