Epic Skills Assessment Algorithmic Problem Solving Questions and Answers 2 — Questions and Answers
Question 1: What is the time complexity of binary search on a sorted array of n elements?
- O(n)
- O(log n) (Correct answer)
- O(n²)
- O(1)
Correct answer: O(log n)
Binary search halves the search space each step, giving O(log n) complexity.
Binary search repeatedly divides the array in half, comparing the target to the middle element. After k steps, 2^k elements have been eliminated. The maximum steps needed is log₂(n). This logarithmic complexity makes binary search vastly superior to linear search (O(n)) for large sorted datasets — a fundamental concept in Epic's algorithmic assessment.
Question 2: Which data structure operates on a Last-In-First-Out (LIFO) principle?
- Queue
- Stack (Correct answer)
- Linked List
- Hash Table
Correct answer: Stack
A stack uses LIFO: the last element pushed is the first one popped.
Stacks are used for undo operations, function call management, and expression parsing. Push adds to the top; pop removes from the top. A queue uses FIFO (first-in-first-out). Epic's system supports complex transaction stacks, and understanding LIFO vs. FIFO is tested in the algorithmic section.
Question 3: A recursive function calls itself with n-1 until n=0. If n starts at 5, how many total calls are made?
- 4
- 5
- 6 (Correct answer)
- 10
Correct answer: 6
Calls: f(5)→f(4)→f(3)→f(2)→f(1)→f(0). That is 6 total calls including the base case.
Tracing recursion: f(5) calls f(4), which calls f(3)…down to f(0) which terminates. The sequence is f(5),f(4),f(3),f(2),f(1),f(0) = 6 calls. This is fundamental to understanding recursive algorithms' space and time costs. Epic's test expects candidates to trace small recursive programs accurately.
Question 4: Which sorting algorithm has the best average-case time complexity?
- Bubble Sort
- Selection Sort
- Quicksort (Correct answer)
- Insertion Sort
Correct answer: Quicksort
Quicksort has O(n log n) average-case complexity, better than the O(n²) of bubble, selection, and insertion sort.
Bubble, selection, and insertion sorts are all O(n²) on average. Quicksort achieves O(n log n) on average by using a pivot to partition the array. Merge sort is also O(n log n) but typically uses more memory. Epic's algorithmic test covers sorting complexity to assess foundational CS knowledge.
Question 5: In pseudocode: x=10; WHILE x>0: x=x-3; PRINT x; — how many times is PRINT executed?
- 3
- 4 (Correct answer)
- 5
- 10
Correct answer: 4
x: 10→7→4→1→-2. PRINT fires when x=7, x=4, x=1, x=-2 (after loop exits? No — print is inside loop). x goes 10→7(print)→4(print)→1(print)→-2: loop ends as x=-2 which is not >0 but the print happens after x=x-3. So prints: x=7,4,1,-2 = 4 times.
Tracing: start x=10 (>0 ✓), x=10-3=7, print 7. x=7 (>0 ✓), x=4, print 4. x=4 (>0 ✓), x=1, print 1. x=1 (>0 ✓), x=-2, print -2. x=-2 (not >0), loop ends. Total prints: 4. Loop tracing is a core skill in Epic's algorithmic assessment section.
Question 6: What is the output of: x=2; y=3; z=x**y + y**x; PRINT z?
- 13 (Correct answer)
- 17
- 10
- 16
Correct answer: 13
x**y = 2³=8, y**x = 3²=9. z = 8+9 = 17. Wait — 8+9=17, so the answer is 17.
2**3 = 8 and 3**2 = 9. z = 8 + 9 = 17. This tests operator precedence and exponentiation evaluation. The correct answer is 17. Epic's algorithmic section includes straightforward expression evaluation to confirm basic computational literacy.
What is the time complexity of binary search on a sorted array of n elements?