Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • DSA
  • Algorithms
  • Analysis of Algorithms
  • Sorting
  • Searching
  • Greedy
  • Recursion
  • Backtracking
  • Dynamic Programming
  • Divide and Conquer
  • Geometric Algorithms
  • Mathematical Algorithms
  • Pattern Searching
  • Bitwise Algorithms
  • Branch & Bound
  • Randomized Algorithms
Open In App
Next Article:
Why is Analysis of Algorithm important?
Next article icon

Algorithms Design Techniques

Last Updated : 07 Feb, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

What is an algorithm? 
An Algorithm is a procedure to solve a particular problem in a finite number of steps for a finite-sized input. 
The algorithms can be classified in various ways. They are: 
 

  1. Implementation Method
  2. Design Method
  3. Design Approaches
  4. Other Classifications

In this article, the different algorithms in each classification method are discussed. 

The classification of algorithms is important for several reasons:

Organization: Algorithms can be very complex and by classifying them, it becomes easier to organize, understand, and compare different algorithms.

Problem Solving: Different problems require different algorithms, and by having a classification, it can help identify the best algorithm for a particular problem.

Performance Comparison: By classifying algorithms, it is possible to compare their performance in terms of time and space complexity, making it easier to choose the best algorithm for a particular use case.

Reusability: By classifying algorithms, it becomes easier to re-use existing algorithms for similar problems, thereby reducing development time and improving efficiency.

Research: Classifying algorithms is essential for research and development in computer science, as it helps to identify new algorithms and improve existing ones.

Overall, the classification of algorithms plays a crucial role in computer science and helps to improve the efficiency and effectiveness of solving problems.
Classification by Implementation Method: There are primarily three main categories into which an algorithm can be named in this type of classification. They are: 
 

  1. Recursion or Iteration: A recursive algorithm is an algorithm which calls itself again and again until a base condition is achieved whereas iterative algorithms use loops and/or data structures like stacks, queues to solve any problem. Every recursive solution can be implemented as an iterative solution and vice versa. 
    Example: The Tower of Hanoi is implemented in a recursive fashion while Stock Span problem is implemented iteratively.
  2. Exact or Approximate: Algorithms that are capable of finding an optimal solution for any problem are known as the exact algorithm. For all those problems, where it is not possible to find the most optimized solution, an approximation algorithm is used. Approximate algorithms are the type of algorithms that find the result as an average outcome of sub outcomes to a problem. 
    Example: For NP-Hard Problems, approximation algorithms are used. Sorting algorithms are the exact algorithms.
  3. Serial or Parallel or Distributed Algorithms: In serial algorithms, one instruction is executed at a time while parallel algorithms are those in which we divide the problem into subproblems and execute them on different processors. If parallel algorithms are distributed on different machines, then they are known as distributed algorithms.

Classification by Design Method: There are primarily three main categories into which an algorithm can be named in this type of classification. They are: 
 

  1. Greedy Method: In the greedy method, at each step, a decision is made to choose the local optimum, without thinking about the future consequences. 
    Example: Fractional Knapsack, Activity Selection.
  2. Divide and Conquer: The Divide and Conquer strategy involves dividing the problem into sub-problem, recursively solving them, and then recombining them for the final answer. 
    Example: Merge sort, Quicksort.
  3. Dynamic Programming: The approach of Dynamic programming is similar to divide and conquer. The difference is that whenever we have recursive function calls with the same result, instead of calling them again we try to store the result in a data structure in the form of a table and retrieve the results from the table. Thus, the overall time complexity is reduced. “Dynamic” means we dynamically decide, whether to call a function or retrieve values from the table. 
    Example: 0-1 Knapsack, subset-sum problem.
  4. Linear Programming: In Linear Programming, there are inequalities in terms of inputs and maximizing or minimizing some linear functions of inputs. 
    Example: Maximum flow of Directed Graph
  5. Reduction(Transform and Conquer): In this method, we solve a difficult problem by transforming it into a known problem for which we have an optimal solution. Basically, the goal is to find a reducing algorithm whose complexity is not dominated by the resulting reduced algorithms. 
    Example: Selection algorithm for finding the median in a list involves first sorting the list and then finding out the middle element in the sorted list. These techniques are also called transform and conquer.
  6. Backtracking: This technique is very useful in solving combinatorial problems that have a single unique solution. Where we have to find the correct combination of steps that lead to fulfillment of the task.  Such problems have multiple stages and there are multiple options at each stage. This approach is based on exploring each available option at every stage one-by-one. While exploring an option if a point is reached that doesn’t seem to lead to the solution, the program control backtracks one step, and starts exploring the next option. In this way, the program explores all possible course of actions and finds the route that leads to the solution.  
    Example: N-queen problem, maize problem.
  7. Branch and Bound: This technique is very useful in solving combinatorial optimization problem that have multiple solutions and we are interested in find the most optimum solution. In this approach, the entire solution space is represented in the form of a state space tree. As the program progresses each state combination is explored, and the previous solution is replaced by new one if it is not the optimal than the current solution. 
    Example: Job sequencing, Travelling salesman problem.

