DS & Algorithms Flashcards

1
Q

What is an algorithm?

A

An algorithm is just the steps you take to solve a problem

A step-by-step procedure that defines a set of instructions that must be carried out in a specific order to produce the desired result

An algorithm is just a function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

When worrying about real data, what 2 things do you have to worry about?

A

Space and time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is Big-O notation?

A

It mathematically describes the complexity of an algorithm in terms of time and SPCE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Name the 4 big O time complexities

A

Quadratic O(n^2), linear O(n), logarithmic O(log n), constant time O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

O(1)

A

For all inputs to our algorithm there is and will always be only one operation required
- Order 1
- Constant Time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

O(1) Example

A

const nums = [1,2,3,4,5]
const firstNumber = nums[0]

No matter how many inputs are located in num, there will only ever be one operation needed!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

O(N)

A

For all inputs to our algorithm there will be one operation per input
- Order N
- Linear
- Linear Scaling

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

O(N) Example

A

const nums = [1,2,3,4,5]
let sum = 0;
for (let num of nums) {
sum += num
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is space complexity?

A

How much memory is used

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is time complexity?

A

How many primitive operations are executed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly