BigOh Flashcards
1
Q
What is log(8)
to base 2
A
its 3log(8) base 2 = 3 as 2^3 = 8
log2(value) = exponent then 2^exponent = value
2
Q
Binary search runtime
A
O(log n)
3
Q
Quick sort runtime
A
O(n log n)
4
Q
Selection sort and few other sorts runtime
A
O(n^2)
5
Q
Runtime of Complex full search, recursive algorithms that solves a problem of size N
A
O(2^n)
6
Q
O(n!) runtime example
A
you are adding a loop for every element like travelling salesman, permutations
7
Q
4 BigOh rules
A
- Always think about worst case
- remove constants
- remove non dominants
- if there are multiple inputs user different terms like (n,m,p,q)
8
Q
What are 7 steps for problem solving
A
- inputs n outputs
- bruteforce approach
- optimised approach
- modular code
- test examples
- error checks n all
- does input fit in memory- divide n conquer
Complete version
- Write down the key points at the top
- data types, input constraints, sorted or unsorted
- multiple examples of inputs and outputs covering all scenarios (empty inputs, edge cases, normal cases)
- complex and simple examples
- Start with the naive/brute force approach, discuss it with recruiter, dont code, discuss time and space complexity
- Find better approach, did we use all information recruiter provided, write down the steps, walk thru the steps with recruiter
- Write modular code, write important functions
- Test all the examples, test all the cases (edge cases), walk thru the code with recruiter
- Bullet proof the code, add error checks n all
- In case the input doesnt fit in memory at once follow divide and conquer approach (for scalability)
9
Q
Coding skills
A
- use descriptive names
- separate logically independent code to functions / write modular code, skip some functions by informing interviewer
- code comments
- testing
- discuss tradeoffs of solution