Classification by Design Approaches : There are two approaches for designing an algorithm. these approaches include 

  1. Top-Down Approach :
  2. Bottom-up approach
  • Top-Down Approach: In the top-down approach, a large problem is divided into small sub-problem. and keep                repeating the process of decomposing problems until the complex problem is solved.
  • Bottom-up approach: The bottom-up approach is also known as the reverse of top-down approaches.
    In approach different, part of a complex program is solved using a programming language and then this is combined into a complete program.

Top-Down Approach:

Breaking down a complex problem into smaller, more manageable sub-problems and solving each sub-problem individually.
Designing a system starting from the highest level of abstraction and moving towards the lower levels.
Bottom-Up Approach:

Building a system by starting with the individual components and gradually integrating them to form a larger system.
Solving sub-problems first and then using the solutions to build up to a solution of a larger problem.
Note: Both approaches have their own advantages and disadvantages and the choice between them often depends on the specific problem being solved.

Here are examples of the Top-Down and Bottom-Up approaches in code:

Top-Down Approach:

C++




// Nikunj Sonigara
 
#include <iostream>
#include <vector>
 
using namespace std;
 
// Function to break down a complex problem
vector<string> break_down_complex_problem(const string& problem) {
    // Implementation for breaking down a complex problem
    // Replace this with actual implementation if needed
    vector<string> sub_problems;
    // ...
    return sub_problems;
}
 
// Function to combine sub-solutions
string combine_sub_solutions(const vector<string>& sub_solutions) {
    // Implementation for combining sub-solutions
    // Replace this with actual implementation if needed
    string combined_solution = "";
    // ...
    return combined_solution;
}
 
// Function to solve the problem
string solve_problem(const string& problem) {
    if (problem == "simple") {
        return "solved";
    } else if (problem == "complex") {
        vector<string> sub_problems = break_down_complex_problem(problem);
        vector<string> sub_solutions;
         
        for (const string& sub : sub_problems) {
            sub_solutions.push_back(solve_problem(sub));
        }
         
        return combine_sub_solutions(sub_solutions);
    } else {
        // Handle other cases if needed
        return "unknown";
    }
}
 
int main() {
    // Example usage
    cout << solve_problem("simple") << endl;
    cout << solve_problem("complex") << endl;
 
    return 0;
}
 
 

Java




import java.util.ArrayList;
import java.util.List;
 
public class Main {
 
    // Function to break down a complex problem
    public static List<String> breakDownComplexProblem(String problem) {
        // Implementation for breaking down a complex problem
        // Replace this with the actual implementation if needed
        List<String> subProblems = new ArrayList<>();
        // ...
        return subProblems;
    }
 
    // Function to combine sub-solutions
    public static String combineSubSolutions(List<String> subSolutions) {
        // Implementation for combining sub-solutions
        // Replace this with the actual implementation if needed
        StringBuilder combinedSolution = new StringBuilder();
        // ...
        return combinedSolution.toString();
    }
 
