1. Home
  2. Explore
  3. Computer Science
  4. MIT Programming Fundamentals Review

Study methods

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

MIT Programming Fundamentals Review

  • 26Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Efficiency Basics
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What are the two types of efficiency considered when analyzing algorithms?

Tap to flipClick to flipspace

Time efficiency (how fast) and space efficiency (storage used).

Or swipe the card

26 cards

  1. What are the two types of efficiency considered when analyzing algorithms?

    Time efficiency (how fast) and space efficiency (storage used).

  2. What is the trade-off between time and space efficiency?

    Sometimes we can precompute and store intermediate results to reduce time (e.g., memoization), at the cost of using more memory.

  3. Why is timing a program not ideal for evaluating algorithm efficiency?

    Timing depends on implementation details, the specific machine, and may not predict behavior on large inputs.

  4. What is the method of counting operations for analyzing algorithms?

    Counting primitive operations (arithmetic, comparisons, assignments, memory access) as a function of input size.

  5. What are primitive operations in the context of algorithm analysis?

    Arithmetic (+, -, *, /), comparisons (==, <, >), assignments, and memory retrieval.

  6. Why does counting operations still depend on implementation?

    Different implementations (e.g., for loop vs while loop) may have different numbers of primitive operations, but the difference is a constant factor.

  7. What advantage does counting operations have over timing?

    It is independent of the specific machine's speed.

  8. What is the next abstraction after counting operations?

    Order of growth (asymptotic analysis) using Big O notation.

  9. What is Big O notation?

    A mathematical notation describing the worst-case upper bound on an algorithm's runtime as input size grows.

  10. What is the law of addition for orders of growth?

    For sequential code blocks, the overall order of growth is the maximum (dominant) of the individual orders.

  11. What is the law of multiplication for orders of growth?

    For nested code (e.g., loops), the overall order of growth is the product of the individual orders.

  12. List the common complexity classes from best to worst.

    O(1) constant, O(log n) logarithmic, O(n) linear, O(n log n) log-linear, O(n^2) quadratic, O(2^n) exponential.

  13. What does O(1) complexity mean?

    Constant time: the runtime does not depend on the input size.

  14. What does O(n) complexity mean?

    Linear time: runtime grows proportionally to the input size.

  15. What does O(n^2) complexity mean?

    Quadratic time: runtime grows with the square of the input size.

  16. What does O(2^n) complexity mean?

    Exponential time: runtime doubles (or more) with each additional input element.

  17. What is the complexity of an iterative factorial algorithm?

    O(n), where n is the input number.

  18. What is the worst-case complexity of linear search in an unsorted list?

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

  19. Does an early exit in linear search change the worst-case complexity?

    No, the worst case still requires checking all elements (e.g., element not in list).

  20. What is the complexity of checking if one list is a subset of another using nested loops?

    O(n*m) where n and m are the list lengths; if lists are equal length, O(n^2).

  21. What is the overall complexity of computing the intersection of two lists with a nested loop and a duplicate removal step?

    O(n^2) if both lists are of size n.

  22. Why is accessing an element in a Python list considered O(1)?

    Lists are stored contiguously; indexing uses base address + offset, giving random access in constant time.

  23. What is the complexity of adding all digits in a string of decimal digits (using a loop)?

    O(n), where n is the length of the string.

  24. Why is worst-case complexity often the focus of analysis?

    It provides an upper bound on runtime, guaranteeing performance even in the worst input scenario.

  25. What is best-case complexity?

    The minimum runtime over all possible inputs of a given size.

  26. What is average-case complexity?

    The expected runtime over all possible inputs of a given size, assuming a distribution of inputs.

Card 1 of 26
Card 1 of 26

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent