JAVASCRIPT
ALGORITHMS
@frontend_in_depth
In this post, we’ll understand how different
tasks require different algorithms in
JavaScript.
1. Sorting algorithm
Sorting is arranging elements in a particular
order. Common algorithms include Bubble Sort,
Merge Sort, and Quick Sort.
2. Search Algorithm
Searching is finding the position of an element in
a list. Common algorithms include Linear Search
and Binary Search. This searches a sorted array
by repeatedly dividing the search interval in half.
3. Recursive Algorithm
Recursion is solving problems by
breaking them down into smaller, simpler
subproblems. This calculates the factorial of a
number by multiplying it by the factorial of the
number one less than itself.
4. Dynamic Programming
Dynamic programming solves problems by
breaking them down into simpler subproblems
and storing the results to avoid redundant
computations. This calculates the nth Fibonacci
number by storing the results of previous
computations.
5. String Manipulation
String manipulation involves altering, parsing, or
analyzing strings. Below checks if the string is
Palindrome or not. This checks if a string is a
palindrome by comparing it to its reverse.
6. Math algorithm
Math algorithms involve performing
mathematical calculations or solving math-
related problems. This calculates the greatest
common divisor (GCD) of two numbers using
the Euclidean algorithm.
7. Bit manipulation
Bit manipulation involves operations on
individual bits of binary numbers. This counts
the number of ls (set bits) in the binary
representation of a number.