Unit 1: Basic Data Structures - Practice Quiz
1 What is the index of the first element in a standard array in languages like C, C++, and Java?
2
How many elements can a 2D array declared as int a[3][4] hold?
3 When inserting an element at the beginning of an array of elements, how many existing elements must be shifted?
4 What is the worst-case time complexity of deleting an element from an array?
5 If the array is left-rotated by positions, what is the result?
6 To multiply matrix of size with matrix , what must be true?
7 In an upper triangular matrix, which elements are zero?
8 When printing a matrix in spiral form, in which order are the boundaries typically traversed first?
9 In C, which character marks the end of a string stored in a character array?
' '
\t
\n
\0
10 A pangram is a sentence that contains:
11 Two strings are anagrams of each other if they:
12 A stack follows which principle for insertion and removal of elements?
13 A queue follows which order for processing elements?
14 What advantage does a circular queue have over a simple linear queue implemented with arrays?
15 In a deque (double-ended queue), insertion and deletion can be performed at:
16 The two-pointer technique for finding a pair with a given sum is most efficiently applied to an array that is:
17 A peak element in an array is an element that is:
18 In an array of size , the majority element is one that appears:
19 In the array , what is the first non-repeating element?
20 After moving all zeros to the end of while keeping the order of non-zero elements, the result is:
21
An array arr = [1, 2, 3, 4, 5] is left-rotated by 2 positions. What is the resulting array?
[2, 1, 5, 4, 3]
[3, 4, 5, 1, 2]
[5, 4, 3, 2, 1]
[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?
23 Two matrices of dimension and of dimension can be multiplied as only if:
24 For the matrix , what is the spiral order traversal starting from the top-left?
1 2 3 6 5 4 7 8 9
1 4 7 8 9 6 3 2 5
1 2 3 6 9 8 7 4 5
1 2 3 4 5 6 7 8 9
25 In a square matrix , an element belongs to the upper triangular part when:
26 To use the two-pointer technique to find a pair summing to , what preprocessing step is required on an unsorted array?
27
In the array [3, 3, 4, 2, 3, 3, 5, 3], which element is the majority element (appears more than times)?
4
2
3
28
After moving all zeros to the end of [0, 1, 0, 3, 12] while keeping non-zero order, the result is:
[0, 0, 1, 3, 12]
[12, 3, 1, 0, 0]
[1, 3, 0, 0, 12]
[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?
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?
8
11
5
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?
6
4
2
3
32 For which string is it impossible to rearrange so that no two adjacent characters are the same?
"aab"
"aaab"
"aabb"
"abab"
33 When implementing a stack using two queues with a costly push operation, what happens during a push?
34
In a circular queue of size implemented with an array, after enqueue the rear pointer is updated as:
rear = (rear + n) % 1
rear = (rear + 1) % n
rear = rear + 1
rear = (rear - 1) % n
35 When implementing two stacks in a single array of size efficiently, where should the two stacks begin growing from?
36 For counting subarrays where the sum of even-indexed elements equals the sum of odd-indexed elements, a common technique uses:
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?
[3, 4, 7, 8, 2, 6, 1]
[4, 3, 8, 7, 6, 2, 1]
[1, 2, 3, 4, 6, 7, 8]
[8, 7, 6, 4, 3, 2, 1]
38
In the array [9, 4, 9, 6, 7, 4], what is the first non-repeating element?
4
6
9
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:
40 Which data structure is most naturally used to reverse a queue while preserving the queue's FIFO interface?
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?
42 For an matrix printed in spiral order, how many direction-boundary shrink operations (adjusting top/bottom/left/right) occur in total during traversal?
43 Using the Boyer-Moore Voting Algorithm on , what are the final candidate and count values just before the verification pass?
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?
top1 == top2
top1 + top2 == n
top1 + 1 == top2
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?
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?
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?
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:
49
Binary search finds a peak element (an element its neighbors) in . If A[mid] < A[mid+1], which direction guarantees a peak exists?
mid+1 .. hi)
lo .. mid)
lo .. mid-1)
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 ?
51
To support push, pop, and findMiddle/deleteMiddle all in , which data structure is used and why?
52
In a deque implemented with a circular array of capacity , indices front and rear, which expression correctly moves front backward during insertFront?
front = (front - 1 + n) % n
front = (front + 1) % n
front = (front - 1) % n
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?
54
For the string "the quick brown fox" (ignoring spaces, lowercase), how many distinct letters must be added to make it a pangram?
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?
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:
57 For an matrix, how many elements belong strictly to the upper triangular part (excluding the main diagonal)?
58 Which approach finds the first non-repeating element in optimal time, and what is that complexity for elements?
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?
A[i-1] > A[i], and with if A[i+1] > A[i]
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?
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →