Big O notation + log Flashcards
(9 cards)
What is big O notation
Describes the time and space complexity of an alogorithm
Explain what log2(n) means
This means the number of times you can divide n by before reaching 1
Give an example of log2(n)
log2(8) = 8 - 4 - 2 - 1. This would be 3 visits
what Big o notation is binary search
O(log n) - Binary search works by repeatedly dividing the search space in half:
Start with a sorted array. Compare the target to the middle element. If the target is smaller, discard the right half; if larger, discard the left half. Repeat until the target is found or the search space is empty.
Since the array is halved each time, the number of steps grows logarithmically with input size (n)
what equation is selection sort
n2 - quadratic time, ineficiant for large data sets. This is because it makes mutiple comparisons.
What is black box testing
- Testing functionallility without knowing internal code
- Testing from a users perspective
what is white box testing
- testing the soruce code and internal code structure
- The goal is to test every possible possibillity
Give me a simple recursive method
int fact (int n){
if (n == 1){
return 1
}else{
n * fact(n - 1);
}
}
- loops keeps running until the base case it met