What is an algorithm? Flashcards
(10 cards)
What is an algorithm?
Set of instructions to solve a problem
Why do we care about time/space complexity?
B/c its how we compare how one algorithm is better than another.
What is time complexity ?
How long does the function take compared to the size of its input?
Without ___ we can’t know the best case. So we must assume worst case.
Context!
What’s an example of logrithmic time? (log n)
Binary search tree. Cuts in half every time!
What’s an example of N Complexity?
Just regular iteration through letters of a string.
What is space complexity?
How much space in memory youre taking up relative to the size of your input
String dups checking - two sum style
Space Complexity -> O of 1 (throwing the letter out if it doesn’t match)
Time complexity -> N * (n-1)
String dups checking - hash map style
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.
If you have 64 objects, how many ways can you arrange them?
64! (64 factorial)