Starting your journey
Please don't be shy
vscode
live-share plugin
Please download this two things
Do it now
An algorithm is any well-defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values, as output. An algorithm is thus a sequence of computational steps that transform the input into the output.
Forms,
CRMs
REST services
etc.
NO
YES
New products & platforms,
science, on-line games
devices, startups
Time & Space complexity
Approaches to solve problems
Searching & Sorting
LinkedList
Trees
Graphs
Dijkstra
Dynamic Programming
Gready algorithms
Finish
Asymptotic notations are super versatile and super cool. They measures how an algorithm scales in relation to its input size
Big O Notation is a convenient way to express the worst-case scenario for an algorithm
Big Omega represents the fastest possible running time
One function is Big θ of another if and only if that function is both Big O and Big Omega of it
O(n + 5) = O(n)
O(2n) = O(n)
O(100) = O(1)
O(n² + 6n + 7) = O(n²)
O(6n^1/3 + n^1/2 + 7) = O(n^1/2)
Other examples:
Space complexity is a measure of the amount of working storage an algorithm needs. That means how much memory, in the worst case, is needed at any point in the algorithm.
This function requires 3 units of space for the parameters and 1 for the local variable, and this never changes, so this is O(1).
function sum(x, y, z) {
let r = x + y + z;
return r;
}
Space complexity
let obj = {}; // O(1)
obj.test = 1 // O(1)
delete obj.test // O(1)
someVar = obj.test // O(1)
Object.keys(obj).find(key => key === “test”) // O(kn),
// where n = number of keys, k = max chars in key
Object.keys // O(n)
Object.values // O(n)
Object.entries // O(n)
let array = [“one”, “two”, “three”];
array[1] // accessing, O(1)
array.push(“four”) // appending, O(1)
array.shift(“zero”) // prepenging, O(n)
array.pop() // popping last element, O(1)
array.unshift() // retrieving first element, O(n)
array.concat // O(n)
array.slice // O(n)
array.splice // O(n)
array.forEach // O(n)
array.sort // O(n*log(n))
let t0 = performance.now();
doSomething();
let t1 = performance.now();
console.log("Call to doSomething took " + (t1 - t0) + " milliseconds.");
Unlike other timing data available to JavaScript (for example Date.now), the timestamps returned by performance.now() are not limited to one-millisecond resolution. Instead, they represent times as floating-point numbers with up to microsecond precision.
console.time("answer time");
alert("Нажмите для продолжения");
console.timeLog("answer time");
alert("Делаем кучу другой работы...");
console.timeEnd("answer time");
Notice that the timer's name is displayed when the timer value is logged using timeLog() and again when it's stopped. In addition, the call to timeEnd() has the additional information, "timer ended" to make it obvious that the timer is no longer tracking time
Write a function that reverses a string. The input string is given as an array of characters char[].
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
/*
* Input: ["h","e","l","l","o"]
* Output: ["o","l","l","e","h"]
*/
function reverseString(s) {
};
Write a function to calculate sum of all digits in a number
/*
* Input: 123
* Output: 6
*/
function calc(n) {
};
Given an unsorted array of 999 unique numbers from 1 to 1000. Find the missing number!
OR
Start solvig easy problems!
Given an array of integers arr, write a function that returns true if and only if the number of occurrences of each value in the array is unique.
/* Input: arr = [1,2,2,1,1,3]
Output: true
Explanation: The value 1 has 3 occurrences, 2 has 2 and 3 has 1.
No two values have the same number of occurrences.
*/
/*
Input: arr = [1,2]
Output: false
*/
var uniqueOccurrences = function(arr) {
};
https://www.youtube.com/watch?v=GhFmRmCK2Ck - Time Complexity and Big O Notation of Algorithms
https://www.youtube.com/watch?v=FJcG-6g4wA4 - Learning Algorithms: Is It REALLY Necessary?
GAYLE LAAKMANN MCDOWELL Cracking the Coding Interview 6th Edition: Big O page 38
http://getyouralgorithm.blogspot.com/2015/10/big-o-notation-simplify-define.html