AP CSP algorithm efficiency and undecidable problems cheat sheet

This cheat sheet covers key concepts of algorithm efficiency, including Big O notation, time complexity, and undecidable problems relevant for AP Computer Science Principles.

Bold97·56 flashcards·56 questions
APcomputer_sciencealgorithms
0
Known
1 / 56
0
Learning
Front

Define Algorithm Efficiency.

Tap to flip
Back

Algorithm efficiency measures the resources required (time and space) for an algorithm to complete. It evaluates how quickly an algorithm runs and how much memory it uses.

Tap to flip
Got it
Still learning

Quiz(56 questions)

Question 1 of 56

1. What does algorithm efficiency primarily measure?

Terms in this Study Set(56)

Algorithm Efficiency(20)

Define Algorithm Efficiency.

Algorithm efficiency measures the resources required (time and space) for an algorithm to complete. It evaluates how quickly an algorithm runs and how much memory it uses.

What is time complexity?

Time complexity quantifies the amount of time an algorithm takes to complete as a function of the input size, often expressed using Big O notation.

True or False: A linear algorithm is O(n^2).

False. A linear algorithm is O(n), meaning its time complexity grows linearly with the input size.

Fill in the blank: The worst-case time complexity of a binary search is ____.

O(log n). This reflects that with each comparison, the search space is halved.

Compare Linear Search and Binary Search.

- Linear Search: O(n) time complexity. - Binary Search: O(log n) time complexity (requires sorted array).

What does the term 'space complexity' refer to?

Space complexity measures the total memory space an algorithm requires, including both the input size and auxiliary space used during execution.

What is the time complexity of bubble sort?

Bubble sort has a time complexity of O(n^2) in the worst and average case scenarios due to nested iterations.

What is the average case of quicksort?

O(n log n). Quicksort is efficient for large datasets, as it divides the array into partitions.

True or False: Recursive algorithms always have better efficiency than iterative ones.

False. Recursion can add overhead and may use more space due to call stack.

Define polynomial time.

Polynomial time refers to an algorithm that runs in O(n^k) for some constant k, indicating efficient scalability with input size.

What is a constant time complexity?

O(1). The execution time remains constant, regardless of the input size.

What is the difference between O(n) and O(n log n)?

O(n) grows linearly with input size, while O(n log n) grows slightly faster due to logarithmic factor.

What is amortized time complexity?

Amortized time complexity averages out the time taken over a sequence of operations, providing a more generalized analysis.

Cause → Effect: What happens when an algorithm has O(n^3) complexity?

The algorithm will perform significantly slower with larger inputs, making it inefficient for large datasets.

True or False: All algorithms have the same efficiency.

False. Algorithms vary widely in efficiency based on their design and the input they process.

What is the impact of input size on algorithm efficiency?

Larger input sizes typically increase execution time and resource usage, affecting overall efficiency.

Fill in the blank: The time complexity for merge sort is ____.

O(n log n). It efficiently divides and conquers the data.

Define exponential time complexity.

Exponential time complexity is O(2^n), indicating that the algorithm's execution time doubles with each additional input element.

What is the time complexity of a for loop that runs n times?

O(n). Each iteration contributes to the total time based on the number of times it runs.

Define logarithmic time complexity.

Logarithmic time complexity, O(log n), occurs when the algorithm reduces the problem size by a constant factor (e.g., halving) with each step, like binary search, making it very efficient for large inputs.

Big O Notation(16)

What does Big O notation describe?

The upper bound of an algorithm's time complexity in the worst-case scenario.

True or False: O(n) is slower than O(log n).

True. O(n) grows linearly, while O(log n) grows logarithmically, which is faster.

O(1) means...

Constant time complexity; execution time does not change with input size.

Fill in the blank: O(n^2) is commonly seen in ________ algorithms.

Quadratic sorting algorithms, like bubble sort and insertion sort.

Compare O(n) and O(n log n).

O(n) is linear; O(n log n) is more complex, typically seen in efficient sorting algorithms.

What is the Big O of this loop: for i from 1 to n, do something?

O(n). The time complexity increases linearly with n.

O(n^3) indicates what type of algorithm?

Cubic time complexity, often found in algorithms with three nested loops.

True or False: O(n) and O(2n) are equivalent.

True. They are both linear; constants do not affect Big O notation.

What is the Big O of an algorithm with nested loops both running n times?

O(n^2). Each loop contributes to the total complexity.

Cause → Effect: Increasing input size in O(n log n) algorithm leads to...

Increased execution time, but more efficiently than O(n^2) algorithms.

What is the best-case time complexity of a linear search?

O(1). If the target is the first element.

Identify the Big O: Merge Sort algorithm.

O(n log n). Efficient sorting using divide and conquer.

True or False: O(log n) indicates exponential growth.

False. O(log n) indicates logarithmic growth, which is slower than linear.

What does O(n!) represent?

Factorial time complexity, typical in algorithms generating permutations.

O(√n) indicates what kind of time complexity?

Sub-linear time complexity; efficiency increases with larger n.

Fill in the blank: The function f(n) = 3n + 2 is O(____).

O(n). Constants are ignored in Big O notation.

Undecidable Problems(12)

What is an undecidable problem?

A decision problem that cannot be solved by any algorithm. Examples include the Halting Problem.

True or False: The Halting Problem is decidable.

False. The Halting Problem is undecidable; no algorithm can determine if any given program halts.

Example of an undecidable problem: __________.

The Halting Problem. It's impossible to determine if a program will eventually stop.

What does the term "reductions" mean in undecidability?

Transforming one problem into another to show that if one is undecidable, so is the other.

Which problem is used to prove undecidability?

The Halting Problem is often used to prove other problems are undecidable.

Can undecidable problems be solved in any specific cases?

Yes, for particular instances, they may be solvable, but not in general.

The Church-Turing Thesis relates to undecidable problems by stating __________.

Any computation can be simulated by a Turing machine, linking undecidable problems to computation.

Example of a decision problem that is undecidable: __________.

The Post Correspondence Problem.

Fill in the blank: If a problem is undecidable, it has no __________ solution.

Algorithmic.

Which class includes problems that are reducible to the Halting Problem?

Undecidable problems class.

True or False: All problems in NP are decidable.

True. NP problems can be solved by a non-deterministic algorithm, and they are decidable.

Compare decidable and undecidable problems.

Decidable: solvable by an algorithm. Undecidable: cannot be solved by any algorithm.

Complexity Classes(8)

P vs NP: Define P.

P is the class of decision problems that can be solved in polynomial time by a deterministic Turing machine.

NP-Complete: What does it mean?

NP-Complete problems are the hardest problems in NP. If one NP-Complete problem can be solved in polynomial time, all NP problems can.

True or False: All NP problems are NP-Complete.

False. Not all NP problems are NP-Complete; NP contains problems that are easier than NP-Complete.

Difference: P vs NP.

- P: Solvable in polynomial time. - NP: Verifiable in polynomial time. - NP-Complete: Most difficult in NP.

Fill in the blank: An NP problem can be solved in __________ time.

non-deterministic polynomial time.

Cause → Effect: If P = NP, then...

...all problems in NP can be solved efficiently, revolutionizing computer science and problem-solving.

Example of NP-Complete problem?

One classic example is the Traveling Salesman Problem (TSP). It requires finding the shortest possible route visiting each city once.

What is the significance of NP-Hard?

NP-Hard problems are at least as hard as the hardest problems in NP. They are not necessarily in NP.

Questions in this Study Set(56)

1. What does algorithm efficiency primarily measure?

A.Resources required for algorithm completion
B.Number of inputs processed
C.Type of data structure used
D.Algorithm's output format

2. What does Big O notation primarily measure?

A.The worst-case time complexity of an algorithm
B.The average-case time complexity of an algorithm
C.The best-case time complexity of an algorithm
D.The space complexity of an algorithm

3. What characterizes an undecidable problem?

A.It cannot be solved by any algorithm.
B.It can be solved by a specific algorithm.
C.It has multiple solutions.
D.It can be solved in finite time.

4. Which of the following statements best defines the class P?

A.P consists of problems solvable in polynomial time by a deterministic Turing machine.
B.P consists of problems solvable in exponential time by any algorithm.
C.P consists of problems that cannot be solved efficiently.
D.P consists of problems that can be verified in polynomial time.

5. How is time complexity typically expressed?

A.Using decimal numbers
B.Using Big O notation
C.As a percentage
D.In milliseconds

6. Which of the following is true regarding O(1) and O(n)?

A.O(1) is faster than O(n)
B.O(n) is faster than O(1)
C.Both are equivalent
D.O(1) is slower than O(n)

7. Which of the following is a classic example of an undecidable problem?

A.The Halting Problem
B.Sorting numbers
C.Finding the maximum value in a list
D.Binary search

8. Which of the following is true about NP-Complete problems?

A.If one NP-Complete problem can be solved in polynomial time, all NP problems can be solved in polynomial time.
B.NP-Complete problems can be solved in logarithmic time.
C.All NP-Complete problems are also in class P.
D.NP-Complete problems are easy to solve.

9. Which of the following complexities indicates a linear algorithm?

A.O(n^2)
B.O(log n)
C.O(n)
D.O(2^n)

10. Fill in the blank: O(n log n) is often associated with ________ algorithms.

A.Quick Sort
B.Bubble Sort
C.Selection Sort
D.Linear Search

11. True or False: The Halting Problem can be resolved for some specific programs.

A.True
B.False
C.Only for infinite loops
D.Only for terminating programs

12. Which of the following is NOT true regarding NP problems?

A.All NP problems can be solved efficiently.
B.NP problems can be verified in polynomial time.
C.Some NP problems are easier than NP-Complete problems.
D.NP problems include both decision and optimization problems.

13. Fill in the blank: The space complexity of an algorithm includes both ____ and auxiliary space.

A.input size
B.output size
C.constant factors
D.types of variables

14. What is the Big O of a single loop that runs 'n' times?

A.O(n^2)
B.O(log n)
C.O(n)
D.O(1)

15. What is the significance of reductions in the context of undecidable problems?

A.It shows how one problem can be transformed into another.
B.It helps classify all problems as decidable.
C.It guarantees a solution for undecidable problems.
D.It simplifies the problem-solving process.

16. What distinguishes NP problems from P problems?

A.NP problems can be verified in polynomial time, while P problems can be solved in polynomial time.
B.P problems can be solved in linear time, while NP problems cannot.
C.NP problems are always harder than P problems.
D.P problems require non-deterministic algorithms.

17. Which algorithm typically has the highest average time complexity?

A.Merge Sort
B.Bubble Sort
C.Binary Search
D.Linear Search

18. Which of the following time complexities indicates the slowest growth?

A.O(2^n)
B.O(n^2)
C.O(log n)
D.O(n)

19. Which of the following is NOT an undecidable problem?

A.The Halting Problem
B.The Post Correspondence Problem
C.The traveling salesman problem
D.The Entscheidungsproblem

20. If it were proven that P = NP, what would be the implication?

A.All problems in NP could be solved efficiently.
B.All NP problems would be harder than P problems.
C.Some problems would remain unsolvable.
D.P would include problems not in NP.

21. What is the time complexity for performing a binary search on a sorted array?

A.O(n)
B.O(n log n)
C.O(log n)
D.O(n^2)

22. If an algorithm has a time complexity of O(n!), it typically involves what kind of computations?

A.Linear computations
B.Quadratic computations
C.Factorial computations
D.Logarithmic computations

23. What does the Church-Turing Thesis propose about computation?

A.All computations can be performed by a Turing machine.
B.Only algorithms can solve problems.
C.All problems are solvable.
D.There exist problems that are solvable only by humans.

24. Which of the following is an example of an NP-Complete problem?

A.Traveling Salesman Problem (TSP)
B.Sorting a list
C.Finding the maximum value in an array
D.Calculating the factorial of a number

25. True or False: A recursive algorithm can have worse efficiency than an iterative algorithm.

A.True
B.False
C.Depends on input size
D.Depends on algorithm type

26. True or False: O(n^3) time complexity is faster than O(n^2).

A.True
B.False
C.Depends on input size
D.Only in specific cases

27. Which statement about undecidable problems is accurate?

A.They can have algorithmic solutions for some cases.
B.They can always be solved with an algorithm.
C.They are always solvable in polynomial time.
D.They are defined as problems that can be solved.

28. Which statement about NP-Hard problems is correct?

A.NP-Hard problems are at least as hard as the hardest problems in NP but are not necessarily in NP.
B.All NP-Hard problems can be solved in polynomial time.
C.NP-Hard problems are easy to verify.
D.NP-Hard problems are a subset of NP-Complete problems.

29. What is an example of polynomial time complexity?

A.O(n)
B.O(log n)
C.O(n^3)
D.O(2^n)

30. Which scenario would lead to increased execution time in an O(n log n) algorithm?

A.Decreasing input size
B.Increasing input size
C.Using constant factors
D.Changing from O(n) to O(1)

31. Fill in the blank: An undecidable problem has no __________ solution.

