2021 January 7th
I love to cook, eat delicious food & learn new recipes. Algorithms for me are programming recipes. As with recipes I Cook, Eat, Tweak & Repeat this concept I follow with algoritms write, run, tweak, repeat.
In my humble opinion, a good way to improve one's cooking skills is to take those recipes and create your own either by tweaking or taking the concepts of what one has learned and applying them to different ingredients, in this case different languages.
In this post I chose JS as the language to learn the below algorithms because it's the language of the web and a language I want to master. Using Big O notation
"Big O notation is a mathematical notation that describes the limiting behavior of a function when the argument tends towards a particular value or infinity." Wikipedia
- Two Sum
- Fibonacci - learn recursion
- FizzBuzz - little fun test
- Dijkstra - shortest path between nodes
- Harmless Ransom Note use Big O notation
- Palindrome - String & array manipulation - String and array methods
- Caesar's Cipher - encryption
- Reverse string
Two Sum Algorithm
Check array for sum of two values with Big O notation
This algorithm will be a JS
function that takes two parameters, a numbers array
arr and a sum value called
function returns a of pair indices from
arr that add up to the
This first attempt is using brute force O(n2). To test copy / paste
The arr passed in has already been defined within the JS code as
const arr = [3, 7, 11, 15];.
You could also enter an array and a sum of your own like this example
twoSumBrute([9, 33, 50, 41], 59);
If a sum is not in the array an error will the arr and sum passed in will be returned
Error no two numbers in array for sum: 159
SyntaxError: No-Inline evaluations must call `render`.