What is an algorithm? Flashcards

(10 cards)

1
Q

What is an algorithm?

A

Set of instructions to solve a problem

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

Why do we care about time/space complexity?

A

B/c its how we compare how one algorithm is better than another.

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

What is time complexity ?

A

How long does the function take compared to the size of its input?

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

Without ___ we can’t know the best case. So we must assume worst case.

A

Context!

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

What’s an example of logrithmic time? (log n)

A

Binary search tree. Cuts in half every time!

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

What’s an example of N Complexity?

A

Just regular iteration through letters of a string.

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

What is space complexity?

A

How much space in memory youre taking up relative to the size of your input

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

String dups checking - two sum style

A

Space Complexity -> O of 1 (throwing the letter out if it doesn’t match)
Time complexity -> N * (n-1)

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

String dups checking - hash map style

A

Space Complexity O of N (keeping the letter in the hash to check. NOT throwing it out as you go.)
Time complexity -> O of N.

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

If you have 64 objects, how many ways can you arrange them?

A

64! (64 factorial)

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