Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
Question 1 of 60 · Definition and initialization of arrays · Easy
What is an array?
Not quite. Try another option.
Answer: A collection of elements stored under one name
An array stores multiple elements, usually of the same data type, under a single name.
Question 2 of 60 · Memory representation of one-dimensional arrays · Easy
How are the elements of a one-dimensional array normally stored in memory?
Not quite. Try another option.
Answer: At consecutive memory locations
The elements of a one-dimensional array are stored in contiguous, or consecutive, memory locations.
Question 3 of 60 · Array traversal · Easy
What does traversing an array mean?
Not quite. Try another option.
Answer: Visiting each array element in sequence
Array traversal means accessing each element of the array, usually one after another.
Question 4 of 60 · Array insertion · Easy
When an element is inserted at the beginning of an array, what may happen to the existing elements?
Not quite. Try another option.
Answer: They may shift one position to the right
Existing elements may need to move right to create space for the new element.
Question 5 of 60 · Array deletion · Easy
After deleting an element from the middle of an array, what is commonly done?
Not quite. Try another option.
Answer: Later elements are shifted to the left
Elements after the deleted position are commonly shifted left to close the gap.
Question 6 of 60 · Linear search · Easy
How does linear search find a target value?
Not quite. Try another option.
Answer: It checks elements one by one
Linear search examines each element in sequence until the target is found or the array ends.
Question 7 of 60 · Binary search · Easy
What condition is normally required before binary search can be used on an array?
Not quite. Try another option.
Answer: The array must already be sorted
Binary search relies on sorted data so that it can discard half of the remaining elements after each comparison.
Question 8 of 60 · Bubble sort · Easy
What does bubble sort repeatedly compare?
Not quite. Try another option.
Answer: Pairs of adjacent array elements
Bubble sort compares adjacent elements and swaps them when they are in the wrong order.
Question 9 of 60 · Complexity analysis of array operations · Easy
What is the typical time complexity of accessing an array element by its index?
Not quite. Try another option.
Answer:
Direct index access takes constant time, represented by .
Question 10 of 60 · Definition and operations of stacks · Easy
Which access rule does a stack follow?
Not quite. Try another option.
Answer: Last In, First Out
A stack follows Last In, First Out (LIFO), so the most recently added item is removed first.
Question 11 of 60 · Stack traversal · Easy
What does stack traversal involve?
Not quite. Try another option.
Answer: Visiting the elements currently in the stack
Stack traversal means visiting or displaying the elements stored in the stack.
Question 12 of 60 · Push operation · Easy
What does the push operation do?
Not quite. Try another option.
Answer: Adds an element to the top of a stack
Push places a new element at the top of a stack.
Question 13 of 60 · Pop operation · Easy
What does the pop operation do?
Not quite. Try another option.
Answer: Removes the top element of a stack
Pop removes, and usually returns, the element currently at the top of the stack.
Question 14 of 60 · Stack underflow and overflow conditions · Easy
When does stack underflow occur?
Not quite. Try another option.
Answer: When popping from an empty stack
Stack underflow occurs when a pop operation is attempted while the stack contains no elements.
Question 15 of 60 · Definition and operations of queues · Easy
Which access rule does a queue follow?
Not quite. Try another option.
Answer: First In, First Out
A queue follows First In, First Out (FIFO), so the earliest added item is removed first.
Question 16 of 60 · Queue traversal · Easy
In which direction are queue elements commonly traversed?
Not quite. Try another option.
Answer: From the front toward the rear
Queue traversal commonly begins at the front and continues toward the rear.
Question 17 of 60 · ENQ operation · Easy
What does the ENQ operation normally do in a queue?
Not quite. Try another option.
Answer: Adds an element at the rear
ENQ, or enqueue, inserts a new element at the rear of a queue.
Question 18 of 60 · DEQ operation · Easy
What does the DEQ operation normally do in a queue?
Not quite. Try another option.
Answer: Removes an element from the front
DEQ, or dequeue, removes the element at the front of a queue.
Question 19 of 60 · Queue underflow and overflow conditions · Easy
When does queue overflow occur in a fixed-size queue?
Not quite. Try another option.
Answer: When adding an element to a full queue
Queue overflow occurs when an enqueue operation is attempted but the fixed-size queue has no free space.
Question 20 of 60 · Stack underflow and overflow conditions · Easy
When does stack overflow occur in a fixed-size stack?
Not quite. Try another option.
Answer: When pushing onto a full stack
Stack overflow occurs when a push operation is attempted but the fixed-size stack has no available space.
Question 21 of 60 · Definition and initialization of arrays · Medium
In a zero-indexed language, an integer array is initialized as A = [7, 14, 21, 28, 35]. Which expression accesses the value 28?
Not quite. Try another option.
Answer: A[3]
Zero-based indexing assigns index 3 to the fourth element, which is 28.
Question 22 of 60 · Memory representation of one-dimensional arrays · Medium
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?
Not quite. Try another option.
Answer: 1024
The address is because array elements occupy contiguous memory.
Question 23 of 60 · Array traversal · Medium
Which loop correctly visits every element of a zero-indexed array A containing n elements exactly once?
Not quite. Try another option.
Answer: for i = 0 to n - 1
A zero-indexed array of length n has valid indices from 0 through n - 1.
Question 24 of 60 · Array insertion · Medium
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?
Not quite. Try another option.
Answer: [10, 20, 25, 30, 40, 50]
Elements from index 2 onward shift one position right before 25 is stored at index 2.
Question 25 of 60 · Array deletion · Medium
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?
Not quite. Try another option.
Answer: [5, 15, 20, 25]
The value 10 is removed, and all later elements shift one position to the left.
Question 26 of 60 · Linear search · Medium
A linear search examines [12, 7, 19, 4, 15] from left to right. How many comparisons are required to find 4?
Not quite. Try another option.
Answer: 4 comparisons
The search compares 4 with 12, 7, 19, and then 4, requiring four comparisons.
Question 27 of 60 · Binary search · Medium
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?
Not quite. Try another option.
Answer: 17, then 31
The first middle value is 17; searching its right half then selects 31 as the next middle value.
Question 28 of 60 · Bubble sort · Medium
Using ascending bubble sort, what is the array after one complete left-to-right pass over [5, 1, 4, 2]?
Not quite. Try another option.
Answer: [1, 4, 2, 5]
Adjacent swaps move 5 successively past 1, 4, and 2, placing the largest value at the end.
Question 29 of 60 · Complexity analysis of array operations · Medium
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?
Not quite. Try another option.
Answer:
All existing elements may need to shift one position right, so the work grows linearly with the array size.
Question 30 of 60 · Definition and operations of stacks · Medium
A stack receives push(6), push(9), pop(), and push(12). Which value is now at the top?
Not quite. Try another option.
Answer: 12
The pop removes 9; pushing 12 afterward makes 12 the top element.
Question 31 of 60 · Stack traversal · Medium
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?
Not quite. Try another option.
Answer: D, C, B, A
Top-to-bottom traversal starts with D and continues through the elements in reverse insertion order.
Question 32 of 60 · Push operation · Medium
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?
Not quite. Try another option.
Answer: 4
Four elements occupy indices 0 through 3; a push increments top to 4 and stores the new element there.
Question 33 of 60 · Pop operation · Medium
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?
Not quite. Try another option.
Answer: Returns 44; top = 2
Pop returns the element at the current top index and then decreases top by one.
Question 34 of 60 · Stack underflow and overflow conditions · Medium
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?
Not quite. Try another option.
Answer: Underflow: top == -1; overflow: top == 7
The stack is empty at -1 and full when the top reaches the final valid index, 7.
Question 35 of 60 · Definition and operations of queues · Medium
An initially empty queue performs ENQ(4), ENQ(7), DEQ(), and ENQ(9). What are its contents from front to rear?
Not quite. Try another option.
Answer: 7, 9
The dequeue removes 4, the earliest element, leaving 7 before the newly enqueued 9.
Question 36 of 60 · Queue traversal · Medium
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?
Not quite. Try another option.
Answer: 4, 5, 0, 1
Traversal begins at front, advances modulo the capacity, and stops after visiting rear.
Question 37 of 60 · ENQ operation · Medium
A circular queue has capacity 5, rear = 3, and is not full. At which index will the next enqueued element be placed?
Not quite. Try another option.
Answer: Index 4
The new rear is calculated as , so the element is stored at index 4.
Question 38 of 60 · DEQ operation · Medium
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?
Not quite. Try another option.
Answer: 6
After removing the front element, the index advances to .
Question 39 of 60 · Queue underflow and overflow conditions · Medium
In a circular queue of capacity 6, which condition indicates that the queue is full when front and rear are valid element indices?
Not quite. Try another option.
Answer: (rear + 1) % 6 == front
A circular queue is full when advancing rear by one position would make it coincide with front.
Question 40 of 60 · Binary search · Medium
A sorted array contains 128 distinct elements. In the worst case, at most how many comparisons are needed for a successful binary search?
Not quite. Try another option.
Answer: 8 comparisons
The worst-case successful search uses comparisons.
Question 41 of 60 · Definition and initialization of arrays · Hard
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?
Not quite. Try another option.
Answer: (0, 14, 9, 0)
Elements without explicit initializers are zero-initialized. Thus a[2] becomes .
Question 42 of 60 · Memory representation of one-dimensional arrays · Hard
An array has base address , lower index bound , and element width bytes. Using contiguous row-major storage, what is the address of A[7]?
Not quite. Try another option.
Answer:
The address is .
Question 43 of 60 · Array traversal · Hard
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?
Not quite. Try another option.
Answer: [2, -3, 4]
After deleting -1, -3 shifts into the current index, but incrementing i skips it. The later -5 is deleted.
Question 44 of 60 · Array insertion · Hard
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?
Not quite. Try another option.
Answer: for (i=n; i>p; --i) A[i]=A[i-1]; A[p]=x;
Elements must be copied from right to left; otherwise an unread element can be overwritten before it is moved.
Question 45 of 60 · Array deletion · Hard
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?
Not quite. Try another option.
Answer:
The deletions require and assignments, respectively, totaling .
Question 46 of 60 · Linear search · Hard
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?
Not quite. Try another option.
Answer: i < n-1 || last == x
A match before the final slot is genuine. A match at the final slot is genuine only when the saved final value equals x.
Question 47 of 60 · Binary search · Hard
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?
Not quite. Try another option.
Answer: 1 and 4
This is a lower-bound search. It returns the first index not containing a value less than x, including the insertion index when x is absent.
Question 48 of 60 · Bubble sort · Hard
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?
Not quite. Try another option.
Answer: 7 comparisons and 1 swap
The first pass makes four comparisons and one swap. The now-sorted array requires a second pass of three comparisons before early termination.
Question 49 of 60 · Complexity analysis of array operations · Hard
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?
Not quite. Try another option.
Answer: Comparisons ; movements ; total
Binary searches total comparisons, but every descending key is inserted at the front, producing movements.
Question 50 of 60 · Definition and operations of stacks · Hard
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?
Not quite. Try another option.
Answer: 3 → 1 → 2 → 4
To pop 3 first, both 1 and 2 must already be below it. After 3 is removed, 2 blocks access to 1.
Question 51 of 60 · Stack traversal · Hard
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?
Not quite. Try another option.
Answer: Output D, C, B, A; final top-to-bottom A, B, C, D
Output occurs during recursive unwinding, so it is bottom-to-top. Pushing each saved value during the same unwinding restores the original stack.
Question 52 of 60 · Push operation · Hard
An array stack of capacity C uses top=-1 when empty. Which guarded push operation correctly inserts x without an out-of-bounds write?
Not quite. Try another option.
Answer: if (top==C-1) overflow; else A[++top]=x;
Index C-1 is the final valid slot. Because top denotes the current top, it must be incremented before storing the new value.
Question 53 of 60 · Pop operation · Hard
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?
The value and next pointer must be saved before the removed node is freed. No field of the freed node may then be accessed.
Question 54 of 60 · Stack underflow and overflow conditions · Hard
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?
Not quite. Try another option.
Answer: top1 + 1 == top2; no free cell remains
The stacks are full when their top indices are adjacent, leaving no unused index between them.
Question 55 of 60 · Definition and operations of queues · Hard
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?
Not quite. Try another option.
Answer: y = E; remaining queue [F, D]
Before the final rotation, the queue is [D, E, F]. Moving D to the rear gives [E, F, D], so y is E.
Question 56 of 60 · Queue traversal · Hard
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?
Not quite. Try another option.
Answer: 6, 7, 0, 1, 2
Traversal advances modulo and includes both occupied endpoints, so it wraps from index 7 to index 0 and stops at 2.
Question 57 of 60 · ENQ operation · Hard
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?
Not quite. Try another option.
Answer: if ((rear+1)%N==front) overflow; else { Q[rear]=x; rear=(rear+1)%N; }
The queue is full when advancing rear would reach front. Since rear is the next free slot, the value is stored before rear advances.
Question 58 of 60 · DEQ operation · Hard
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?
Not quite. Try another option.
Answer: It returns P, and front becomes 0
The element at the current front is removed first. Advancing index 5 modulo wraps front to 0.
Question 59 of 60 · Queue underflow and overflow conditions · Hard
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?
Not quite. Try another option.
Answer: It is full with 7 elements, so ENQ overflows
Because , no insertion slot is available. The unused-slot convention permits at most seven elements.
Question 60 of 60 · Complexity analysis of array operations · Hard
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?
Not quite. Try another option.
Answer: Appends ; deletions ; capacity
Geometric resizing gives amortized constant-time appends. Front deletions shift elements, while peak capacity remains linear.
That's unit 2
Answer a few questions and your score shows up here.
Nearly through. Did unit 2 of INT322 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 2 of INT322 save you a night before the exam?
Then you can help keep it free for the next batch. 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.