A.A finite sequence of steps for solving a problem
B.A diagram showing only computer hardware
C.A collection of unrelated programming statements
D.A physical device used to store information
Correct Answer: A finite sequence of steps for solving a problem
Explanation:
An algorithm is a finite, well-defined sequence of steps used to solve a problem.
Incorrect! Try again.
2What does complexity analysis primarily measure?
Complexity analysis
Easy
A.The color scheme of a program
B.The price of the computer system
C.The resources used by an algorithm
D.The number of programmers required
Correct Answer: The resources used by an algorithm
Explanation:
Complexity analysis estimates resources such as execution time and memory usage.
Incorrect! Try again.
3What does a time-space trade-off mean?
Time-space trade-off
Easy
A.Using more memory to reduce execution time
B.Using more hardware to increase code length
C.Using fewer variables to increase input size
D.Using more comments to reduce program size
Correct Answer: Using more memory to reduce execution time
Explanation:
A time-space trade-off commonly uses additional memory to make an algorithm run faster, or saves memory at the cost of more time.
Incorrect! Try again.
4What does Omega notation describe for an algorithm?
Omega notation
Easy
A.An asymptotic lower bound
B.An average array value
C.An asymptotic upper bound
D.An exact memory address
Correct Answer: An asymptotic lower bound
Explanation:
Omega notation, written as , gives an asymptotic lower bound on growth.
Incorrect! Try again.
5What does Theta notation represent?
Theta notation
Easy
A.A tight asymptotic bound
B.Only an asymptotic upper bound
C.Only an asymptotic lower bound
D.A fixed array position
Correct Answer: A tight asymptotic bound
Explanation:
Theta notation, written as , bounds a function from both above and below asymptotically.
Incorrect! Try again.
6Which notation is commonly used to express an asymptotic upper bound?
Big O notation
Easy
A. notation
B. notation
C. notation
D. notation
Correct Answer: notation
Explanation:
Big O notation expresses an asymptotic upper bound on an algorithm's growth.
Incorrect! Try again.
7Which of the following is a linear data structure?
Basic data structures
Easy
A.Graph
B.Array
C.Tree
D.Heap
Correct Answer: Array
Explanation:
An array is linear because its elements are arranged in a sequence.
Incorrect! Try again.
8How are elements organized in a linear array?
Linear arrays
Easy
A.In a network structure
B.In a hierarchical order
C.In a sequential order
D.In a random graph
Correct Answer: In a sequential order
Explanation:
A linear array stores elements in a single sequential arrangement.
Incorrect! Try again.
9How are the elements of a standard one-dimensional array usually stored in memory?
Memory representation of arrays
Easy
A.Only inside secondary storage
B.Only inside CPU registers
C.In unrelated memory locations
D.In contiguous memory locations
Correct Answer: In contiguous memory locations
Explanation:
Array elements are normally stored next to one another in contiguous memory locations.
Incorrect! Try again.
10What is array traversal?
Array traversal
Easy
A.Removing the first array element
B.Sorting only duplicate elements
C.Combining two array indexes
D.Visiting each array element
Correct Answer: Visiting each array element
Explanation:
Traversal means accessing each element of an array, usually once and in sequence.
Incorrect! Try again.
11When an element is inserted at the beginning of an array, what may need to happen?
Array insertion
Easy
A.Existing elements shift left
B.All elements become sorted
C.The last element becomes first
D.Existing elements shift right
Correct Answer: Existing elements shift right
Explanation:
Elements are shifted one position to the right to create space at the beginning.
Incorrect! Try again.
12When an array element is deleted from the middle, what commonly fills the empty position?
Array deletion
Easy
A.Earlier elements shifted right
B.Later elements shifted left
C.A new array inserted there
D.The deleted element copied again
Correct Answer: Later elements shifted left
Explanation:
Elements after the deleted item are commonly shifted left to close the gap.
Incorrect! Try again.
13What is the purpose of sorting an array?
Array sorting
Easy
A.To increase the array capacity
B.To remove every repeated element
C.To convert elements into indexes
D.To arrange elements in a chosen order
Correct Answer: To arrange elements in a chosen order
Explanation:
Sorting arranges array elements in an order such as ascending or descending.
Incorrect! Try again.
14What is the main goal of searching an array?
Array searching
Easy
A.To change the array data type
B.To duplicate the entire array
C.To locate a specified element
D.To reverse all array elements
Correct Answer: To locate a specified element
Explanation:
Array searching attempts to find whether a target element exists and often returns its position.
Incorrect! Try again.
15What does merging two arrays produce?
Array merging
Easy
A.One array containing only duplicates
B.One array containing their elements
C.Two arrays containing sorted elements
D.Two arrays containing fewer indexes
Correct Answer: One array containing their elements
Explanation:
Merging combines elements from two arrays into a single array.
Incorrect! Try again.
16What is the typical time complexity of accessing an array element by its index?
Complexity analysis of array operations
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
An array index directly identifies an element's location, so indexed access takes constant time.
Incorrect! Try again.
17What does bubble sort repeatedly compare?
Bubble sort
Easy
A.First and last elements
B.Elements from separate arrays
C.Adjacent elements
D.Randomly selected elements
Correct Answer: Adjacent elements
Explanation:
Bubble sort compares adjacent elements and swaps them when they are in the wrong order.
Incorrect! Try again.
18How does insertion sort build the sorted portion of an array?
Insertion sort
Easy
A.By repeatedly dividing the array into halves
B.By inserting each element into its proper position
C.By selecting elements at random positions
D.By swapping only the first and last elements
Correct Answer: By inserting each element into its proper position
Explanation:
Insertion sort takes each new element and inserts it into the correct position within the sorted portion.
Incorrect! Try again.
19In ascending selection sort, which element is usually selected during each pass?
Selection sort
Easy
A.The middle array element
B.The first duplicate element
C.The smallest remaining element
D.The largest processed element
Correct Answer: The smallest remaining element
Explanation:
Selection sort repeatedly finds the smallest unsorted element and places it in the next sorted position.
Incorrect! Try again.
20Which statement correctly distinguishes binary search from linear search?
Linear search
Easy
A.Linear search requires sorted data
B.Linear search always divides the range
C.Binary search checks every element
D.Binary search requires sorted data
Correct Answer: Binary search requires sorted data
Explanation:
Binary search requires sorted data and repeatedly halves the search range, while linear search can examine elements sequentially in unsorted data.
Incorrect! Try again.
21A list ADT specifies operations such as insertion, deletion, and retrieval but does not specify how elements are stored. Which statement best describes this distinction?
Basic concepts and notations
Medium
A.The ADT defines execution time, while a data structure defines correctness
B.The ADT defines memory addresses, while an algorithm provides the values
C.The ADT defines behavior, while a data structure provides an implementation
D.The ADT defines hardware details, while an algorithm defines storage size
Correct Answer: The ADT defines behavior, while a data structure provides an implementation
Explanation:
An abstract data type specifies permitted values and operations. A data structure, such as an array or linked list, implements those operations.
Incorrect! Try again.
22What is the time complexity of the following code?
for i = 1 to n:
for j = 1 to i:
process(A[j])
Complexity analysis
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The total number of calls is , which is .
Incorrect! Try again.
23An application repeatedly tests whether values occur in a fixed array. Which approach uses extra space to reduce the average lookup time?
Time-space trade-off
Medium
A.Apply selection sort separately before every query
B.Scan the array from the beginning for every query
C.Copy the array into another unsorted linear array
D.Store the values in a hash table before processing queries
Correct Answer: Store the values in a hash table before processing queries
Explanation:
A hash table requires additional memory but can provide average membership tests after preprocessing.
Incorrect! Try again.
24If , which option gives the tightest asymptotic lower bound listed?
Omega notation
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The quadratic term dominates for large , so the tightest listed lower bound is .
Incorrect! Try again.
25An algorithm performs exactly primitive operations for sufficiently large . What is its tight asymptotic complexity?
Theta notation
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The term dominates the linear and constant terms, giving both matching upper and lower bounds.
Incorrect! Try again.
26For , which option is the tightest Big O bound listed?
Big O notation
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The term grows faster than the linear term, so is the tightest listed upper bound.
Incorrect! Try again.
27A linear array has a lower index bound of and an upper index bound of . How many elements can it store?
Linear arrays
Medium
A. elements
B. elements
C. elements
D. elements
Correct Answer: elements
Explanation:
The number of valid indices is .
Incorrect! Try again.
28An integer array begins at address , each element occupies bytes, and indexing starts at . What is the address of ?
Memory representation of arrays
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The address is because seven elements precede .
Incorrect! Try again.
29An algorithm visits each element of an array of size once and performs constant-time work per element. If the array size doubles, what happens asymptotically to the running time?
Array traversal
Medium
A.It becomes approximately twice as large
B.It becomes approximately logarithmically larger
C.It becomes approximately four times larger
D.It remains approximately unchanged
Correct Answer: It becomes approximately twice as large
Explanation:
A complete traversal takes time, so doubling approximately doubles the work.
Incorrect! Try again.
30A linear array currently contains elements at indices through . To insert a new value at index while preserving order, how many existing elements must be shifted?
Array insertion
Medium
A. elements
B. elements
C. elements
D. elements
Correct Answer: elements
Explanation:
The elements at indices through must move one position right, so elements are shifted.
Incorrect! Try again.
31An array contains elements at indices through . If the element at index is deleted while preserving order, how many elements must be shifted left?
Array deletion
Medium
A. elements
B. elements
C. elements
D. elements
Correct Answer: elements
Explanation:
The elements at indices through must shift left, giving shifts.
Incorrect! Try again.
32A sorting method must preserve the original relative order of records having equal keys. Which property is required?
Array sorting
Medium
A.The method must be recursive
B.The method must be adaptive
C.The method must be in-place
D.The method must be stable
Correct Answer: The method must be stable
Explanation:
A stable sorting algorithm preserves the relative order of elements whose keys are equal.
Incorrect! Try again.
33A fixed unsorted array of elements will receive many search queries. Which strategy has the better asymptotic total time when the number of queries is large?
Array searching
Medium
A.Copy once and then scan both arrays for each query
B.Use linear search independently for every query
C.Sort once and then use binary search for each query
D.Reverse once and then scan backward for each query
Correct Answer: Sort once and then use binary search for each query
Explanation:
Sorting once costs about , after which each query costs instead of .
Incorrect! Try again.
34Two sorted arrays contain and elements. Using the standard two-pointer merge, what is the maximum number of element comparisons needed?
Array merging
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
In the worst case, comparisons continue until only one element remains, requiring comparisons.
Incorrect! Try again.
35A dynamic array doubles its capacity whenever it becomes full. What are the amortized and worst-case time complexities of appending one element?
Complexity analysis of array operations
Medium
A.Amortized and worst-case
B.Amortized and worst-case
C.Amortized and worst-case
D.Amortized and worst-case
Correct Answer: Amortized and worst-case
Explanation:
Most appends take constant time, but an append that triggers resizing must copy existing elements.
Incorrect! Try again.
36Using ascending bubble sort, what is the array after one complete left-to-right pass over ?
Bubble sort
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Adjacent inversions are swapped in sequence, moving rightward until the array becomes .
Incorrect! Try again.
37How many element shifts does insertion sort perform when sorting in ascending order?
Insertion sort
Medium
A. shifts
B. shifts
C. shifts
D. shifts
Correct Answer: shifts
Explanation:
The inserted elements require , , and shifts respectively, for a total of .
Incorrect! Try again.
38What is the array after the first two passes of ascending selection sort on ?
Selection sort
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The first pass places first, and the second pass places in the second position.
Incorrect! Try again.
39A successful linear search is performed on an array of elements. If the target is equally likely to be at any position, what is the expected number of comparisons?
Linear search
Medium
A. comparisons
B. comparisons
C. comparisons
D. comparisons
Correct Answer: comparisons
Explanation:
The expected number is the average of positions through : .
Incorrect! Try again.
40Binary search uses on a sorted array indexed from to . How many comparisons are made when searching for the value at index ?
Binary search
Medium
A. comparisons
B. comparisons
C. comparisons
D. comparisons
Correct Answer: comparisons
Explanation:
The examined indices are , so the search makes comparisons.
Incorrect! Try again.
41An algorithm has best-case time and worst-case time . Its average-case time is under one particular input distribution. Which conclusion is guaranteed independently of the input distribution?
Basic concepts and notations
Hard
A.Every input takes time, and some input takes time
B.At least half of all inputs take time for each input size
C.Every input takes time, except for finitely many input sizes
D.Every input takes time, and some input takes time
Correct Answer: Every input takes time, and some input takes time
Explanation:
A worst-case bound of means every input is bounded above by and, for sufficiently large sizes, at least one input requires . The stated average depends on its chosen distribution.
Incorrect! Try again.
42What is the tight asymptotic running time of the following loop nest, assuming the innermost body takes constant time?
for i = 1 to n
for j = 1 to i
for k = 1; k <= j; k = 2*k
constant-time operation
Complexity analysis
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The innermost loop costs . Thus the total is .
Incorrect! Try again.
43A static set contains distinct keys from a universe of size . Implementation D uses a direct-address table, while implementation S uses a sorted array. Ignoring the storage of the keys themselves, which comparison correctly describes their worst-case membership queries and auxiliary space?
Time-space trade-off
Hard
A.D uses space and query time; S uses space and query time
B.D uses space and query time; S uses space and query time
C.D uses space and query time; S uses space and query time
D.D uses space and query time; S uses space and query time
Correct Answer: D uses space and query time; S uses space and query time
Explanation:
Direct addressing allocates one entry per universe value, giving space and constant-time lookup. A sorted array stores keys and supports binary search in time.
Incorrect! Try again.
44Define when is a power of two and otherwise. Which is the strongest asymptotic lower bound among the following choices that holds for every sufficiently large integer ?
Omega notation
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
For every , , so . For infinitely many non-powers of two, , which prevents an bound.
Incorrect! Try again.
45For powers of two, let and . What is the tight asymptotic solution?
Theta notation
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Expanding gives , an arithmetic sum equal to .
Incorrect! Try again.
46Let for . Which option is the tightest valid Big O bound listed?
Big O notation
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The function is itself . It grows faster than and , and it is not bounded by .
Incorrect! Try again.
47A circular queue is implemented in an array of capacity , reserving one empty cell. front points to the first element and rear to the next insertion cell. Initially, front = 6 and rear = 2. After three dequeues followed by four enqueues, what are the final indices and number of stored elements, assuming no operation fails?
Linear arrays
Hard
A.front = 1, rear = 5, with 4 elements
B.front = 2, rear = 6, with 4 elements
C.front = 1, rear = 6, with 5 elements
D.front = 0, rear = 5, with 5 elements
Correct Answer: front = 1, rear = 6, with 5 elements
Explanation:
Initially the occupied indices are , so there are four elements. Three dequeues move front to ; four enqueues move rear from to , leaving five elements.
Incorrect! Try again.
48A two-dimensional array is stored in row-major order. Each element occupies bytes, and the address of is . What is the address of ?
Memory representation of arrays
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Each row has elements. The offset is bytes, so the address is .
Incorrect! Try again.
49A row-major integer array is traversed once. A cache line holds consecutive integers. The cache is initially empty, fully associative, uses LRU, and holds lines. Ignoring all other memory traffic, how many cache misses occur for row-wise and column-wise traversal, respectively?
Array traversal
Hard
A. row-wise and column-wise
B. row-wise and column-wise
C. row-wise and column-wise
D. row-wise and column-wise
Correct Answer: row-wise and column-wise
Explanation:
Row-wise traversal uses each of the lines once. Column-wise accesses cycle through rows, exceeding the -line cache before a line can be reused, so every element access misses.
Incorrect! Try again.
50An array initially contains elements. Exactly elements are then inserted one at a time at index , with all existing elements shifted right for each insertion. How many element shifts are performed in total?
Array insertion
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The insertions shift elements. Their sum is .
Incorrect! Try again.
51A contiguous array initially has elements. The first element is deleted times in succession, where , and each deletion shifts every remaining element left. What is the total number of shifts?
Array deletion
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The deletions require shifts. This arithmetic series sums to .
Incorrect! Try again.
52The array contains each integer from to exactly once. What is the minimum number of arbitrary element swaps required to sort it?
Array sorting
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The permutation has cycles , , and . A cycle of length needs swaps, giving .
Incorrect! Try again.
53A sorted array of length may contain duplicates. An algorithm must return every index whose value equals . If there are matches, what is the optimal worst-case running time in the comparison model?
Array searching
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Two boundary searches can locate the first and last occurrence in time, after which reporting the indices costs . The output alone requires time.
Incorrect! Try again.
54Two sorted arrays of lengths and are merged using the standard two-pointer algorithm. What are the minimum and maximum possible numbers of key comparisons?
Array merging
Hard
A.Minimum and maximum
B.Minimum and maximum
C.Minimum and maximum
D.Minimum and maximum
Correct Answer: Minimum and maximum
Explanation:
The minimum occurs when every element of one array precedes every element of the other, exhausting the shorter array. Interleaving can delay exhaustion until one element remains, producing comparisons.
Incorrect! Try again.
55A dynamic array starts with capacity and doubles whenever an append finds it full. Appending writes the new element once, and resizing copies every existing element once. If exactly elements are appended, how many total element writes, including copies, occur?
Complexity analysis of array operations
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The appended elements cause writes. Resizing copies elements, so the total is .
Incorrect! Try again.
56Standard left-to-right bubble sort uses a shrinking unsorted boundary and stops early after a pass with no swaps. On the input , how many key comparisons and swaps are performed?
Bubble sort
Hard
A. comparisons and swaps
B. comparisons and swaps
C. comparisons and swaps
D. comparisons and swaps
Correct Answer: comparisons and swaps
Explanation:
The value moves left by one position per pass, requiring swaps. The shrinking passes perform comparisons.
Incorrect! Try again.
57Insertion sort is run on for . Counting only comparisons between the key and an array element, how many such comparisons and element shifts occur?
Insertion sort
Hard
A. comparisons and shifts
B. comparisons and shifts
C. comparisons and shifts
D. comparisons and shifts
Correct Answer: comparisons and shifts
Explanation:
The first insertions each make one unsuccessful key comparison. Inserting makes successful comparisons and shifts all preceding elements, totaling comparisons.
Incorrect! Try again.
58Selection sort repeatedly finds the minimum of the unsorted suffix and swaps only when that minimum is not already in position. On a reverse-sorted array of distinct elements, how many key comparisons and swaps occur?
Selection sort
Hard
A. comparisons and swaps
B. comparisons and swaps
C. comparisons and swaps
D. comparisons and swaps
Correct Answer: comparisons and swaps
Explanation:
Selection sort always performs comparisons. In a reversed array, each swap places both the smallest and a largest remaining element, producing swaps.
Incorrect! Try again.
59A linear search examines an array of length . The search is successful with probability , and conditional on success, the target position is uniformly distributed among the indices. What is the expected number of key comparisons?
Linear search
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
A successful search averages comparisons, while failure requires . Therefore the expectation is .
Incorrect! Try again.
60Consider lower-bound binary search on a sorted array using the half-open interval [low, high). It updates low = mid + 1 when A[mid] < x; otherwise it updates high = mid. Which invariant is sufficient to prove that the final low is the first index whose value is at least ?
Binary search
Hard
A.Every index below high has value less than , and every index at or above low has value at least
B.Every index below low has value less than , and every index at or above high has value at least
C.Every index below low has value at most , and every index above high has value greater than
D.Every index through low has value less than , and every index after high has value at least
Correct Answer: Every index below low has value less than , and every index at or above high has value at least
Explanation:
The updates preserve that all discarded left-side elements are less than and all discarded right-side elements are at least . At termination low = high, so this boundary is the first position with value at least .
Incorrect! Try again.
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 →