Unit 2: Introduction to Array Concepts - Practice Quiz
1 What is an array?
2 How are the elements of a one-dimensional array normally stored in memory?
3 What does traversing an array mean?
4 When an element is inserted at the beginning of an array, what may happen to the existing elements?
5 After deleting an element from the middle of an array, what is commonly done?
6 How does linear search find a target value?
7 What condition is normally required before binary search can be used on an array?
8 What does bubble sort repeatedly compare?
9 What is the typical time complexity of accessing an array element by its index?
10 Which access rule does a stack follow?
11 What does stack traversal involve?
12 What does the push operation do?
13 What does the pop operation do?
14 When does stack underflow occur?
15 Which access rule does a queue follow?
16 In which direction are queue elements commonly traversed?
17 What does the ENQ operation normally do in a queue?
18 What does the DEQ operation normally do in a queue?
19 When does queue overflow occur in a fixed-size queue?
20 When does stack overflow occur in a fixed-size stack?
21
In a zero-indexed language, an integer array is initialized as A = [7, 14, 21, 28, 35]. Which expression accesses the value 28?
A[2]
A[4]
A[5]
A[3]
22
An integer array begins at address 1000, and each element occupies 4 bytes. What is the address of A[6] if indexing starts at zero?
1028
1020
1018
1024
23
Which loop correctly visits every element of a zero-indexed array A containing n elements exactly once?
for i = 1 to n - 1
for i = 1 to n
for i = 0 to n
for i = 0 to n - 1
24
The array [10, 20, 30, 40, 50] has one unused position at the end. After inserting 25 at index 2, what is the resulting array?
[10, 20, 25, 30, 40, 50]
[10, 20, 25, 40, 50, 30]
[10, 25, 20, 30, 40, 50]
[10, 20, 30, 25, 40, 50]
25
The element at index 1 is deleted from [5, 10, 15, 20, 25], and remaining elements are shifted left. What is the logical array afterward?
[10, 15, 20, 25]
[5, 15, 20, 25]
[5, 10, 20, 25]
[5, 15, 20, 10]
26
A linear search examines [12, 7, 19, 4, 15] from left to right. How many comparisons are required to find 4?
3 comparisons
2 comparisons
5 comparisons
4 comparisons
27
Binary search is used on [3, 8, 12, 17, 25, 31, 40] to find 31. Using the middle index rounded down, which values are compared with the target?
25, then 31
12, then 25, then 31
17, then 25, then 31
17, then 31
28
Using ascending bubble sort, what is the array after one complete left-to-right pass over [5, 1, 4, 2]?
[5, 1, 2, 4]
[1, 4, 2, 5]
[1, 5, 2, 4]
[1, 2, 4, 5]
29 An element is inserted at the beginning of a full logical array that has spare physical capacity. What is the worst-case time complexity of the insertion?
30
A stack receives push(6), push(9), pop(), and push(12). Which value is now at the top?
12
9
6
31
A stack contains A, B, C, and D, where D is the top. In which order are elements encountered when traversing from top to bottom?
A, D, C, B
D, A, B, C
D, C, B, A
A, B, C, D
32
An array-based stack of capacity 6 uses top = -1 when empty. If it currently contains four elements, what is top immediately after one valid push?
4
5
6
3
33
An array-based stack is [11, 22, 33, 44] with top = 3. What does one pop return, and what is the new value of top?
44; top = 3
33; top = 2
11; top = 2
44; top = 2
34
For an array-based stack of capacity 8 using zero-based indexing and top = -1 for an empty stack, which pair correctly identifies underflow and overflow checks?
top == -1; overflow: top == 7
top == 0; overflow: top == 8
top == -1; overflow: top == 8
top == 0; overflow: top == 7
35
An initially empty queue performs ENQ(4), ENQ(7), DEQ(), and ENQ(9). What are its contents from front to rear?
4, 7, 9
9, 7
7, 9
4, 9
36
A circular queue of capacity 6 has front = 4, rear = 1, and occupied indices 4, 5, 0, 1. Which index order correctly traverses the queue?
4, 3, 2, 1
4, 5, 0, 1
1, 0, 5, 4
0, 1, 4, 5
37
A circular queue has capacity 5, rear = 3, and is not full. At which index will the next enqueued element be placed?
2
0
3
4
38
A circular queue of capacity 7 has front = 5 and contains more than one element. After one dequeue, what is the new value of front?
5
0
6
4
39
In a circular queue of capacity 6, which condition indicates that the queue is full when front and rear are valid element indices?
rear == 5
(front + 1) % 6 == rear
rear == front
(rear + 1) % 6 == front
40
A sorted array contains 128 distinct elements. In the worst case, at most how many comparisons are needed for a successful binary search?
64 comparisons
128 comparisons
7 comparisons
8 comparisons
41
In C11, the following declaration and update are executed: int a[8] = { [2] = 5, [5] = 9 }; a[2] += a[0] + a[5];. What is (a[0], a[2], a[5], a[7]) afterward?
(0, 14, 9, undefined)
(0, 5, 9, 0)
(0, 14, 9, 0)
(undefined, 14, 9, undefined)
42
An array has base address , lower index bound , and element width bytes. Using contiguous row-major storage, what is the address of A[7]?
43
Consider for (i = 0; i < n; i++) if (A[i] < 0) { shift A[i+1..n-1] one place left; n--; }. If the initial logical array is [2, -1, -3, 4, -5], what logical array remains?
[2, -1, 4]
[2, 4]
[2, -3, 4, -5]
[2, -3, 4]
44
A zero-indexed array has length n, spare capacity, and a new value x must be inserted stably at index p. Which operation preserves every existing element?
A[p]=x; for (i=n; i>p; --i) A[i]=A[i-1];
for (i=n; i>p; --i) A[i]=A[i-1]; A[p]=x;
for (i=p; i<n; ++i) A[i+1]=A[i]; A[p]=x;
for (i=n-1; i>=p; --i) A[i]=A[i+1]; A[p]=x;
45
A stable deletion from index p shifts all later elements left. Starting with length , delete index , then delete index from the resulting array, where and . How many element-to-element assignments are performed?
46
A sentinel search for x in a nonempty array executes last=A[n-1]; A[n-1]=x; i=0; while (A[i]!=x) i++; A[n-1]=last;. Which condition correctly determines whether x was originally present?
i == n-1 && last != x
i < n-1 || last == x
i != n-1 || last != x
i < n-1 && last == x
47
The following half-open binary search is applied to [1, 3, 3, 3, 8]: low=0; high=n; while (low<high) { mid=low+(high-low)/2; if (A[mid]<x) low=mid+1; else high=mid; }. What values are returned for x=3 and x=4, respectively?
3 and 4
2 and 3
1 and 4
1 and 3
48
An optimized bubble sort runs passes starting at pass=0, compares indices j and j+1 for j=0,...,n-2-pass, and stops after a pass with no swaps. For [1, 2, 4, 3, 5], how many comparisons and swaps occur?
9 comparisons and 1 swap
7 comparisons and 2 swaps
4 comparisons and 1 swap
7 comparisons and 1 swap
49 A sorted array is built by inserting keys supplied in strictly descending order. Each insertion position is found by binary search, after which elements are shifted to preserve order. What are the asymptotic costs?
50
The values 1, 2, 3, 4 are pushed onto one initially empty stack in that order, with pop operations allowed between pushes. Which complete pop sequence is impossible?
2 → 1 → 4 → 3
3 → 2 → 1 → 4
1 → 3 → 4 → 2
3 → 1 → 2 → 4
51
A stack initially contains A, B, C, D from top to bottom. A recursive procedure pops x, recursively processes the remaining stack, outputs x, and then pushes x back. What is the output order and final stack order?
A, B, C, D; final top-to-bottom A, B, C, D
A, B, C, D; final top-to-bottom D, C, B, A
D, C, B, A; final top-to-bottom A, B, C, D
D, C, B, A; final top-to-bottom D, C, B, A
52
An array stack of capacity C uses top=-1 when empty. Which guarded push operation correctly inserts x without an out-of-bounds write?
if (top==C-1) overflow; else A[++top]=x;
if (top==C) overflow; else A[++top]=x;
if (top==C) overflow; else A[top++]=x;
if (top==C-1) overflow; else A[top++]=x;
53
For a nonempty linked stack whose top points to the first node, which pop sequence returns the top value, updates the stack, and avoids use-after-free?
p=top; x=p->data; top=p->next; free(p); return x;
x=top->data; top=top->next; free(top); return x;
p=top; free(p); top=p->next; return p->data;
p=top->next; x=top->data; free(p); top=p; return x;
54
Two stacks share an array of size N. Stack 1 grows upward with top1=-1 initially, while stack 2 grows downward with top2=N initially. Which condition means that a subsequent push to either stack would overflow?
top2 - 1 == top1; one free cell remains
top1 == top2; no free cell remains
top1 + 1 == top2; no free cell remains
top1 + 1 == N; no free cell remains
55
Starting with an empty FIFO queue, execute ENQ(A), ENQ(B), ENQ(C), DEQ(), ENQ(D), ENQ(E), DEQ(), DEQ(), ENQ(F). Then execute x=DEQ(); ENQ(x); y=DEQ();. What is y, and what remains from front to rear?
y = D; remaining queue [E, F]
y = E; remaining queue [F, D]
y = F; remaining queue [D, E]
y = D; remaining queue [F, E]
56
A circular queue uses an array of size 8, with front and rear both pointing to occupied endpoints. If front=6 and rear=2, which indices are visited in FIFO order?
6, 7, 0, 1, 2
6, 5, 4, 3, 2
6, 7, 0, 1
6, 7, 0, 1, 2, 3
57
A circular queue of array size N leaves one slot unused. front points to the first element and rear points to the next insertion slot. Which guarded ENQ(x) operation is correct?
if (rear==N-1) overflow; else { Q[rear]=x; rear=rear+1; }
if ((rear+1)%N==front) overflow; else { rear=(rear+1)%N; Q[rear]=x; }
if (rear==front) overflow; else { Q[rear]=x; rear=(rear+1)%N; }
if ((rear+1)%N==front) overflow; else { Q[rear]=x; rear=(rear+1)%N; }
58
A circular queue of size 6 uses front for the first element and rear for the next free slot. It has front=5, rear=1, Q[5]=P, and Q[0]=Q. What does one DEQ return, and what is the new front?
Q, and front becomes 0
P, and front becomes 0
P, and front becomes 1
Q, and front becomes 1
59
A circular queue uses an array of size 8, leaves one slot unused, and represents emptiness by front==rear. If front=3 and rear=2, which description is correct?
7 elements, so ENQ overflows
6 elements
8 elements, so DEQ underflows
0 elements, so DEQ underflows
60 A dynamic array starts empty and doubles its capacity whenever full. After append operations, all elements are deleted one at a time from the front, preserving order by shifting. What are the total append cost, total deletion cost, and peak capacity?
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 →