CPP Algorithms & Complexity Analysis Flashcards
6 cards from real CPP practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 6 CPP Algorithms & Complexity Analysis flashcards as text
Which sorting algorithm does std::stable_sort typically use?
Answer: Merge sort
std::stable_sort typically uses merge sort to preserve the relative order of equal elements with O(n log n) complexity.
What is the worst-case time complexity of quicksort?
Answer: O(n²)
Quicksort degrades to O(n²) in the worst case when the pivot always creates maximally unbalanced partitions, such as on already-sorted input.
Which C++ algorithm fills a range with sequentially increasing values?
Answer: std::iota
std::iota fills a range with sequentially increasing values starting from an initial value and is defined in .
What does std::partition do to a range?
Answer: Rearranges elements so those satisfying a predicate come first
std::partition rearranges elements so all elements satisfying the predicate appear before those that do not.
What is the time complexity of std::binary_search on a sorted range?
Answer: O(log n)
std::binary_search operates on a sorted range and repeatedly halves the search space, achieving O(log n) time complexity.
Which algorithm computes the sum of a range sequentially from left to right?
Answer: std::accumulate
std::accumulate from folds a range from left to right using a binary operation, defaulting to addition.