Grokking Algorithms Flashcards
what is an algorithm?
it’s a set of instructions that accomplish a specific task,
any piece of code is an algorithm.
what do we use for searching?
binary search
what does a binary search need?
it needs a sorted list as it’s input
what is the big o of linear time (exhaustive search)
O(n)
what is the big O of binary search?
O(Log(n))
what does big O notation do?
it gives an indication of how fast an algorithm is running
why do we calculate big O notation?
because algorithms grow at different rates
what does big O notation calculate?
number of operations
what scenario does big O notations give?
worst-case scenario
what is big O for reading an array vs linked list?
array : O(1)
list : O(n)
what is big O for insertion an array vs linked list?
array : O(n)
list : O(1)
what is big O for deletion an array vs linked list?
array : O(n)
list : O(1)
what are the types of accessing elements in memory?
1 - random access
2 - sequential access
what does random access mean and who do we use it with?
we use it with an array and it means i can go to an exact index in memory
what does sequential access mean and who do we use it with?
we use it with linked lists and arrays, and it means that we have to go through the list reach time to reach a specific element or index
what is the big O notation for selection sort?
O(n^2)
what is the difference in performance for loops and recursion?
loops : performance for program
recursion : performance for programmer
what are the two parts for every recursive function?
1 - base case
2 - recursive case
what are the two operations of a stack?
push and pop
what is divide and conquer?
they are recursive algorithms
what is the worst case and average case for quicksort?
worst : O(n^2)
average : n log n
which is faster quick sort or merge sort?
quicksort because the constant is always smaller
how to choose the pivot for quicksort?
always choose the middle because if you get the first or last you might end up in the worst case scenario because it divides the sorted array into uneven sides and you will often hit the worst case
what is a hash function?
it takes in a string and gives back a number