Data structures and algorithms | Algorithms | DSA

mrcaption49

Pranav Bakare

Posted on November 2, 2024

Data structures and algorithms | Algorithms | DSA

In computer science, algorithms are often categorized based on their function and data structure. Here’s a breakdown of basic algorithm types by their core functions:

  1. Searching Algorithms

These algorithms help locate a specific item within a data structure, like an array or list.

Linear Search: Checks each element sequentially until the target is found.

Binary Search: Efficiently searches a sorted array by repeatedly dividing the search interval in half.

Jump Search: Skips ahead in a sorted array and then performs a linear search within the segment.

Interpolation Search: Used on uniformly distributed sorted arrays; estimates the position of the search key.

  1. Sorting Algorithms

These algorithms reorder elements in a specific sequence, typically ascending or descending.

Bubble Sort: Repeatedly swaps adjacent elements if they’re in the wrong order.

Selection Sort: Finds the smallest element and moves it to the sorted portion of the list.

Insertion Sort: Builds a sorted list by inserting each element in its proper place.

Merge Sort: Uses a divide-and-conquer approach to split, sort, and merge lists.

Quick Sort: Divides the list using a pivot and sorts the subarrays recursively.

  1. Tree Algorithms

Tree algorithms are used to navigate, manipulate, or search within tree data structures.

Binary Tree Traversal: Techniques like in-order, pre-order, and post-order traversal to visit nodes in specific sequences.

Binary Search Tree (BST): A binary tree where each node has a left (smaller) and right (larger) child.

AVL Tree: A self-balancing binary search tree.

Red-Black Tree: A balanced BST that follows specific color rules for balancing.

Segment Tree: Used for range queries and updates.

  1. Graph Algorithms

These algorithms operate on graphs, which consist of nodes (vertices) and edges.

Depth-First Search (DFS): Explores as far as possible along each branch before backtracking.

Breadth-First Search (BFS): Explores all neighbors before moving to the next level.

Dijkstra’s Algorithm: Finds the shortest path between nodes in a weighted graph.

Bellman-Ford Algorithm: Finds shortest paths but works even with graphs with negative weights.

Floyd-Warshall Algorithm: Computes shortest paths between all pairs of nodes.

  1. Dynamic Programming Algorithms

Dynamic programming (DP) is used to solve complex problems by breaking them down into overlapping subproblems.

Fibonacci Sequence: Calculates the nth Fibonacci number using a bottom-up approach.

Knapsack Problem: Solves optimization problems for resource allocation.

Longest Common Subsequence (LCS): Finds the longest sequence common to two strings.

Matrix Chain Multiplication: Determines the optimal way to multiply matrices.

  1. Greedy Algorithms

Greedy algorithms make the best local choice at each step to find an overall optimum.

Prim’s Algorithm: Finds the minimum spanning tree for a graph.

Kruskal’s Algorithm: Also finds the minimum spanning tree by adding the lowest-cost edges.

Huffman Coding: Compresses data by building a binary tree with the shortest codes for the most common symbols.

Activity Selection: Selects the maximum number of activities that don’t overlap in time.

  1. Backtracking Algorithms

These algorithms try solutions incrementally and backtrack when they reach a dead end.

N-Queens Problem: Places N queens on an N×N board without conflicts.

Sudoku Solver: Uses a backtracking approach to fill the puzzle grid.

Maze Solver: Finds a path in a maze by exploring each possibility.

  1. Divide and Conquer Algorithms

Divide and conquer algorithms solve problems by breaking them down into smaller subproblems.

Merge Sort: Divides the list in halves, sorts each half, and merges them.

Quick Sort: Divides the list around a pivot.

Binary Search: Divides the search interval to find the target in logarithmic time.

Each of these categories offers different approaches for handling various types of computational problems, making it easier to choose the right algorithm for a specific task.

💖 💪 🙅 🚩
mrcaption49
Pranav Bakare

Posted on November 2, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related