A.algorithmic
B.finite
C.practical
D.unique

32. What is the significance of NP-Completeness?

A.It identifies the most difficult problems in the class NP.
B.It means all NP problems can be solved in constant time.
C.It indicates that NP-Complete problems cannot be solved at all.
D.It proves that P and NP are equivalent.

33. Which time complexity suggests a constant execution time regardless of input size?

A.O(n)
B.O(log n)
C.O(1)
D.O(n^2)

34. What is the time complexity of a nested loop where each loop runs n times?

A.O(n)
B.O(n log n)
C.O(n^2)
D.O(2^n)

35. Which of the following problems is known to be undecidable?

A.The Post Correspondence Problem
B.Finding the greatest common divisor
C.Determining if a number is prime
D.Searching a database

36. What is the difference in growth rates between O(n) and O(n log n)?

A.O(n) grows faster
B.O(n) grows slower
C.They are identical
D.O(n log n) grows slower

37. Which of these time complexities is NOT comparable to O(n)?

A.O(log n)
B.O(2n)
C.O(n^2)
D.O(n log n)

38. True or False: All problems in the class NP are undecidable.

A.True
B.False
C.Only some are undecidable
D.They are mostly undecidable

39. What does amortized time complexity provide?

A.Maximum time taken
B.Average time over operations
C.Worst-case scenario
D.Best-case scenario

40. What does O(√n) represent in terms of time complexity?

A.Linear time complexity
B.Logarithmic time complexity
C.Quadratic time complexity
D.Sub-linear time complexity

41. Which best compares decidable and undecidable problems?

A.Decidable problems can be solved by algorithms; undecidable problems cannot.
B.All problems are decidable.
C.Decidable problems are always simpler than undecidable problems.
D.Undecidable problems can be solved in some cases.

42. What happens to an algorithm with O(n^3) complexity as input size increases?

A.Performance remains constant
B.Performance decreases rapidly
C.Performance improves
D.Performance significantly slows down

43. True or False: O(2n) is equivalent to O(n).

A.True
B.False
C.Only for large n
D.Only for small n

44. Which of the following statements about the Halting Problem is true?

A.It is undecidable for any algorithm to determine if a program halts.
B.It can be solved for simple programs with a known output.
C.It is a decidable problem that can be solved with a specific algorithm.
D.It only applies to programs written in Python.

45. True or False: All algorithms execute with the same efficiency.

A.True
B.False
C.Depends on implementation
D.Depends on hardware

46. Identify the Big O notation of the Binary Search algorithm.

A.O(n)
B.O(log n)
C.O(n^2)
D.O(1)

47. How does larger input size affect algorithm efficiency?

A.It decreases execution time
B.It has no effect
C.It increases execution time
D.It always improves efficiency

48. Which of the following correctly describes the relationship between O(n) and O(n^2)?

A.O(n) is worse than O(n^2)
B.O(n^2) is faster than O(n)
C.O(n) grows slower than O(n^2)
D.Both are equivalent

49. Fill in the blank: Merge sort has a time complexity of ____.

A.O(n)
B.O(n^2)
C.O(log n)
D.O(n log n)

50. What does O(n^2) typically indicate about an algorithm's performance?

A.It has quadratic time complexity.
B.It has linear time complexity.
C.It has cubic time complexity.
D.It runs in constant time.

51. What characterizes exponential time complexity?

A.O(n)
B.O(2^n)
C.O(log n)
D.O(n^2)

52. Which of the following is NOT a characteristic of O(log n) time complexity?

A.It grows slower than O(n).
B.It indicates logarithmic growth.
C.It represents linear time complexity.
D.It is often seen in search algorithms.

53. What is the time complexity of a simple for loop that iterates n times?

A.O(1)
B.O(log n)
C.O(n)
D.O(n^2)

54. Define logarithmic time complexity.

A.O(n)
B.O(n log n)
C.O(log n)
D.O(n^2)

55. Which of the following scenarios represents an algorithm with logarithmic time complexity?

A.Searching for a number in a sorted array with binary search.
B.Checking each element in an unsorted array for a match.
C.Summing all elements in an array.
D.Iterating through a list to find the maximum value.

56. Which of the following describes the time complexity of insertion sort in the worst case?

A.O(n log n)
B.O(n^2)
C.O(n)
D.O(1)

Related Study Sets

Create Your Own Study Set

Upload a PDF, paste your notes, or describe a topic – AI generates flashcards, quizzes and more in seconds.