Unit 1: Basic Data Structures - Practice Quiz

CSE329 — Prelude To Competitive Coding 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is the index of the first element in a standard array in languages like C, C++, and Java?

Arrays Easy
A.
B.
C. Depends on array size
D.

2 How many elements can a 2D array declared as int a[3][4] hold?

Declaring and processing 1D and 2D arrays Easy
A.
B.
C.
D.

3 When inserting an element at the beginning of an array of elements, how many existing elements must be shifted?

Insertion in an array Easy
A.
B.
C.
D.

4 What is the worst-case time complexity of deleting an element from an array?

Deletion from array Easy
A.
B.
C.
D.

5 If the array is left-rotated by positions, what is the result?

Array rotations Easy
A.
B.
C.
D.

6 To multiply matrix of size with matrix , what must be true?

Matrix multiplication Easy
A. and must be equal in size
B. Rows of equal columns of
C. Columns of equal rows of
D. and must be square

7 In an upper triangular matrix, which elements are zero?

Lower triangular and upper triangular matrix of array Easy
A. All elements below the main diagonal
B. All elements above the main diagonal
C. All elements in the first row
D. All diagonal elements

8 When printing a matrix in spiral form, in which order are the boundaries typically traversed first?

Print a matrix in spiral form Easy
A. Left column, top row, right column, bottom row
B. Top row, right column, bottom row, left column
C. Right column, bottom row, left column, top row
D. Bottom row, left column, top row, right column

9 In C, which character marks the end of a string stored in a character array?

String declaration and manipulation Easy
A. Space ' '
B. Tab \t
C. Newline \n
D. Null character \0

10 A pangram is a sentence that contains:

Missing characters to make a string Pangram Easy
A. No repeated words
B. Exactly 26 words
C. Only vowels
D. Every letter of the alphabet at least once

11 Two strings are anagrams of each other if they:

Remove minimum number of characters so that two strings become anagram Easy
A. Contain the same characters with the same frequencies
B. Have the same length only
C. Start with the same letter
D. Are exactly identical strings

12 A stack follows which principle for insertion and removal of elements?

Creation of stack using arrays Easy
A. Priority based
B. FIFO (First In First Out)
C. Random access
D. LIFO (Last In First Out)

13 A queue follows which order for processing elements?

Creation of queue using array Easy
A. Reverse order
B. LIFO (Last In First Out)
C. FIFO (First In First Out)
D. Sorted order

14 What advantage does a circular queue have over a simple linear queue implemented with arrays?

Circular Queue Easy
A. It removes the need for a front pointer
B. It reuses empty spaces created after dequeuing
C. It allows random access to elements
D. It stores elements in sorted order

15 In a deque (double-ended queue), insertion and deletion can be performed at:

Implementation of Deque using circular array Easy
A. Only the front
B. Both the front and the rear
C. Only the middle
D. Only the rear

16 The two-pointer technique for finding a pair with a given sum is most efficiently applied to an array that is:

Two pointer technique depicted by problem to find if there exists a pair in an unsorted array whose sum is equal to X Easy
A. Circular
B. Unsorted
C. Sorted
D. Empty

17 A peak element in an array is an element that is:

Finding a peak element in array Easy
A. The largest element only
B. The first element only
C. Greater than or equal to its neighbors
D. Always at the middle index

18 In an array of size , the majority element is one that appears:

Find the majority element Easy
A. More than once
B. Exactly times
C. At least once
D. More than times

19 In the array , what is the first non-repeating element?

Find the first non-repeating element in a given array of integers Easy
A.
B.
C.
D.

20 After moving all zeros to the end of while keeping the order of non-zero elements, the result is:

Move All Zeros to End of Array Easy
A.
B.
C.
D.

21 An array arr = [1, 2, 3, 4, 5] is left-rotated by 2 positions. What is the resulting array?

Array rotations Medium
A. [2, 1, 5, 4, 3]
B. [3, 4, 5, 1, 2]
C. [5, 4, 3, 2, 1]
D. [4, 5, 1, 2, 3]

22 To insert an element at index in an array of size (with space available), how many elements must be shifted in the worst case?

Insertion in an array Medium
A.
B.
C.
D.

23 Two matrices of dimension and of dimension can be multiplied as only if:

Matrix multiplication Medium
A.
B.
C.
D.

24 For the matrix , what is the spiral order traversal starting from the top-left?

Print a matrix in spiral form Medium
A. 1 2 3 6 5 4 7 8 9
B. 1 4 7 8 9 6 3 2 5
C. 1 2 3 6 9 8 7 4 5
D. 1 2 3 4 5 6 7 8 9

25 In a square matrix , an element belongs to the upper triangular part when:

Lower triangular and upper triangular matrix of array Medium
A.
B.
C.
D.

26 To use the two-pointer technique to find a pair summing to , what preprocessing step is required on an unsorted array?

Two pointer technique depicted by problem to find if there exists a pair in an unsorted array whose sum is equal to X Medium
A. Remove duplicates first
B. Build a prefix sum array first
C. Reverse the array first
D. Sort the array first

27 In the array [3, 3, 4, 2, 3, 3, 5, 3], which element is the majority element (appears more than times)?

Find the majority element Medium
A. 4
B. 2
C. No majority element exists
D. 3

28 After moving all zeros to the end of [0, 1, 0, 3, 12] while keeping non-zero order, the result is:

Move All Zeros to End of Array Medium
A. [0, 0, 1, 3, 12]
B. [12, 3, 1, 0, 0]
C. [1, 3, 0, 0, 12]
D. [1, 3, 12, 0, 0]

29 A peak element is one that is greater than or equal to its neighbors. In [1, 3, 20, 4, 1, 0], which index holds a peak element?

Finding a peak element in array Medium
A. Index 3 (value 4)
B. Index 2 (value 20)
C. Index 5 (value 0)
D. Index 0 (value 1)

30 A pangram contains every letter of the alphabet. For the string "the quick brown fox", how many distinct letters are missing to make it a pangram?

Missing characters to make a string Pangram Medium
A. 8
B. 11
C. 5
D. 15

31 Given strings "bcadeh" and "hea", what is the minimum number of characters to remove from both so they become anagrams of each other?

Remove minimum number of characters so that two strings become anagram Medium
A. 6
B. 4
C. 2
D. 3

32 For which string is it impossible to rearrange so that no two adjacent characters are the same?

Rearrange characters so that no two adjacent characters are same Medium
A. "aab"
B. "aaab"
C. "aabb"
D. "abab"

33 When implementing a stack using two queues with a costly push operation, what happens during a push?

Implement Stack using Queues Medium
A. The new element is enqueued, then all previous elements are dequeued and re-enqueued behind it
B. The element is enqueued to the second queue only
C. Both queues are swapped without moving elements
D. The element is simply enqueued to the main queue

34 In a circular queue of size implemented with an array, after enqueue the rear pointer is updated as:

Circular Queue Medium
A. rear = (rear + n) % 1
B. rear = (rear + 1) % n
C. rear = rear + 1
D. rear = (rear - 1) % n

35 When implementing two stacks in a single array of size efficiently, where should the two stacks begin growing from?

Implement two Stacks in an array Medium
A. Both from index 0, alternating slots
B. One uses even indices, the other uses odd indices
C. Both from the middle, growing outward
D. One from the start (index 0) growing forward, the other from the end (index ) growing backward

36 For counting subarrays where the sum of even-indexed elements equals the sum of odd-indexed elements, a common technique uses:

Count subarrays having an equal sum of elements at even and odd positions Medium
A. A stack of running maximums
B. A prefix-difference (even minus odd) with a hash map of first occurrences
C. Binary search on prefix sums
D. A two-pointer sliding window on sorted data

37 After rearranging [4, 3, 7, 8, 6, 2, 1] so that even-index elements are smaller than their odd-index neighbors (a wave-like pattern), which is a valid result?

Rearrange array such that even index elements are smaller and odd index elements are greater Medium
A. [3, 4, 7, 8, 2, 6, 1]
B. [4, 3, 8, 7, 6, 2, 1]
C. [1, 2, 3, 4, 6, 7, 8]
D. [8, 7, 6, 4, 3, 2, 1]

38 In the array [9, 4, 9, 6, 7, 4], what is the first non-repeating element?

Find the first non-repeating element in a given array of integers Medium
A. 4
B. 6
C. 9
D. 7

39 On a plank of length , ants moving toward each other pass through without changing direction. For finding the last moment before all ants fall off, the key insight is:

Last Moment Before All Ants Fall Out of a Plank Medium
A. Two colliding ants passing through are equivalent to two ants continuing in their original directions
B. Collisions add up delays that must be summed for each pair
C. The last moment equals the total number of ants times the plank length
D. Ants moving left always fall before ants moving right

40 Which data structure is most naturally used to reverse a queue while preserving the queue's FIFO interface?

Reversing a Queue Medium
A. A circular buffer
B. A priority queue
C. Another queue
D. A stack

41 An array A of size is left-rotated by positions using the reversal algorithm (reverse , reverse , then reverse the whole array). For and , what is the resulting array?

Array rotations Hard
A.
B.
C.
D.

42 For an matrix printed in spiral order, how many direction-boundary shrink operations (adjusting top/bottom/left/right) occur in total during traversal?

Print a matrix in spiral form Hard
A. Exactly adjustments, one per element
B. Exactly 4 adjustments total, once per side
C. Exactly 4 boundary variables are adjusted a total that scales with
D. Exactly adjustments regardless of shape

43 Using the Boyer-Moore Voting Algorithm on , what are the final candidate and count values just before the verification pass?

Find the majority element Hard
A. candidate , count
B. candidate , count
C. candidate , count
D. candidate , count

