Unit 2: Introduction to Array Concepts - Practice Quiz

INT322 — Computing System And Technologies 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is an array?

Definition and initialization of arrays Easy
A. A condition that compares two expressions
B. A collection of elements stored under one name
C. A function that repeats a block of code
D. A variable that stores only text values

2 How are the elements of a one-dimensional array normally stored in memory?

Memory representation of one-dimensional arrays Easy
A. At consecutive memory locations
B. Only inside processor registers
C. Across unrelated storage devices
D. At randomly selected memory locations

3 What does traversing an array mean?

Array traversal Easy
A. Removing the first array element
B. Visiting each array element in sequence
C. Copying the array into a stack
D. Sorting the array in descending order

4 When an element is inserted at the beginning of an array, what may happen to the existing elements?

Array insertion Easy
A. They may shift one position to the right
B. They are permanently removed from memory
C. They are automatically sorted by value
D. They may shift one position to the left

5 After deleting an element from the middle of an array, what is commonly done?

Array deletion Easy
A. The entire array is automatically reversed
B. Every element is changed to zero
C. Later elements are shifted to the left
D. Earlier elements are shifted to the right

6 How does linear search find a target value?

Linear search Easy
A. It swaps adjacent elements repeatedly
B. It removes elements from the end
C. It checks only the middle element
D. It checks elements one by one

7 What condition is normally required before binary search can be used on an array?

Binary search Easy
A. The array must contain only strings
B. The array must contain no duplicates
C. The array must have an odd size
D. The array must already be sorted

8 What does bubble sort repeatedly compare?

Bubble sort Easy
A. Pairs of adjacent array elements
B. Every element with a stack top
C. The array size with each value
D. The first and last elements only

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

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

10 Which access rule does a stack follow?

Definition and operations of stacks Easy
A. Largest In, First Out
B. Smallest In, First Out
C. First In, First Out
D. Last In, First Out

11 What does stack traversal involve?

Stack traversal Easy
A. Removing every element without examining it
B. Visiting the elements currently in the stack
C. Sorting array elements by swapping them
D. Adding an element to a full queue

12 What does the push operation do?

Push operation Easy
A. Searches for an element in an array
B. Adds an element to the front of a queue
C. Adds an element to the top of a stack
D. Removes an element from a stack

13 What does the pop operation do?

Pop operation Easy
A. Removes the top element of a stack
B. Adds an element to the top of a stack
C. Inserts an element into a sorted array
D. Removes the rear element of a queue

14 When does stack underflow occur?

Stack underflow and overflow conditions Easy
A. When popping from a full stack
B. When popping from an empty stack
C. When traversing a nonempty stack
D. When pushing onto an empty stack

15 Which access rule does a queue follow?

Definition and operations of queues Easy
A. Largest In, First Out
B. Last In, First Out
C. Smallest In, Last Out
D. First In, First Out

16 In which direction are queue elements commonly traversed?

Queue traversal Easy
A. From the front toward the rear
B. From the smallest toward the largest
C. From the middle toward the front
D. From the top toward the bottom

17 What does the ENQ operation normally do in a queue?

ENQ operation Easy
A. Removes an element from the rear
B. Removes an element from the middle
C. Adds an element at the front
D. Adds an element at the rear

18 What does the DEQ operation normally do in a queue?

DEQ operation Easy
A. Removes an element from the rear
B. Removes an element from the front
C. Adds an element at the front
D. Adds an element in the middle

19 When does queue overflow occur in a fixed-size queue?

Queue underflow and overflow conditions Easy
A. When removing an element from a full queue
B. When adding an element to an empty queue
C. When traversing a partially filled queue
D. When adding an element to a full queue

20 When does stack overflow occur in a fixed-size stack?

Stack underflow and overflow conditions Easy
A. When pushing onto a full stack
B. When pushing onto an empty stack
C. When reading the top stack element
D. When popping from a full 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?

Definition and initialization of arrays Medium
A. A[2]
B. A[4]
C. A[5]
D. 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?

Memory representation of one-dimensional arrays Medium
A. 1028
B. 1020
C. 1018
D. 1024

23 Which loop correctly visits every element of a zero-indexed array A containing n elements exactly once?

Array traversal Medium
A. for i = 1 to n - 1
B. for i = 1 to n
C. for i = 0 to n
D. 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?

