Chapters 5 and 6

0.0(0)
studied byStudied by 5 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/75

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

76 Terms

1
New cards

algorithm efficiency

Big-O Notation is a mathematical tool to measure _____

2
New cards

running time,

input size

Big-O Notation describes how _____ grows with _____

3
New cards

worst-case

Big-O Notation focuses on _____ performance

4
New cards

machine-specific,

scalability

Big-O Notation ignores _____ details; emphasizes _____

5
New cards

algorithms independently

Why use Big-O?

  1. Compares _____ of hardware

6
New cards

performance

Why use Big-O?

  1. Predicts _____ as input grows large

7
New cards

best algorithm

Why use Big-O?

  1. Helps select the _____ for a problem

8
New cards

algorithm behavior

Why use Big-O?

  1. Makes _____ easier to reason about

9
New cards

Constant Time - O(I),

Logarithmic Time - O(log n),

Linear Time - O(n),

Linearithmic Time - O(n log n),

Quadratic Time - O(n^2),

Exponential / Factorial - O(2^n), O (n!)

Common Big-O Classes (6)

10
New cards

Constant Time - O(I)

runtime does not grow with input size

11
New cards

Constant Time - O(I)

operations take the same time regardless of n

12
New cards

Constant Time - O(I)

examples:

  • accessing an array element

  • checking if a stack is empty

13
New cards

Logarithmic Time - O(log n)

input is repeatedly divided (often by 2)

14
New cards

Logarithmic Time - O(log n)

very efficient even for large inputs

15
New cards

Logarithmic Time - O(log n)

example:

binary search in a sorted list

16
New cards

Linear Time - O(n)

work grows directly with input size

17
New cards

Linear Time - O(n)

processes each element once

18
New cards

Linear Time - O(n)

example:

  • finding the max value in a list

19
New cards

Linearithmic Time - O(n log n)

common for divide-and-conquer algorithms

20
New cards

Linearithmic Time - O(n log n)

faster than quadratic, slower than linear

21
New cards

Linearithmic Time - O(n log n)

examples:

  • merge sort

  • heap sort

22
New cards

Quadratic Time - O(n^2)

caused by nested loops

23
New cards

Quadratic Time - O(n^2)

work grows with the square of input size

24
New cards

Quadratic Time - O(n^2)

examples:

  • bubble sort

  • checking all pairs

25
New cards

Exponential - O(2^n)

work doubles for every additional element

26
New cards

Exponential - O(2^n)

very slow for large inputs

27
New cards

Exponential - O(2^n)

example:

  • naive Fibonacci recursion

28
New cards

Factorial Time - O (n!)

grows extremely fast

29
New cards

Factorial Time - O (n!)

common in brute-force permutation problems

30
New cards

Factorial Time - O (n!)

examples:

  • generating all permutations

  • brute-force TSP

31
New cards

repeated steps,

nested repetition,

operations repeated,

divide-and-conquer,

major operations

Using Big-O for Non-Code Algorithms:

  • identify _____ (loops in words)

  • detect _____ (steps repeated inside steps)

  • find _____ per input element

  • recognize _____ descriptions

  • count how many times _____ occur

32
New cards

count operations,

multiply,

recurrence relations,

master theorem,

best / worst / average

Using Big-O for Pseudocode / Code:

  • _____ in loops

  • _____ for nested loops

  • apply _____ for recursion

  • use _____ for divide-and-conquer

  • distinguish _____ cases

33
New cards

growth rate

Big-O measures algorithm _____

34
New cards

code,

non-code

Big-O works for ______ and ______ descriptions

35
New cards

scalability

Big-O focuses on _____, not exact time

36
New cards

algorithm efficiency

Big-O helps compare _____

37
New cards

Omega Notation

describes a lower bound

38
New cards

Omega Notation

Guarantees the runtime is at least f(n)

  • If an algorithm is Ω(f(n)):

  • It cannot run faster than f(n)

39
New cards

Omega Notation

Used to highlight minimum possible performance

40
New cards

Theta Notation

gives a tight bound

41
New cards

Theta Notation

Describes the exact growth rate

42
New cards

Theta Notation

If an algorithm is Θ(f(n)), then:

  • It does not grow faster than f(n)

  • It does not grow slower than f(n)

43
New cards

Theta Notation

Used when best and worst cases are in the same order of magnitude

44
New cards

input,

Best Case, Average Case, Worst Case,

Omega, Theta, and O

Different performance Cases

  • Real performance differs depending on _____

  • Three perspectives: _____, _____, and _____

  • These cases map well to _____, _____, and _____

45
New cards

Best Case

Fastest possible execution

46
New cards

Best Case

Minimum operations

47
New cards

Best Case

Represented using Ω

48
New cards

Average Case

Expected performance across typical inputs

49
New cards

Average Case

Balanced view

50
New cards

Average Case

Represented using Θ

51
New cards

Time Complexity

  • is a measure of the amount of time an algorithm takes to run to completion, expressed as a function of the length of the input.

  • Different Case Scenario

    • O → maximum time

    • Θ → expected time

    • Ω → minimum time

  • Use all three to capture full algorithm behavior

52
New cards

O

maximum time

53
New cards

theta

expected time

54
New cards

omega

minimum time

55
New cards

overall behavior,

separate inputs,

single complexity class,

algorithm catalogs, textbooks, performance summaries

Computing for the Time complexity of the whole algorithm:

  • We analyze the _____ of the algorithm

  • We do not _____ into best/average/worst

  • We want one _____

  • Used in _____, _____, and _____

56
New cards

Big O notation

as the standard

57
New cards

runtime

Inputs vary, so _____ varies

58
New cards

Worst-case

describes the maximum possible cost

59
New cards

Big-O

  • guarantees performance no matter what input is given

  • This makes it the standard way to express overall complexity

60
New cards

Worst-case Big-O

Key Rule:

Overall complexity = _____

61
New cards

theta

requires tight upper and lower bounds

62
New cards

omega

requires a minimum guaranteed growth pattern

63
New cards

Θ or Ω,

O(n)

  • If best/average/worst differ, then:

    • There is no single _____ for the entire algorithm

    • Only _____ remains valid.

64
New cards

space complexity

Measures memory usage

65
New cards

Variables,

Temporary structures,

Recursion depth

space complexity measures memory usage (3)

66
New cards

space complexity

Also has best, average, worst depending on structure

67
New cards

Space complexity

measures how much memory an algorithm uses during execution

68
New cards

Input space,

Auxiliary space,

Output space

Space complexity measures how much memory an algorithm uses during execution.

This includes (3)

69
New cards

Input space

Memory needed to store the input itself.

70
New cards

Auxiliary space

  • Extra memory required by the algorithm

    • variables, data structures, stacks, buffers, recursion depth, etc.

71
New cards

Output space

Memory required to store the result (sometimes included, sometimes separate).

72
New cards

Recursion

space complexity example

73
New cards

Best case

Using a recursive function

  • minimal recursion

74
New cards

Average case

Using a recursive function

  • variable depth

75
New cards

Worst case

Using a recursive function

  • deepest recursion

76
New cards