โ† All CPP Flashcard Decks

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
  1. What does std::find return when the element is not found?

    Answer: The end iterator of the range

    std::find returns the end iterator of the searched range when the element is not present.

  2. What is the time complexity of std::find on an unsorted std::vector?

    Answer: O(n)

    std::find performs a linear search, checking each element one by one, giving O(n) worst-case time.

  3. Which STL algorithm returns true only if a predicate holds for every element in a range?

    Answer: std::all_of

    std::all_of returns true only if the predicate returns true for every element in the range.

  4. What does std::transform do?

    Answer: Applies a function to each element and writes results to an output range

    std::transform applies a given callable to each element in an input range and writes the results to an output range.

  5. Which algorithm removes consecutive duplicate elements from a sorted range?

    Answer: std::unique

    std::unique removes consecutive duplicate elements and returns an iterator to the new logical end of the range.

  6. What is the key difference between std::count and std::count_if?

    Answer: std::count counts a specific value; std::count_if counts elements matching a predicate

    std::count counts occurrences of a specific value by equality, while std::count_if counts elements for which a predicate returns true.