Algorithms
Algorithms
LMNs- Algorithms
Read
Courses
Jobs
LMNs– Algorithms
Analyze an algorithm
Asymptotic Notations
https://www.geeksforgeeks.org/lmns-algorithms-gq/ Page 1 of 8
LMNs- Algorithms - GeeksforGeeks 12/01/24, 12:19 PM
Solving recurrences
Sorting
https://www.geeksforgeeks.org/lmns-algorithms-gq/ Page 2 of 8
LMNs- Algorithms - GeeksforGeeks 12/01/24, 12:19 PM
Searching
Trees
Trees: Unlike Arrays, Linked Lists, Stack and queues, which are linear
data structures, trees are hierarchical data structures. Depth First
Traversals: (a) Inorder (b) Preorder (c) Postorder Important Tree
Properties and Formulas
Binary Search Tree, is a node-based binary tree data structure which has
the following properties:
The left subtree of a node contains only nodes with keys less than
the node’s key.
The right subtree of a node contains only nodes with keys greater
than the node’s key.
The left and right subtree each must also be a binary search tree.
There must be no duplicate nodes.
1. Insertion
2. Deletion
AVL Tree
AVL tree is a self-balancing Binary Search Tree (BST) where the difference
between heights of left and right subtrees cannot be more than one for all
nodes.
1. Insertion
https://www.geeksforgeeks.org/lmns-algorithms-gq/ Page 3 of 8
LMNs- Algorithms - GeeksforGeeks 12/01/24, 12:19 PM
2. Deletion
B-Tree
1. B-Tree Insertion
2. B-Tree Deletion
Graph
Graph Algorithms
https://www.geeksforgeeks.org/lmns-algorithms-gq/ Page 4 of 8
LMNs- Algorithms - GeeksforGeeks 12/01/24, 12:19 PM
https://www.geeksforgeeks.org/lmns-algorithms-gq/ Page 5 of 8
LMNs- Algorithms - GeeksforGeeks 12/01/24, 12:19 PM
Following are some standard algorithms that are Divide and Conquer
algorithms.
1) Binary Search is a searching algorithm. In each step, the algorithm
compares the input element x with the value of the middle element in
array. If the values match, return the index of middle. Otherwise, if x is less
than the middle element, then the algorithm recurs for left side of middle
element, else recurs for right side of middle element.
2) Quicksort is a sorting algorithm. The algorithm picks a pivot element,
rearranges the array elements in such a way that all elements smaller than
the picked pivot element move to left side of pivot, and all greater
elements move to right side. Finally, the algorithm recursively sorts the
subarrays on left and right of pivot element.
3) Merge Sort is also a sorting algorithm. The algorithm divides the array
in two halves, recursively sorts them and finally merges the two sorted
halves.
4) Closest Pair of Points The problem is to find the closest pair of points
in a set of points in x-y plane. The problem can be solved in O(n^2) time
by calculating distances of every pair of points and comparing the
distances to find the minimum. The Divide and Conquer algorithm solves
the problem in O(nLogn) time.
Greedy Approach
https://www.geeksforgeeks.org/lmns-algorithms-gq/ Page 6 of 8
LMNs- Algorithms - GeeksforGeeks 12/01/24, 12:19 PM
the smallest weight edge that doesn’t cause a cycle in the MST
constructed so far.
2) Prim’s Minimum Spanning Tree: In Prim’s algorithm also, we create a
MST by picking edges one by one. We maintain two sets: set of the
vertices already included in MST and the set of the vertices not yet
included. The Greedy Choice is to pick the smallest weight edge that
connects the two sets.
3) Dijkstra’s Shortest Path: The Dijkstra’s algorithm is very similar to
Prim’s algorithm. The shortest path tree is built up, edge by edge. We
maintain two sets: set of the vertices already included in the tree and the
set of the vertices not yet included. The Greedy Choice is to pick the edge
that connects the two sets and is on the smallest weight path from source
to the set that contains not yet included vertices.
4) Huffman Coding: Huffman Coding is a loss-less compression
technique. It assigns variable length bit codes to different characters. The
Greedy Choice is to assign least bit length code to the most frequent
character.
Dynamic Programming
https://www.geeksforgeeks.org/lmns-algorithms-gq/ Page 7 of 8
LMNs- Algorithms - GeeksforGeeks 12/01/24, 12:19 PM
BackTracking
https://www.geeksforgeeks.org/lmns-algorithms-gq/ Page 8 of 8