    // Function to solve the problem
    public static String solveProblem(String problem) {
        if ("simple".equals(problem)) {
            return "solved";
        } else if ("complex".equals(problem)) {
            List<String> subProblems = breakDownComplexProblem(problem);
            List<String> subSolutions = new ArrayList<>();
 
            for (String sub : subProblems) {
                subSolutions.add(solveProblem(sub));
            }
 
            return combineSubSolutions(subSolutions);
        } else {
            // Handle other cases if needed
            return "unknown";
        }
    }
 
    public static void main(String[] args) {
        // Example usage
        System.out.println(solveProblem("simple"));
        System.out.println(solveProblem("complex"));
    }
}
 
 

Python




def solve_problem(problem):
    if problem == "simple":
        return "solved"
    elif problem == "complex":
        sub_problems = break_down_complex_problem(problem)
        sub_solutions = [solve_problem(sub) for sub in sub_problems]
        return combine_sub_solutions(sub_solutions)
 
 

C#




using System;
using System.Collections.Generic;
 
class Program {
    // Function to break down a complex problem
    static List<string>
    BreakDownComplexProblem(string problem)
    {
        // Implementation for breaking down a complex
        // problem Replace this with actual implementation
        // if needed
        List<string> subProblems = new List<string>();
        // ...
        return subProblems;
    }
 
    // Function to combine sub-solutions
    static string
    CombineSubSolutions(List<string> subSolutions)
    {
        // Implementation for combining sub-solutions
        // Replace this with actual implementation if needed
        string combinedSolution = "";
        // ...
        return combinedSolution;
    }
 
    // Function to solve the problem
    static string SolveProblem(string problem)
    {
        if (problem == "simple") {
            return "solved";
        }
        else if (problem == "complex") {
            List<string> subProblems
                = BreakDownComplexProblem(problem);
            List<string> subSolutions = new List<string>();
 
            foreach(string sub in subProblems)
            {
                subSolutions.Add(SolveProblem(sub));
            }
 
            return CombineSubSolutions(subSolutions);
        }
        else {
            // Handle other cases if needed
            return "unknown";
        }
    }
 
    // Main method
    static void Main()
    {
        // Example usage
        Console.WriteLine(SolveProblem("simple"));
        Console.WriteLine(SolveProblem("complex"));
    }
}
 
 

Javascript




// Function to break down a complex problem
function break_down_complex_problem(problem) {
    // Implementation for breaking down a complex problem
    // Replace this with actual implementation if needed
    const sub_problems = [];
    // ...
    return sub_problems;
}
 
// Function to combine sub-solutions
function combine_sub_solutions(sub_solutions) {
    // Implementation for combining sub-solutions
    // Replace this with actual implementation if needed
    let combined_solution = "";
    // ...
    return combined_solution;
}
 
// Function to solve the problem
function solve_problem(problem) {
    if (problem === "simple") {
        return "solved";
    } else if (problem === "complex") {
        const sub_problems = break_down_complex_problem(problem);
        const sub_solutions = [];
 
        for (const sub of sub_problems) {
            sub_solutions.push(solve_problem(sub));
        }
 
        return combine_sub_solutions(sub_solutions);
    } else {
        // Handle other cases if needed
        return "unknown";
    }
}
 
// Example usage
console.log(solve_problem("simple"));
console.log(solve_problem("complex"));
 
// This code is contributed by Yash Agarwal(yashagarwal2852002)
 
 

Bottom-Up Approach (in Python):

Python




def solve_sub_problems(sub_problems):
    return [solve_sub_problem(sub) for sub in sub_problems]
 
def combine_sub_solutions(sub_solutions):
    # implementation to combine sub-solutions to solve the larger problem
 
def solve_problem(problem):
    if problem == "simple":
        return "solved"
    elif problem == "complex":
        sub_problems = break_down_complex_problem(problem)
        sub_solutions = solve_sub_problems(sub_problems)
        return combine_sub_solutions(sub_solutions)
 
 

Other Classifications: Apart from classifying the algorithms into the above broad categories, the algorithm can be classified into other broad categories like: 
 

  1. Randomized Algorithms: Algorithms that make random choices for faster solutions are known as randomized algorithms. 
    Example: Randomized Quicksort Algorithm.
  2. Classification by complexity: Algorithms that are classified on the basis of time taken to get a solution to any problem for input size. This analysis is known as time complexity analysis. 
    Example: Some algorithms take O(n), while some take exponential time.
  3. Classification by Research Area: In CS each field has its own problems and needs efficient algorithms. 
    Example: Sorting Algorithm, Searching Algorithm, Machine Learning etc.
  4. Branch and Bound Enumeration and Backtracking: These are mostly used in Artificial Intelligence.


Next Article
Why is Analysis of Algorithm important?

S

simranjenny84
Improve
Article Tags :
  • Algorithms
  • DSA
Practice Tags :
  • Algorithms

Similar Reads

  • Algorithms Tutorial
    Algorithm is a step-by-step procedure for solving a problem or accomplishing a task. In the context of data structures and algorithms, it is a set of well-defined instructions for performing a specific computational task. Algorithms are fundamental to computer science and play a very important role
    1 min read
  • What is an Algorithm | Introduction to Algorithms
    The word Algorithm means "A set of finite rules or instructions to be followed in calculations or other problem-solving operations" Or "A procedure for solving a mathematical problem in a finite number of steps that frequently involves recursive operations". Therefore Algorithm refers to a sequence
    15+ min read
  • Definition, Types, Complexity and Examples of Algorithm
    An algorithm is a well-defined sequential computational technique that accepts a value or a collection of values as input and produces the output(s) needed to solve a problem. Or we can say that an algorithm is said to be accurate if and only if it stops with the proper output for each input instanc
    13 min read
  • Algorithms Design Techniques
    What is an algorithm? An Algorithm is a procedure to solve a particular problem in a finite number of steps for a finite-sized input. The algorithms can be classified in various ways. They are: Implementation MethodDesign MethodDesign ApproachesOther ClassificationsIn this article, the different alg
    10 min read
  • Why is Analysis of Algorithm important?
    Why is Performance of Algorithms Important ? There are many important things that should be taken care of, like user-friendliness, modularity, security, maintainability, etc. Why worry about performance? The answer to this is simple, we can have all the above things only if we have performance. So p
    2 min read
  • Analysis of Algorithms

    • Asymptotic Analysis
      Given two algorithms for a task, how do we find out which one is better? One naive way of doing this is - to implement both the algorithms and run the two programs on your computer for different inputs and see which one takes less time. There are many problems with this approach for the analysis of
      3 min read

    • Worst, Average and Best Case Analysis of Algorithms
      In the previous post, we discussed how Asymptotic analysis overcomes the problems of the naive way of analyzing algorithms. Now let us learn about What is Worst, Average, and Best cases of an algorithm: 1. Worst Case Analysis (Mostly used) In the worst-case analysis, we calculate the upper bound on
      10 min read

    • Types of Asymptotic Notations in Complexity Analysis of Algorithms
      We have discussed Asymptotic Analysis, and Worst, Average, and Best Cases of Algorithms. The main idea of asymptotic analysis is to have a measure of the efficiency of algorithms that don't depend on machine-specific constants and don't require algorithms to be implemented and time taken by programs
      8 min read

    • How to Analyse Loops for Complexity Analysis of Algorithms
      We have discussed Asymptotic Analysis, Worst, Average and Best Cases and Asymptotic Notations in previous posts. In this post, an analysis of iterative programs with simple examples is discussed. The analysis of loops for the complexity analysis of algorithms involves finding the number of operation
      15+ min read

    • How to analyse Complexity of Recurrence Relation
      The analysis of the complexity of a recurrence relation involves finding the asymptotic upper bound on the running time of a recursive algorithm. This is usually done by finding a closed-form expression for the number of operations performed by the algorithm as a function of the input size, and then
      7 min read

    • Introduction to Amortized Analysis
      Amortized Analysis is used for algorithms where an occasional operation is very slow, but most other operations are faster. In Amortized Analysis, we analyze a sequence of operations and guarantee a worst-case average time that is lower than the worst-case time of a particularly expensive operation.
      10 min read

    Types of Algorithms

    • Sorting Algorithms
      A Sorting Algorithm is used to rearrange a given array or list of elements in an order. For example, a given array [10, 20, 5, 2] becomes [2, 5, 10, 20] after sorting in increasing order and becomes [20, 10, 5, 2] after sorting in decreasing order. There exist different sorting algorithms for differ
      3 min read

    • Searching Algorithms
      Searching algorithms are essential tools in computer science used to locate specific items within a collection of data. In this tutorial, we are mainly going to focus upon searching in an array. When we search an item in an array, there are two most common algorithms used based on the type of input
      3 min read

    • Greedy Algorithms
      Greedy algorithms are a class of algorithms that make locally optimal choices at each step with the hope of finding a global optimum solution. At every step of the algorithm, we make a choice that looks the best at the moment. To make the choice, we sometimes sort the array so that we can always get
      3 min read

    • Dynamic Programming or DP
      Dynamic Programming is an algorithmic technique with the following properties. It is mainly an optimization over plain recursion. Wherever we see a recursive solution that has repeated calls for the same inputs, we can optimize it using Dynamic Programming. The idea is to simply store the results of
      3 min read

    • What is Pattern Searching ?
      Pattern searching in Data Structures and Algorithms (DSA) is a fundamental concept that involves searching for a specific pattern or sequence of elements within a given data structure. This technique is commonly used in string matching algorithms to find occurrences of a particular pattern within a
      5 min read

    • Backtracking Algorithm
      Backtracking algorithms are like problem-solving strategies that help explore different options to find the best solution. They work by trying out different paths and if one doesn't work, they backtrack and try another until they find the right one. It's like solving a puzzle by testing different pi
      4 min read

    • Divide and Conquer Algorithm
      Divide and Conquer algorithm is a problem-solving strategy that involves. Divide : Break the given problem into smaller non-overlapping problems.Conquer : Solve Smaller ProblemsCombine : Use the Solutions of Smaller Problems to find the overall result.Examples of Divide and Conquer are Merge Sort, Q
      1 min read

    • Mathematical Algorithms
      The following is the list of mathematical coding problem ordered topic wise. Please refer Mathematical Algorithms (Difficulty Wise) for the difficulty wise list of problems. GCD and LCM: GCD of Two Numbers LCM of Two Numbers LCM of array GCD of array Basic and Extended Euclidean Stein’s Algorithm fo
      5 min read

    • Geometric Algorithms
      Geometric algorithms are a type of algorithm that deal with solving problems related to geometry. These algorithms are used to solve various geometric problems such as computing the area of a polygon, finding the intersection of geometric shapes, determining the convex hull of a set of points, and m
      4 min read

    • Bitwise Algorithms
      Bitwise algorithms in Data Structures and Algorithms (DSA) involve manipulating individual bits of binary representations of numbers to perform operations efficiently. These algorithms utilize bitwise operators like AND, OR, XOR, NOT, Left Shift, and Right Shift. BasicsIntroduction to Bitwise Algori
      4 min read

    • Graph Algorithms
      Graph algorithms are methods used to manipulate and analyze graphs, solving various range of problems like finding the shortest path, cycles detection. If you are looking for difficulty-wise list of problems, please refer to Graph Data Structure. BasicsGraph and its representationsBFS and DFS Breadt
      3 min read

    • Randomized Algorithms
      Randomized algorithms in data structures and algorithms (DSA) are algorithms that use randomness in their computations to achieve a desired outcome. These algorithms introduce randomness to improve efficiency or simplify the algorithm design. By incorporating random choices into their processes, ran
      2 min read

    • Branch and Bound Algorithm
      The Branch and Bound Algorithm is a method used in combinatorial optimization problems to systematically search for the best solution. It works by dividing the problem into smaller subproblems, or branches, and then eliminating certain branches based on bounds on the optimal solution. This process c
      1 min read

  • The Role of Algorithms in Computing
    Algorithms play a crucial role in computing by providing a set of instructions for a computer to perform a specific task. They are used to solve problems and carry out tasks in computer systems, such as sorting data, searching for information, image processing, and much more. An algorithm defines th
    8 min read
  • Most important type of Algorithms
    What is an Algorithm?An algorithm is a step-by-step procedure to solve a problem. A good algorithm should be optimized in terms of time and space. Different types of problems require different types of algorithmic techniques to be solved in the most optimized manner. There are many types of algorith
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences