Companion repo to a course on Udemy.com
- How performant an algorithm is
- To compare different solutions or algorithms to a problem
Examples
-
Reverse string examples tried earlier.
-
Steps code
-
N times N - Quadratic or N*N runtimes.
-
Input to algorithm is sort of steps taken in an algorithm?!
- No matter what input is the output is always in a constant time.
- Find problems which can be solved in this time.
- You have this if doubling the number of elements you are iterating over doesn't double the amount of work.
- Always assume that searching operations are log(n).
- Iterating thorough some collection of data.
- If you see for loop spanning from 0 to array.length, you probably have "n" or linear runtime.
- You have this doubling the number of elements you are iterating over doesn't double the amount of work.
- Always assume that any sorting operation is n * log(n).
- Every element in a collection has to be compared to every other elemnent. The handshake problem.
- If you add a single element to a collection, the processing power required doubles.
- Efficiency of algorithm
= Probably O(n) - Linear runtime
= Still O(n). There is no constants in runtime. No 3 times, 2 times.
= O(n + m) - That has runtime
= O(n^2) - Big Red flag. Two nested for loops.
= O(n*m)
= O(n*log(n)) - Almost every sorting algo, best complexity will be
= O(log(n)) - Already soprted array and finding someting inside it.
- How much more memory is required by doubling the problem set?
- Generally you can apply the same rules as runtime complexity.
- Reversing a string is a great example, every additional charc added to result set, was one to one mapped.
- Ways of organizing information with optimal 'runtime complexity' for adding or removing records.
- Javascript natively implements several data structures.