When analyzing algorithms, understanding asymptotic notations is crucial for describing their time and space complexity.
- Constant: O(1)
- Linear: O(n)
- Quadratic: O(n^2)
- Cubic: O(n^3)
- Logarithmic: O(log n)
Understanding common operations on objects and arrays is crucial for efficient algorithm design.
- Insert / Remove at End
- Insert / Remove at Beginning
- Access
- Search
- Push / Pop
- Shift / Unshift / Concat / Slice / Splice
- forEach / map / filter / reduce
-
Fibonacci Sequence
- Explanation: Series of numbers where each number is the sum of the two preceding ones.
- Code Example: (JavaScript)
function fibonacci(n) { if (n <= 1) return n; return fibonacci(n - 1) + fibonacci(n - 2); }
-
Factorial of a Number
- Explanation: Product of all positive integers up to a given number.
- Code Example: (JavaScript)
function factorial(n) { return n === 0 ? 1 : n * factorial(n - 1); }
-
Prime Number
- Explanation: A number greater than 1 not divisible by any other numbers except 1 and itself.
- Code Example: (JavaScript)
function isPrime(n) { // Implementation }
-
Power of Two
- Explanation: Numbers that can be expressed as 2^n.
- Code Example: (JavaScript)
function isPowerOfTwo(n) { // Implementation }
-
Recursion
- Explanation: A programming technique where a function calls itself.
- Code Example: (JavaScript)
function recursiveFunction() { // Implementation recursiveFunction(); // Call itself }
-
Fibonacci Sequence with Recursion
- Explanation: Calculating Fibonacci sequence using recursion.
- Code Example: (JavaScript)
function fibonacciRecursive(n) { // Implementation }
-
Factorial of a Number with Recursion
- Explanation: Calculating factorial using recursion.
- Code Example: (JavaScript)
function factorialRecursive(n) { // Implementation }