BigOh Flashcards

1
Q

What is log(8) to base 2

A

its 3
log(8) base 2 = 3 as 2^3 = 8
log2(value) = exponent then 2^exponent = value

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

Binary search runtime

A

O(log n)

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

Quick sort runtime

A

O(n log n)

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

Selection sort and few other sorts runtime

A

O(n^2)

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

Runtime of Complex full search, recursive algorithms that solves a problem of size N

A

O(2^n)

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

O(n!) runtime example

A

you are adding a loop for every element like travelling salesman, permutations

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

4 BigOh rules

A
  1. Always think about worst case
  2. remove constants
  3. remove non dominants
  4. if there are multiple inputs user different terms like (n,m,p,q)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are 7 steps for problem solving

A
  1. inputs n outputs
  2. bruteforce approach
  3. optimised approach
  4. modular code
  5. test examples
  6. error checks n all
  7. does input fit in memory- divide n conquer

Complete version

  1. Write down the key points at the top
    1. data types, input constraints, sorted or unsorted
    2. multiple examples of inputs and outputs covering all scenarios (empty inputs, edge cases, normal cases)
    3. complex and simple examples
  2. Start with the naive/brute force approach, discuss it with recruiter, dont code, discuss time and space complexity
  3. Find better approach, did we use all information recruiter provided, write down the steps, walk thru the steps with recruiter
  4. Write modular code, write important functions
  5. Test all the examples, test all the cases (edge cases), walk thru the code with recruiter
  6. Bullet proof the code, add error checks n all
  7. In case the input doesnt fit in memory at once follow divide and conquer approach (for scalability)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Coding skills

A
  1. use descriptive names
  2. separate logically independent code to functions / write modular code, skip some functions by informing interviewer
  3. code comments
  4. testing
  5. discuss tradeoffs of solution
How well did you know this?
1
Not at all
2
3
4
5
Perfectly