Algorithms OA Practice Exam (Latest
Version) | A+ Graded.
Q1: Which of the following best describes the relationship between an algorithm and a data
structure?
A. Algorithms are used only for sorting, while data structures are used only for storage
B. Data structures provide a way to organize data, and algorithms define operations that can be
performed on those structures
C. Algorithms are more important than data structures for program efficiency
D. Data structures are only relevant for large datasets
Correct Answer: B [CORRECT]
Rationale: Data structures organize and store data efficiently, while algorithms define the step-
by-step procedures for manipulating that data. The choice of data structure directly affects
algorithm performance, as different structures support different operations with varying time
complexities.
Q2: What is the time complexity of accessing an element at a specific index in an array?
A. O(1)
B. O(log n)
C. O(n)
D. O(n²)
Correct Answer: A [CORRECT]
Rationale: Arrays provide constant-time random access O(1) because elements are stored
contiguously in memory, and the address of any element can be calculated directly using base
address + (index × element size). This is a fundamental advantage of arrays over linked lists.
Q3: Which of the following is TRUE about a singly linked list compared to an array?
A. Singly linked lists provide O(1) random access
B. Singly linked lists require contiguous memory allocation
,C. Singly linked lists allow O(1) insertion at the head
D. Singly linked lists have O(log n) search time
Correct Answer: C [CORRECT]
Rationale: Singly linked lists allow O(1) insertion at the head by simply updating the head
pointer and the new node's next pointer. Arrays require O(n) shift operations for insertion at the
beginning. Singly linked lists have O(n) search time and cannot provide O(1) random access.
Q4: A recursive function that solves a problem by dividing it into smaller subproblems of the
same type is an example of which algorithmic approach?
A. Greedy algorithm
B. Dynamic programming
C. Divide and conquer
D. Brute force
Correct Answer: C [CORRECT]
Rationale: Divide and conquer algorithms recursively break a problem into smaller, independent
subproblems of the same type, solve each subproblem, and combine results. Key examples
include Merge Sort and Quick Sort. Dynamic programming is similar but handles overlapping
subproblems with memoization.
Q5: What is the worst-case time complexity of binary search on a sorted array?
A. O(1)
B. O(log n)
C. O(n)
D. O(n log n)
Correct Answer: B [CORRECT]
Rationale: Binary search repeatedly halves the search space, resulting in O(log n) time
complexity in all cases. Each comparison eliminates half of the remaining elements, requiring at
most ⌈log₂(n)⌉ comparisons for a sorted array of size n.
Q6: Select all that apply: Which of the following are characteristics of a good hash function?
, A. It is deterministic (same input always produces the same output)
B. It produces a uniform distribution of hash values
C. It is computationally expensive to ensure security
D. It minimizes collisions
E. It always produces unique values for different inputs
Correct Answers: A, B, D [CORRECT]
Rationale: A good hash function must be deterministic, produce uniform distribution to
minimize collisions, and be computationally efficient. Perfect hashing (E) is not required or
practical for general use; collisions are expected and handled through collision resolution
strategies.
Q7: Which data structure would be most appropriate for implementing a "Last In, First Out"
(LIFO) behavior?
A. Queue
B. Stack
C. Linked list
D. Array
Correct Answer: B [CORRECT]
Rationale: A stack is specifically designed for LIFO behavior, where the last element inserted is
the first one removed. All stack operations (push, pop, peek) are O(1). While other data
structures could be adapted, stacks provide the most direct and efficient implementation.
Q8: What is the time complexity of inserting an element at the end of a dynamic array
(ArrayList) in the average case?
A. O(1)
B. O(log n)
C. O(n)
D. O(n²)
Correct Answer: A [CORRECT]
Rationale: Dynamic arrays provide amortized O(1) insertion at the end. While occasional
resizing operations take O(n), these happen infrequently enough that the amortized cost
remains constant. This makes ArrayLists very efficient for appending elements.