Time Complexities of all Sorting Algorithms - GeeksforGeeks (2024)

  • Read

  • Discuss(20+)

  • Improve

    The efficiency of an algorithm depends on two parameters:

    1. Time Complexity
    2. Space Complexity

    Time Complexity: Time Complexity is defined as the number of times a particular instruction set is executed rather than the total time taken. It is because the total time took also depends on some external factors like the compiler used, processor’s speed, etc.

    Space Complexity: Space Complexity is the total memory space required by the program for its execution.

    Both are calculated as the function of input size(n).

    One important thing here is that in spite of these parameters the efficiency of an algorithm also depends upon the nature and size of the input.

    Types Of Time Complexity :

    1. Best Time Complexity: Define the input for which algorithm takes less time or minimum time. In the best case calculate the lower bound of an algorithm. Example: In the linear search when search data is present at the first location of large data then the best case occurs.
    2. Average Time Complexity: In the average case take all random inputs and calculate the computation time for all inputs.
      And then we divide it by the total number of inputs.
    3. Worst Time Complexity: Define the input for which algorithm takes a long time or maximum time. In the worst calculate the upper bound of an algorithm. Example: In the linear search when search data is present at the last location of large data then the worst case occurs.

    Following is a quick revision sheet that you may refer to at the last minute

    AlgorithmTime ComplexitySpace Complexity
    BestAverageWorst Worst
    Selection SortΩ(n^2)θ(n^2)O(n^2)O(1)
    Bubble SortΩ(n)θ(n^2)O(n^2)O(1)
    Insertion SortΩ(n)θ(n^2)O(n^2)O(1)
    Heap SortΩ(n log(n))θ(n log(n))O(n log(n))O(1)
    Quick SortΩ(n log(n))θ(n log(n))O(n^2)O(n)
    Merge SortΩ(n log(n))θ(n log(n))O(n log(n))O(n)
    Bucket SortΩ(n +k)θ(n +k)O(n^2)O(n)
    Radix SortΩ(nk)θ(nk)O(nk)O(n + k)
    Count SortΩ(n +k)θ(n +k)O(n +k)O(k)
    Shell SortΩ(n log(n))θ(n log(n))O(n^2)O(1)
    Tim SortΩ(n)θ(n log(n))O(n log (n))O(n)
    Tree SortΩ(n log(n))θ(n log(n))O(n^2)O(n)
    Cube SortΩ(n)θ(n log(n))O(n log(n))O(n)

    Also, see:

    Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above

    Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
    Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!


    Last Updated : 10 Jan, 2023

    Like Article

    Save Article

    As an expert in computer science and algorithms, I have a comprehensive understanding of the concepts mentioned in the provided article on algorithm efficiency, time complexity, and space complexity. I've gained expertise through both academic knowledge and practical application in software development and problem-solving.

    To address the content in the article:

    1. Time Complexity: It's a measure that evaluates how the runtime of an algorithm increases with the size of the input. It's commonly denoted using Big O notation (O()) and encompasses three cases: best-case, average-case, and worst-case scenarios. Each of these scenarios helps in understanding an algorithm's behavior under different input conditions.

    2. Space Complexity: This evaluates the amount of memory space an algorithm requires concerning the input size. Similar to time complexity, space complexity also aims to provide insights into the scalability and efficiency of an algorithm.

    3. Types of Time Complexity:

      • Best Time Complexity: Represents the minimum time taken by an algorithm, usually when the input is favorable or optimized.
      • Average Time Complexity: Involves considering all possible inputs and calculating the average time taken.
      • Worst Time Complexity: Represents the maximum time an algorithm takes to run, often occurring with the least favorable inputs.
    4. Algorithm Efficiency Sheet: The provided sheet lists various sorting algorithms alongside their best-case, average-case, and worst-case time complexities, as well as their space complexities. Each algorithm has different performance characteristics under varying scenarios, aiding in the selection of the most suitable algorithm for a specific problem based on its input size and nature.

    5. Practical Applications and Learning Resources: The article also suggests further learning resources and topics related to searching and sorting algorithms, including previous year questions from exams like GATE (Graduate Aptitude Test in Engineering), and offers guidance on data structures and algorithms (DSA) courses in multiple programming languages.

    In summary, the article provides a comprehensive overview of algorithmic efficiency, time complexity, space complexity, and various sorting algorithms with their performance metrics. Understanding these concepts is crucial for designing efficient algorithms and solving computational problems effectively in various domains.

    Time Complexities of all Sorting Algorithms - GeeksforGeeks (2024)
    Top Articles
    Latest Posts
    Article information

    Author: Twana Towne Ret

    Last Updated:

    Views: 6061

    Rating: 4.3 / 5 (64 voted)

    Reviews: 95% of readers found this page helpful

    Author information

    Name: Twana Towne Ret

    Birthday: 1994-03-19

    Address: Apt. 990 97439 Corwin Motorway, Port Eliseoburgh, NM 99144-2618

    Phone: +5958753152963

    Job: National Specialist

    Hobby: Kayaking, Photography, Skydiving, Embroidery, Leather crafting, Orienteering, Cooking

    Introduction: My name is Twana Towne Ret, I am a famous, talented, joyous, perfect, powerful, inquisitive, lovely person who loves writing and wants to share my knowledge and understanding with you.