List all the time complexities, from most efficient to least
O(1), O(logn), O(n), O(nlogn), On^k), O(k^n), O(n!)
What does constant time (O(1)) complexity mean?
As the size of the input/problem increases;
the amount of time taken remains the same;
What does linear time (O(n)) complexity mean?
As the size of the input/problem increases;
the amount of time taken increases at the same rate (directly proportional relationship);
What can O(n!) be described as?
The number of permutations (ways of arranging) of n
What is an intractable problem?
Problem can be solved but only in exponential time (or greater)
What is a tractable problem?
Problem can be solved in polynomial time (or less)
What is a heuristic algorithm?
Finds a close-to-optimal solution by relaxing the constraints of the problem to reduce the size of the problem space
What approaches can we take to try and solve intractable problems?
Use a heuristic algorithm, providing a close-to-optimal solution;
It makes use of estimates based on experience and relaxes some constraints of the problem;
State and explain the time complexity of the linear search [3]
O(n);
As the size of the list/problem increases, the time taken increases at the SAME RATE;
The worst-case scenario is that ALL ๐ items will be visited (if item is at the end of the list);
State and explain the time complexity of the binary search [3]
O(log n);
Each comparison halves the size of the list that has to be searched through;
If the size of the list doubles then the number of comparisons needed only increases by 1;
Explain how the Bubble Sort works [3]
On each pass through the list it compares each pair of adjacent items;
If they’re in the wrong order, the items are swapped;
Does at most n passes through the list;
State and explain the time complexity of the Bubble Sort [3]
O(n^2);
The algorithm makes (at most) ๐ passes through the list;
On each pass ๐ items are examined;
State two ways to improve the efficiency of the Bubble Sort [2]
**Solution 1: **
Have a flag (Boolean) variable that is set to True if a swap is made and reset to False at the start of each pass.
Change the outer loop so that it would stop repeating if no swaps have been made;
**Solution 2: **
After the inner loop subtract 1 fromits upper limit;
by subtractingthe pass numberfromthe length of the list;
State and explain the time complexity of the merge sort [2]
Merge Sort works by repeatedly halving the list into sublists until there are n lists of 1 element.
The halving process takes ๐ถ(๐๐๐โก๐) operations;
These sublists are then compared with adjacent sublists and ordered. This takes ๐ถ(๐) operations;