1. Home
  2. Explore
  3. Computer Science
  4. Algorithm Complexity Analysis

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Algorithm Complexity Analysis

  • 58Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Search Fundamentals
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is a search algorithm?

Tap to flipClick to flipspace

An algorithm used to find an item or group of items in a collection.

Or swipe the card

58 cards

  1. What is a search algorithm?

    An algorithm used to find an item or group of items in a collection.

  2. What is the difference between an implicit and an explicit search collection?

    An implicit collection is represented indirectly, while an explicit collection contains identifiable elements such as list entries.

  3. What are exhaustive enumeration and bisection search examples of?

    They are search algorithms.

  4. What is the goal of a sorting algorithm?

    To arrange the elements of a list in a specified order, such as increasing order.

  5. What does algorithmic complexity measure?

    How the cost of an algorithm grows as the input size increases.

  6. Why are worst-case bounds often emphasized when analyzing algorithms?

    They guarantee performance even on the most difficult inputs.

  7. What does it mean to amortize a computational cost?

    To spread a one-time cost across many later operations.

  8. What is the general strategy of divide and conquer?

    Break a problem into smaller instances of the same problem, solve them, and combine their solutions.

  9. What is linear search?

    A search that examines list elements one at a time until the target is found or the list ends.

  10. Does linear search require the list to be sorted?

    No. Linear search works even when the elements are in arbitrary order.

  11. What is the worst-case complexity of linear search?

    O(n)O(n)O(n), where nnn is the list length.

  12. Why does returning immediately when linear search finds the target improve the average case but not the worst case?

    It may stop early for targets near the beginning, but an absent or final target still requires examining all nnn elements.

  13. How can linear search take advantage of a sorted list?

    It can stop when it reaches an element larger than the target.

  14. What is the worst-case complexity of linear search with early stopping on a sorted list?

    O(n)O(n)O(n).

  15. What is bisection search, also called binary search?

    A search that repeatedly examines the middle element and discards the half that cannot contain the target.

  16. What prerequisite does binary search have?

    The list must be sorted.

  17. Why is binary search logarithmic?

    Each step reduces the remaining problem size by a factor of 222.

  18. What is the worst-case complexity of binary search?

    O(log n).

  19. Why is the work inside each binary-search step constant?

    The algorithm compares an element and adjusts boundary indices rather than copying the list.

  20. When is sorting worthwhile before searching?

    It is worthwhile when the cost of sorting can be amortized over sufficiently many searches.

  21. Why can sorting not have a cost below O(n)O(n)O(n) in the general setting described?

    Every element must be examined at least once to determine where it belongs.

  22. What is the cost of performing kkk binary searches after sorting a list?

    O(k log n), in addition to the one-time sorting cost.

  23. What is the total cost of sorting once and then performing kkk binary searches?

    O(sort(n) + k log n).

  24. What is BOGO sort?

    A sorting method that repeatedly generates random permutations until the list happens to be sorted.

  25. What is the best-case complexity of BOGO sort?

    O(n)O(n)O(n).

  26. What is the average-case complexity of BOGO sort?

    O(n!)O(n!)O(n!).

  27. Why is the worst-case behavior of random BOGO sort effectively unbounded?

    Randomly generated permutations may never produce a sorted list within any fixed number of attempts.

  28. How does bubble sort operate?

    It repeatedly compares adjacent elements and swaps them when they are out of order.

  29. When can bubble sort stop?

    When it completes a full pass without performing any swaps.

  30. What does one complete pass of bubble sort guarantee?

    The largest element in the unsorted portion is placed at its final position at the end.

  31. What is the worst-case complexity of bubble sort?

    O(n2)O(n^2)O(n2).

  32. What is the central idea of selection sort?

    Find the smallest element in the unsorted portion and place it at the beginning of that portion.

  33. What does selection sort guarantee after iii steps?

    The first iii elements are sorted, and every element in the remaining suffix is at least as large as the sorted prefix elements.

  34. What is a loop invariant?

    A property that is true before a loop begins and remains true after every iteration.

  35. What is the loop invariant used to justify selection sort?

    The sorted prefix is ordered, and no element in the prefix is larger than the smallest element in the remaining suffix.

  36. What is the base case for the selection-sort loop invariant?

    An empty sorted prefix, which is trivially sorted and contains no element larger than a suffix element.

  37. What is the worst-case complexity of selection sort?

    O(n2)O(n^2)O(n2).

  38. Why does selection sort remain quadratic even though its remaining scan gets shorter?

    The total comparisons form a sum proportional to n + (n-1) + cdots + 1, which is O(n2)O(n^2)O(n2).

  39. What is the base case of merge sort?

    A list with zero or one element is already sorted.

  40. What are the main steps of merge sort?

    Split the list into two halves, recursively sort both halves, and merge the sorted halves.

  41. How are two sorted lists merged?

    Compare their first remaining elements, append the smaller one to the result, and repeat until one list is empty; then append the remainder.

  42. Why is merging two sorted lists efficient?

    Each element is copied into the result once, and the number of comparisons is at most proportional to the total list length.

  43. What is the complexity of merging two sorted lists whose total length is nnn?

    O(n)O(n)O(n).

  44. Why does merge sort have logarithmically many levels?

    The list size is halved at each level until sublists contain at most one element.

  45. How much work does merge sort perform at each level of recursion?

    O(n)O(n)O(n) work.

  46. What is the overall worst-case complexity of merge sort?

    O(n log n).

  47. Why is merge sort called a log-linear algorithm?

    Its running time is proportional to n log n, combining linear work with a logarithmic number of levels.

  48. How does merge sort compare with bubble sort and selection sort in worst-case complexity?

    Merge sort is O(n log n), while bubble sort and selection sort are O(n2)O(n^2)O(n2).

  49. What worst-case sorting performance is presented as the best available in this content?

    O(n log n).

  50. What is the hierarchy of algorithmic growth rates discussed?

    From generally more desirable to less desirable: constant, logarithmic, linear, log-linear, quadratic, and exponential.

  51. What are the three A's of computational thinking?

    Abstraction, automation, and algorithms.

  52. What is abstraction in computational thinking?

    Capturing the essential structure of a problem while hiding unnecessary implementation details.

  53. What does automation mean in computational thinking?

    Mechanizing an abstraction so a machine can execute it as a sequence of steps.

  54. How does recursion help solve computational problems?

    It expresses a problem in terms of simpler versions of itself and combines those solutions.

  55. What is the role of abstraction in modular programming?

    It allows a computation to be encapsulated in a procedure with a clear contract.

  56. How do classes and methods help organize software?

    They modularize systems by combining data with operations that act on that data.

  57. What is computational problem solving?

    Transforming a problem into an algorithm that a computer can execute to produce or evaluate a solution.

  58. Why is describing an algorithm useful even apart from programming?

    It forces precise communication and clarifies the structure of one's reasoning.

Card 1 of 58
Card 1 of 58

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent