Skip to content

bhanuprakasheagala/Algorithms

Repository files navigation

Algorithms

Welcome to the Algorithms repository!

Table of Contents

Introduction

What is an Algorithm?

An algorithm is a step-by-step procedure or formula for solving a problem. It is a set of well-defined instructions in sequence to achieve a specific output from a given input. Algorithms are fundamental to computer science and are used in various fields to perform calculations, data processing, automated reasoning, and other tasks.

Characteristics of Algorithms

  1. Definiteness: Each step of the algorithm must be precisely defined. The instructions should be clear and unambiguous.
  2. Finiteness: An algorithm must always terminate after a finite number of steps.
  3. Input: An algorithm has zero or more inputs taken from a specified set of objects.
  4. Output: An algorithm produces one or more outputs.
  5. Effectiveness: The steps are basic enough to be performed, in principle, by a person using pencil and paper.

Types of Algorithms

  1. Search Algorithms: Used to retrieve information stored within some data structure. Examples include binary search and linear search.
  2. Sort Algorithms: Used to arrange data in a particular order. Examples include quicksort, mergesort, and bubblesort.
  3. Divide and Conquer Algorithms: Break the problem into smaller subproblems, solve each subproblem recursively, and combine their solutions to solve the original problem. An example is the mergesort algorithm.
  4. Dynamic Programming Algorithms: Solve problems by breaking them down into simpler subproblems and storing the results of these subproblems to avoid computing the same results again. An example is the Fibonacci sequence algorithm.
  5. Greedy Algorithms: Make a series of choices, each of which looks best at the moment, with the hope of finding the global optimum. An example is Dijkstra's algorithm for finding the shortest path.
  6. Backtracking Algorithms: Build up a solution incrementally and backtrack as soon as it determines that the current solution cannot be completed to a valid one. An example is the n-queens problem.
  7. Graph Algorithms: Operate on graphs to solve problems like finding the shortest path, maximum flow, etc. Examples include Dijkstra's algorithm and Kruskal's algorithm.

Examples of Common Algorithms

  • Binary Search: Efficiently finds the position of a target value within a sorted array.
  • Quicksort: Sorts an array by partitioning the array into sub-arrays, which are then sorted recursively.
  • Dijkstra’s Algorithm: Finds the shortest paths from a single source vertex to all other vertices in a graph.
  • Knapsack Problem: Uses dynamic programming to find the most valuable subset of items that fit in a knapsack.
  • A Algorithm*: Used in pathfinding and graph traversal, known for its efficiency and accuracy.

Real-World Applications

  1. Navigation Systems: Algorithms like Dijkstra's or A* are used to find the shortest path between locations.
  2. Search Engines: Algorithms like PageRank are used to rank web pages.
  3. Data Compression: Algorithms like Huffman coding reduce the size of files for storage and transmission.
  4. Cryptography: Algorithms like RSA are used to secure data.
  5. Machine Learning: Algorithms like gradient descent optimize models to improve performance on tasks.

This repository is a comprehensive resource for anyone interested in algorithms. It includes implementations of a wide range of algorithms in different programming languages, detailed explanations, and examples. Each algorithm is accompanied by a README file explaining its purpose, complexity, and usage.

Getting Started

To get started, clone the repository to your local machine:

git clone https://github.com/yourusername/algorithms.git

Navigate to the directory:

cd algorithms

You can find the implementation of each algorithm in its respective folder. Each folder contains a README file with detailed information about the algorithm, including its theoretical background and practical applications.

Algorithms

Sorting Algorithms

  • Bubble Sort
  • Selection Sort
  • Insertion Sort
  • Merge Sort
  • Quick Sort
  • Heap Sort
  • Radix Sort
  • Bucket Sort

Searching Algorithms

  • Linear Search
  • Binary Search

Graph Algorithms

  • Breadth-First Search (BFS)
  • Depth-First Search (DFS)
  • Dijkstra's Algorithm
  • A Search Algorithm*
  • Bellman-Ford Algorithm
  • Floyd-Warshall Algorithm
  • Kruskal's Algorithm
  • Prim's Algorithm
  • Topological Sort
  • Tarjan's Algorithm

Dynamic Programming

  • Fibonacci Sequence
  • Knapsack Problem
  • Longest Common Subsequence
  • Longest Increasing Subsequence
  • Matrix Chain Multiplication
  • Coin Change Problem
  • Edit Distance
  • 0/1 Knapsack Problem

Greedy Algorithms

  • Activity Selection Problem
  • Huffman Coding
  • Kruskal’s Minimum Spanning Tree Algorithm
  • Prim’s Minimum Spanning Tree Algorithm
  • Fractional Knapsack Problem
  • Job Sequencing Problem

Divide and Conquer

  • Merge Sort
  • Quick Sort
  • Binary Search
  • Strassen's Matrix Multiplication
  • Closest Pair of Points

Backtracking

  • N-Queens Problem
  • Sudoku Solver
  • Hamiltonian Cycle
  • Graph Coloring
  • Subset Sum Problem
  • Knight’s Tour Problem

String Algorithms

  • Knuth-Morris-Pratt (KMP) Algorithm
  • Rabin-Karp Algorithm
  • Longest Common Substring
  • Longest Palindromic Substring
  • Z Algorithm
  • Boyer-Moore Algorithm

Mathematical Algorithms

  • Sieve of Eratosthenes
  • Euclidean Algorithm
  • Primality Test
  • Greatest Common Divisor (GCD)
  • Least Common Multiple (LCM)
  • Fast Fourier Transform (FFT)

Miscellaneous Algorithms

  • Reservoir Sampling
  • Fisher-Yates Shuffle
  • Topological Sort
  • Union-Find Algorithm
  • Bloom Filter