CS 161

0.0(0)
studied byStudied by 6 people
0.0(0)
call with kaiCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/49

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 7:59 AM on 1/30/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

50 Terms

1
New cards

How to find O(?) between two functions

  • How to Solve

    • Take limit to infinity of g(n)/f(n) <= C, for some C > 0

    • If true, then g(n) is O(f(n))

    • Rule, put the one inside the big O in the denominator, and the other in the numerator.

2
New cards

How to find Ω(?) between two functions

  • Take limit to infinity of g(n)/f(n) >= C, for some C > 0

  • If true, then g(n) is omega(f(n))

3
New cards

How to find θ(?) between two functions

True if both functions are O(?) and Ω(?)

4
New cards

How to find o(?) between two functions

  • Take limit to infinity of g(n)/f(n) = 0

  • If true, then g(n) is o(f(n))

5
New cards

L’hopital’s Rule

knowt flashcard image
6
New cards

⅀(from 1 to n) of c

c*n

7
New cards

⅀(from 1 to n) of i

(n*(n+1))/2

8
New cards

⅀(from 1 to n) of i²

(n*(n+1)*(2n+1))/6

9
New cards

⅀(from 1 to n) of i³

(n² * (n+1)²)/4

10
New cards

Summation to theta rule

For ⅀(from 1 to n) ik, it is θ(k+1)

11
New cards

⅀(from 1 to n) of ai

 (1-an+1)/(1-a), as long as a != 1

12
New cards

⅀(from 1 to ) of ai assuming a| < 1

1/(1-a)

13
New cards
term image
knowt flashcard image
14
New cards
term image

2

15
New cards
term image
knowt flashcard image
16
New cards

logb(a*c) = ?

logb(a) + logb(c)

17
New cards

logb(a/c) = ?

logb(a) - logb(c)

18
New cards

logb(ac)

c*logb(a)

19
New cards

logb(a) = ? (3 things)

logc(a) / logc(b)

logc(a) * logb(c)

1/loga(b)

20
New cards

blogc(a) = ?

alogc(b)

21
New cards

(ba)c = ?

ba*c

22
New cards

ba*bc = ?

ba+c

23
New cards

ba/bc = ?

ba-c

24
New cards

logb1 = ?

= 0

25
New cards

logb(ba)

= a

26
New cards

(n k) = ? (combination)

n! /(k! * (n-k)!)

27
New cards

Harmonic Number, what is it, whats is the limit of it, what is it’s θ(?)

Theta(logn)

<p>Theta(logn)</p>
28
New cards

How to solve x = b^n for n

Basically do n = logb(x)

29
New cards

How to solve probability problems like x has y chance to appear in n size array, using sequential search, what is probability

probability that x appears at z position in the array of size n is 1/n, if x is 100% in the array, or 1/(y*n) if it has y chance

Then you need to do i+1 operations to find it

So probability is sum from 0 to n-1 of (i+1)/(y*n), which u can simplify down.

30
New cards

How to do an inductive proof

Prove that base case is true f(0) or f(1) usually.

Assume that f(k) is true

Prove that f(k+1) is true using f(k)

31
New cards

Post Order Traversal of a tree

Left, Right, RootP

32
New cards

Pre Order Traversal of a Tree

Root, Left, Right

33
New cards

In Order Traversal of a tree

Left, Root, Right

34
New cards

When is a binary tree considered to be proper

If every internal node has two children

35
New cards

What is the depth of a tree

Distance from root node to x node, where depth of the root is 0

36
New cards

Height

Distance from root node to furthest leaf.

37
New cards

Whats max amount of nodes of tree at level x

2x nodesM

38
New cards

Max amount of nodes and max amount of leaves of tree with height h

Max amount of nodes: 2h+1-1
Max amount of leaves: 2h

39
New cards

A binary tree with n nodes has atleast a depth of

 >= floor(logn)

40
New cards

A binary tree with n leaves has atleast a depth of

 >= ceiling(logn)

41
New cards

How to do binary search steps, what is the bigO of binary search

  1. Set low to lowest index in array, high to highest index in array

  2. Check Base Case that high>low, make sure thats true

  3. Calculate mid by doing floor((high+low)/2)

    1. If x==A[mid], return mid

    2. If x<A[mid], set high to mid+1, recalculate starting at step #2

    3. If x>A[mid], set low to mid+1, recalculate starting at step #2

      Binary Search is O(logn)

42
New cards

What is the O of insertion sort, is it stable, What about the memory notation, and what are the steps of insertion sort, assuming ascending order,

O(n2)
It is stable
Memory: In place)

  1. Start with 2nd element in the array, lets say x

  2. Compare the with the element to the left of it, say y

    1. If x<y, swap x and y, and repeat step 2

    2. If x>y, leave it, set x to next position to sort in array, and go again at step 2

    3. Repeat until end of array

43
New cards

What is the O-notation of selection sort, is it stable, and what are the steps of selection sort, assuming ascending order

O(n2)
It is not stable

Two Ways:

  1. Search array for min, swap it to front, keep doing this

  1. Search array for max, swap it to back, keep doing this

44
New cards

What is the O-notation of quick sort, is it stable, what is the average case, What is the memory requirement, what are the steps,

WOrst Case: O(n2)
It is not stable
Memory: O(logn) for extra stack

Average Case: O(nlogn)
1. This one is hard to explain in steps, you just really need to go over example #6 in HW2, or #1 in HW3

45
New cards

What is the O-notation of Merge Sort, is it stable, what is the memroy requirement, what are the steps

Worst Case: O(nlogn)
It is stable
Memory: O(n) extra for merge

Basically, keep splitting array in half, recursively, until its just two elements, then merge together, starting with left, then right, make sure to do example.

46
New cards

What is the O-notation of HeapSort, is it stable, what is the memroy requirement, what are the steps, how do you find parent of leaf, how do you find left child of parent, right child of parent

Worst Case: O(nlogn)
It is NOT stable
Memory: In Place

Steps:
1. Heapify the array (basically make it into heap, easiest way is draw a tree
2. RemoveMin or Max (depending on tpye of heap)
3. Replace with last leaf in heap, siftdown.

Right Child of i = 2i+2
Left child of i = 2i+1
Parent of i = floor((i-1)/2)

47
New cards

Rank the following: logn, ny. (for y >1 and y<=1 , 1/n, 1, (logn)y, an nn, n!, nn, n!, ab^n, (logn)n

  1. O(1/n)

  2. O(1)

  3. O(logn)

  4. O(logn)y

  5. O(ny) for 0 < y <= 1

  6. O(nlogn)

  7. O(ny) for y > 1

  8. O(an)

  9. O((logn)n)

  10. O(n!)

  11. O(ab^n)

  12. O(nn)

48
New cards

In average qucijk sort case, how do you sort the keys of permutations, how do you find the probability that two keys are compared.

Sort array in ascending order, then list keys based on index

The probability that the keys sj and si are compared (assuming j>i) is: 2/(j-i+1)

49
New cards

Inversion

Pair of items in a sequence such that the larger one precedes the smaller one

50
New cards

Steps To solving line intersections

  1. Assign labels for left side top to bottom (6 at top, 1 at bottom for example)

  2. Assign labels to right side, for where the lines meet on the left side (line labels should be the same)

  3. The list created is bottom to top of right side

  4. Count permutations in list = intersections