Big O Notation Flashcards

1
Q

What do O and n stand for in Big O Notation?

A

O: “order of the functions” “operarations”

n: “the size of the dataset”

2
Q

What are the common functions for data structures?

A

access, search

insert, delete

3
Q

What is the most common space complexity?

A

O(n)

linear time

4
Q

What is the space complexity for a Skip List?

A

O(n log n)

5
Q

What is constant time?

A

O(1)

An operation that takes the same amount of time, no matter the size of the dataset

6
Q

What is linear time?

A

O(n)

An operation where time increases as size increases

7
Q

What is logarithmic time?

A

O(log n)

An operation that decreases the size of the dataset each iteration

8
Q

A

O(n^2)

An operation that runs more than one loop (nested loops)

9
Q

What is exponential time?

A

O(2^n)

An operation that has multiple permutations for each input

“Brute Force” algorithms

10
Q

What are the time complexities? Rate them fastest to slowest.

A
```Constant O(1) fastest
Logarithmic O(log n) fast for large datasets
Linear O(n) fast for small datasets
O(n log n) slower than linear
Quadratic O(n^2) slower as data grows
Exponential O(2^n) very slow
Factorial O(n!) Slowest```
11
Q

What are the time complexities of access & search for stacks, queues, and linked-lists?

A

Both are linear time O(n)

12
Q

What are the time complexities of insert & delete for stacks and queues?

A

Both are constant time O(1)

13
Q

What are the time complexities of an array?

A

Access O(1) constant time

```Search O(n) linear time
Insertion O(n)
Deletion O(n)```
14
Q

What are the time complexities of
access, search, insert, delete for
B-tree, Red-Black-tree, & AVL-tree?

A

All are logarithmic time O(log n)

15
Q

What is the time complexity of quicksort?

Space complexity?

A

Can be O(n log n)

Space: O(log n)

16
Q

What is the time complexity of mergesort?

Space complexity?

A

Time O(n log n)

Space O(n) linear

17
Q

What is the time complexity of timesort?

Space complexity?

A

Time: O(n log n)

Space: O(n) linear

18
Q

What is the time complexity of heap sort?

Space complexity?

A

Time: O(n log n)

Space: O(1)

19
Q

What are the time and space complexities of bubble, insertion, and selection sort?

A

Space O(1)

20
Q

What is an “in-place” algorithm?

A

An algorithm that transforms its input and uses no auxiliary data structure

21
Q

What is a pointer?

A

An object that stores a memory address

A pointer references a location in memory

22
Q

What are the pros and cons of an in-place algorithm

A

Pro: it is very time efficient

Con: it mutates the original data structure

23
Q

What are the time complexities for a hash table?

A
```search, insert, delete:
Worst O(n) linear
Best O(1) constant```
24
Q

What are the time complexities for a skip list, binary search tree, and KD tree?

A

access, search, insertion, delete:
Worst: O(n)
Best: O(log n)

25
Q

What are the time complexities of a splay tree?

A
```search, insert, delete:
Always O(log n)```
26
Q

What arenthe time complexities of a Cartesian Tree?

A

search, insert, delete:
Worst: O(n)
Best: O(log n)

27
Q

What is accessing a data structure?

A

access:

When you use the element’s index|address to get the value

28
Q

What is searching a data structure?

A

Searching is iterating/traversing the data structure to find the element you are looking for

29
Q

What is insertion?

A

Adding an element to a data structure

30
Q

What is deletion?

A

Removing an element from a data structure

31
Q

What is Amortized Time?

A

Essentially amortized time means “average time taken per operation, if you do many operations”.

If you do an operation a million times, you don’t really care about the worst-case or the best-case of that operation.

What you care about is how much time is taken in total when you repeat the operation a million times.