Array insertion Medium
A. [10, 20, 25, 30, 40, 50]
B. [10, 20, 25, 40, 50, 30]
C. [10, 25, 20, 30, 40, 50]
D. [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?

Array deletion Medium
A. [10, 15, 20, 25]
B. [5, 15, 20, 25]
C. [5, 10, 20, 25]
D. [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?

Linear search Medium
A. 3 comparisons
B. 2 comparisons
C. 5 comparisons
D. 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?

Binary search Medium
A. 25, then 31
B. 12, then 25, then 31
C. 17, then 25, then 31
D. 17, then 31

28 Using ascending bubble sort, what is the array after one complete left-to-right pass over [5, 1, 4, 2]?

Bubble sort Medium
A. [5, 1, 2, 4]
B. [1, 4, 2, 5]
C. [1, 5, 2, 4]
D. [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?

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

30 A stack receives push(6), push(9), pop(), and push(12). Which value is now at the top?

Definition and operations of stacks Medium
A. 12
B. No value
C. 9
D. 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?

Stack traversal Medium
A. A, D, C, B
B. D, A, B, C
C. D, C, B, A
D. 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?

Push operation Medium
A. 4
B. 5
C. 6
D. 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?

Pop operation Medium
A. Returns 44; top = 3
B. Returns 33; top = 2
C. Returns 11; top = 2
D. Returns 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?

Stack underflow and overflow conditions Medium
A. Underflow: top == -1; overflow: top == 7
B. Underflow: top == 0; overflow: top == 8
C. Underflow: top == -1; overflow: top == 8
D. Underflow: 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?

Definition and operations of queues Medium
A. 4, 7, 9
B. 9, 7
C. 7, 9
D. 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?

Queue traversal Medium
A. 4, 3, 2, 1
B. 4, 5, 0, 1
C. 1, 0, 5, 4
D. 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?

ENQ operation Medium
A. Index 2
B. Index 0
C. Index 3
D. Index 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?

DEQ operation Medium
A. 5
B. 0
C. 6
D. 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?

Queue underflow and overflow conditions Medium
A. rear == 5
B. (front + 1) % 6 == rear
C. rear == front
D. (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?

Binary search Medium
A. 64 comparisons
B. 128 comparisons
C. 7 comparisons
D. 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?

Definition and initialization of arrays Hard
A. (0, 14, 9, undefined)
B. (0, 5, 9, 0)
C. (0, 14, 9, 0)
D. (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]?

Memory representation of one-dimensional arrays Hard
A.
B.
C.
D.

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?

Array traversal Hard
A. [2, -1, 4]
B. [2, 4]
C. [2, -3, 4, -5]
D. [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?

Array insertion Hard
A. A[p]=x; for (i=n; i>p; --i) A[i]=A[i-1];
B. for (i=n; i>p; --i) A[i]=A[i-1]; A[p]=x;
C. for (i=p; i<n; ++i) A[i+1]=A[i]; A[p]=x;
D. 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?

Array deletion Hard
A.
B.
C.
D.

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?

Linear search Hard
A. i == n-1 && last != x
B. i < n-1 || last == x
C. i != n-1 || last != x
D. 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?

Binary search Hard
A. 3 and 4
B. 2 and 3
C. 1 and 4
D. 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?

Bubble sort Hard
A. 9 comparisons and 1 swap
B. 7 comparisons and 2 swaps
C. 4 comparisons and 1 swap
D. 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?

Complexity analysis of array operations Hard
A. Comparisons ; movements ; total
B. Comparisons ; movements ; total
C. Comparisons ; movements ; total
D. Comparisons ; movements ; total

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?

Definition and operations of stacks Hard
A. 2 → 1 → 4 → 3
B. 3 → 2 → 1 → 4
C. 1 → 3 → 4 → 2
D. 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?

Stack traversal Hard
A. Output A, B, C, D; final top-to-bottom A, B, C, D
B. Output A, B, C, D; final top-to-bottom D, C, B, A
C. Output D, C, B, A; final top-to-bottom A, B, C, D
D. Output 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?

Push operation Hard
A. if (top==C-1) overflow; else A[++top]=x;
B. if (top==C) overflow; else A[++top]=x;
C. if (top==C) overflow; else A[top++]=x;
D. 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?

Pop operation Hard
A. p=top; x=p->data; top=p->next; free(p); return x;
B. x=top->data; top=top->next; free(top); return x;
C. p=top; free(p); top=p->next; return p->data;
D. 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?

Stack underflow and overflow conditions Hard
A. top2 - 1 == top1; one free cell remains
B. top1 == top2; no free cell remains
C. top1 + 1 == top2; no free cell remains
D. 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?

Definition and operations of queues Hard
A. y = D; remaining queue [E, F]
B. y = E; remaining queue [F, D]
C. y = F; remaining queue [D, E]
D. 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?

Queue traversal Hard
A. 6, 7, 0, 1, 2
B. 6, 5, 4, 3, 2
C. 6, 7, 0, 1
D. 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?

ENQ operation Hard
A. if (rear==N-1) overflow; else { Q[rear]=x; rear=rear+1; }
B. if ((rear+1)%N==front) overflow; else { rear=(rear+1)%N; Q[rear]=x; }
C. if (rear==front) overflow; else { Q[rear]=x; rear=(rear+1)%N; }
D. 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?

DEQ operation Hard
A. It returns Q, and front becomes 0
B. It returns P, and front becomes 0
C. It returns P, and front becomes 1
D. It returns 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?

Queue underflow and overflow conditions Hard
A. It is full with 7 elements, so ENQ overflows
B. It is neither full nor empty and stores 6 elements
C. It is full with 8 elements, so DEQ underflows
D. It is empty with 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?

Complexity analysis of array operations Hard
A. Appends ; deletions ; capacity
B. Appends ; deletions ; capacity
C. Appends ; deletions ; capacity
D. Appends ; deletions ; capacity