Algorithmic Efficiency - AP Computer Science Principles
Card 1 of 30
What is the time complexity of a merge sort algorithm?
What is the time complexity of a merge sort algorithm?
Tap to reveal answer
$O(n \text{ log } n)$. Divide-and-conquer with linear merge operations.
$O(n \text{ log } n)$. Divide-and-conquer with linear merge operations.
← Didn't Know|Knew It →
Which algorithm has a time complexity of $O(n)$?
Which algorithm has a time complexity of $O(n)$?
Tap to reveal answer
Linear search algorithm. Checks each element once in worst case.
Linear search algorithm. Checks each element once in worst case.
← Didn't Know|Knew It →
What is the space complexity of an algorithm?
What is the space complexity of an algorithm?
Tap to reveal answer
It measures the memory usage of an algorithm. Tracks additional storage beyond input data.
It measures the memory usage of an algorithm. Tracks additional storage beyond input data.
← Didn't Know|Knew It →
State the Big O notation for the worst case of quicksort.
State the Big O notation for the worst case of quicksort.
Tap to reveal answer
$O(n^2)$. Poor pivot selection leads to unbalanced partitions.
$O(n^2)$. Poor pivot selection leads to unbalanced partitions.
← Didn't Know|Knew It →
What is the average case time complexity of quicksort?
What is the average case time complexity of quicksort?
Tap to reveal answer
$O(n \text{ log } n)$. Balanced partitioning creates optimal divide-and-conquer.
$O(n \text{ log } n)$. Balanced partitioning creates optimal divide-and-conquer.
← Didn't Know|Knew It →
Identify the time complexity for depth-first search (DFS).
Identify the time complexity for depth-first search (DFS).
Tap to reveal answer
$O(V + E)$. Visits each vertex and edge exactly once.
$O(V + E)$. Visits each vertex and edge exactly once.
← Didn't Know|Knew It →
What is the time complexity of breadth-first search (BFS)?
What is the time complexity of breadth-first search (BFS)?
Tap to reveal answer
$O(V + E)$. Explores all vertices and their adjacent edges.
$O(V + E)$. Explores all vertices and their adjacent edges.
← Didn't Know|Knew It →
State the time complexity of selection sort.
State the time complexity of selection sort.
Tap to reveal answer
$O(n^2)$. Nested loops to find minimum and swap elements.
$O(n^2)$. Nested loops to find minimum and swap elements.
← Didn't Know|Knew It →
What is the Big O notation for an algorithm with constant time?
What is the Big O notation for an algorithm with constant time?
Tap to reveal answer
$O(1)$. Operation takes same time regardless of input size.
$O(1)$. Operation takes same time regardless of input size.
← Didn't Know|Knew It →
Identify the Big O notation for insertion sort in the best case.
Identify the Big O notation for insertion sort in the best case.
Tap to reveal answer
$O(n)$. Already sorted array requires only single pass.
$O(n)$. Already sorted array requires only single pass.
← Didn't Know|Knew It →
What is the time complexity of heap sort?
What is the time complexity of heap sort?
Tap to reveal answer
$O(n \text{ log } n)$. Maintains heap property through logarithmic operations.
$O(n \text{ log } n)$. Maintains heap property through logarithmic operations.
← Didn't Know|Knew It →
What is the Big O notation for Fibonacci sequence using recursion?
What is the Big O notation for Fibonacci sequence using recursion?
Tap to reveal answer
$O(2^n)$. Each call branches into two recursive calls.
$O(2^n)$. Each call branches into two recursive calls.
← Didn't Know|Knew It →
Identify the Big O notation for matrix multiplication.
Identify the Big O notation for matrix multiplication.
Tap to reveal answer
$O(n^3)$. Three nested loops for standard multiplication algorithm.
$O(n^3)$. Three nested loops for standard multiplication algorithm.
← Didn't Know|Knew It →
What is the space complexity of a recursive algorithm using stack?
What is the space complexity of a recursive algorithm using stack?
Tap to reveal answer
$O(n)$. Call stack grows proportionally with recursion depth.
$O(n)$. Call stack grows proportionally with recursion depth.
← Didn't Know|Knew It →
State the Big O notation for an exponential time algorithm.
State the Big O notation for an exponential time algorithm.
Tap to reveal answer
$O(2^n)$. Runtime doubles with each additional input element.
$O(2^n)$. Runtime doubles with each additional input element.
← Didn't Know|Knew It →
Find and correct the error: 'A binary search has $O(n)$ complexity.'
Find and correct the error: 'A binary search has $O(n)$ complexity.'
Tap to reveal answer
Correct: 'A binary search has $O(\text{log } n)$ complexity.'. Binary search divides search space logarithmically.
Correct: 'A binary search has $O(\text{log } n)$ complexity.'. Binary search divides search space logarithmically.
← Didn't Know|Knew It →
What is the time complexity of Dijkstra's algorithm?
What is the time complexity of Dijkstra's algorithm?
Tap to reveal answer
$O(V^2)$. Uses adjacency matrix for dense graph representation.
$O(V^2)$. Uses adjacency matrix for dense graph representation.
← Didn't Know|Knew It →
Identify the Big O notation for the best case of quicksort.
Identify the Big O notation for the best case of quicksort.
Tap to reveal answer
$O(n \text{ log } n)$. Good pivot creates balanced recursive partitions.
$O(n \text{ log } n)$. Good pivot creates balanced recursive partitions.
← Didn't Know|Knew It →
What does the term 'polynomial time' mean in algorithmic complexity?
What does the term 'polynomial time' mean in algorithmic complexity?
Tap to reveal answer
It means time complexity is $O(n^k)$ for constant $k$. Runtime bounded by polynomial function of input size.
It means time complexity is $O(n^k)$ for constant $k$. Runtime bounded by polynomial function of input size.
← Didn't Know|Knew It →
Identify the time complexity of Kruskal’s algorithm.
Identify the time complexity of Kruskal’s algorithm.
Tap to reveal answer
$O(E \text{ log } E)$. Sorting edges dominates the union-find operations.
$O(E \text{ log } E)$. Sorting edges dominates the union-find operations.
← Didn't Know|Knew It →
What is the worst-case time complexity of insertion sort?
What is the worst-case time complexity of insertion sort?
Tap to reveal answer
$O(n^2)$. Comparisons increase quadratically for reverse-sorted input.
$O(n^2)$. Comparisons increase quadratically for reverse-sorted input.
← Didn't Know|Knew It →
Identify the time complexity of a hash table search operation.
Identify the time complexity of a hash table search operation.
Tap to reveal answer
$O(1)$. Direct access through hash function calculation.
$O(1)$. Direct access through hash function calculation.
← Didn't Know|Knew It →
Find and correct the error: 'The time complexity of merge sort is $O(n^2)$.'
Find and correct the error: 'The time complexity of merge sort is $O(n^2)$.'
Tap to reveal answer
Correct: 'The time complexity of merge sort is $O(n \text{ log } n)$.'. Merge sort consistently divides and merges efficiently.
Correct: 'The time complexity of merge sort is $O(n \text{ log } n)$.'. Merge sort consistently divides and merges efficiently.
← Didn't Know|Knew It →
Identify the Big O notation for the average case of bubble sort.
Identify the Big O notation for the average case of bubble sort.
Tap to reveal answer
$O(n^2)$. Adjacent swaps still require quadratic comparisons.
$O(n^2)$. Adjacent swaps still require quadratic comparisons.
← Didn't Know|Knew It →
What is the Big O notation for an algorithm with logarithmic time complexity?
What is the Big O notation for an algorithm with logarithmic time complexity?
Tap to reveal answer
$O(\text{log } n)$. Search space halves with each comparison step.
$O(\text{log } n)$. Search space halves with each comparison step.
← Didn't Know|Knew It →
State the Big O notation for searching an unsorted list.
State the Big O notation for searching an unsorted list.
Tap to reveal answer
$O(n)$. Must examine every element without ordering advantage.
$O(n)$. Must examine every element without ordering advantage.
← Didn't Know|Knew It →
What is the time complexity of the Floyd-Warshall algorithm?
What is the time complexity of the Floyd-Warshall algorithm?
Tap to reveal answer
$O(n^3)$. All-pairs shortest path with triple nested loops.
$O(n^3)$. All-pairs shortest path with triple nested loops.
← Didn't Know|Knew It →
Find and correct the error: 'BFS has a space complexity of $O(E)$.'
Find and correct the error: 'BFS has a space complexity of $O(E)$.'
Tap to reveal answer
Correct: 'BFS has a space complexity of $O(V)$.'. Queue stores vertices, not edges during traversal.
Correct: 'BFS has a space complexity of $O(V)$.'. Queue stores vertices, not edges during traversal.
← Didn't Know|Knew It →
State the Big O notation for a linear search algorithm.
State the Big O notation for a linear search algorithm.
Tap to reveal answer
$O(n)$. Examines each element sequentially until found.
$O(n)$. Examines each element sequentially until found.
← Didn't Know|Knew It →
Identify the time complexity of Prim's algorithm using a priority queue.
Identify the time complexity of Prim's algorithm using a priority queue.
Tap to reveal answer
$O(E \text{ log } V)$. Priority queue operations dominate edge processing time.
$O(E \text{ log } V)$. Priority queue operations dominate edge processing time.
← Didn't Know|Knew It →