44 Two stacks are implemented in a single array of size using the space-efficient approach (stack1 grows from index 0, stack2 grows from index ). What is the correct overflow condition when pushing to either stack, given tops top1 and top2?

Implement two Stacks in an array Hard
A. top1 == top2
B. top1 + top2 == n
C. top1 + 1 == top2
D. top1 == n / 2

45 For strings s1 = "bcadeh" and s2 = "hea", what is the minimum number of characters to delete (from either string) to make them anagrams of each other?

Remove minimum number of characters so that two strings become anagram Hard
A.
B.
C.
D.

46 On a plank of length , ants moving left are at positions and ants moving right are at . When two ants collide they reverse direction. What is the last moment before all ants fall off?

Last Moment Before All Ants Fall Out of a Plank Hard
A.
B.
C.
D.

47 To find whether a pair sums to in an unsorted array using the two-pointer technique, what preprocessing is required and what is the resulting overall time complexity?

Two pointer technique depicted by problem to find if there exists a pair in an unsorted array whose sum is equal to X Hard
A. Build a hash set, giving overall
B. Sort first, giving overall
C. Sort first, giving overall
D. No preprocessing, giving overall

48 The trick to count subarrays where the sum of even-indexed and odd-indexed elements are equal is to negate elements at odd positions and then:

Count subarrays having an equal sum of elements at even and odd positions Hard
A. count subarrays with sum using prefix-sum frequencies
B. count subarrays with maximum sum using Kadane
C. count all pairs where
D. count subarrays with sum equal to the total array sum

49 Binary search finds a peak element (an element its neighbors) in . If A[mid] < A[mid+1], which direction guarantees a peak exists?

Finding a peak element in array Hard
A. Search the right half (mid+1 .. hi)
B. Search the left half (lo .. mid)
C. Search the left half including mid (lo .. mid-1)
D. Either half works equally well

50 A rearrangement of a string with no two adjacent equal characters is possible if and only if the maximum character frequency maxFreq satisfies which condition for a string of length ?

Rearrange characters so that no two adjacent characters are same Hard
A.
B.
C.
D.

51 To support push, pop, and findMiddle/deleteMiddle all in , which data structure is used and why?

Design a stack with operations on middle element Hard
A. A singly linked list with a tail pointer
B. A dynamic array with an index to the middle
C. Two stacks balancing each other
D. A doubly linked list with a pointer to the middle node

52 In a deque implemented with a circular array of capacity , indices front and rear, which expression correctly moves front backward during insertFront?

Implementation of Deque using circular array Hard
A. front = (front - 1 + n) % n
B. front = (front + 1) % n
C. front = (front - 1) % n
D. front = front - 1

53 When implementing a stack using a single queue, making push the costly operation, what is the sequence of steps for push(x) on a queue currently holding elements?

Implement Stack using Queues Hard
A. Enqueue , then dequeue and re-enqueue all elements
B. Enqueue only; no rotation is needed
C. Dequeue all elements, enqueue , then re-enqueue the rest
D. Enqueue , then dequeue and re-enqueue the first elements

54 For the string "the quick brown fox" (ignoring spaces, lowercase), how many distinct letters must be added to make it a pangram?

Missing characters to make a string Pangram Hard
A.
B.
C.
D.

55 Using the two-pointer approach with a insertPos pointer, how many swaps occur for A = [0, 1, 0, 3, 12] while preserving the order of non-zero elements?

Move All Zeros to End of Array Hard
A.
B.
C.
D.

56 A single flip means toggling exactly one contiguous group of adjacent same-bits. All bits can be made same by a single flip iff the number of 'groups' of consecutive equal bits is at most:

Check if all bits can be made same by single flip Hard
A.
B.
C.
D.

57 For an matrix, how many elements belong strictly to the upper triangular part (excluding the main diagonal)?

Lower triangular and upper triangular matrix of array Hard
A.
B.
C.
D.

58 Which approach finds the first non-repeating element in optimal time, and what is that complexity for elements?

Find the first non-repeating element in a given array of integers Hard
A. Sort then scan,
B. Nested loops comparing all pairs,
C. Single pass with a hash map,
D. Two passes with a hash map of counts,

59 For a valid 'wave-like' arrangement where A[0] < A[1] > A[2] < A[3] > ..., which single-pass swapping rule achieves this in without sorting?

Rearrange array such that even index elements are smaller and odd index elements are greater Hard
A. Reverse the array and swap alternate elements
B. For each odd index , swap with if A[i-1] > A[i], and with if A[i+1] > A[i]
C. For each even index, swap with the global maximum found so far
D. Sort the array then swap adjacent pairs from the start

60 Given two sorted (descending) arrays, to find the maximum pairwise sums , the efficient approach uses a max-heap starting with which pair, and pushes which neighbors after each extraction?

K maximum sum from two arrays Hard
A. Start with all pairs in the heap; pop times
B. Start with ; after popping push and with a visited set
C. Start with ; after popping push only
D. Start with the last indices; after popping push only