ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Analysis of Algorithms
    COMP4121
    Progress0 / 28 topics
    Topics
    1. Introduction2. Role of Algorithms in Computing3. Analysis on Nature of Input and Size of Input4. Asymptotic Notations5. Big-O Notation6. Big-Ω Notation7. Big-Θ Notation8. Little-o Notation9. Little-ω Notation10. Sorting Algorithm Analysis11. Loop Invariants12. Recursion and Recurrence Relations13. Algorithm Design Techniques14. Brute Force Approach15. Divide-and-Conquer Approach16. Merge Sort17. Quick Sort18. Greedy Approach19. Dynamic Programming20. Elements of Dynamic Programming21. Search Trees22. Heaps23. Hashing24. Graph Algorithms25. Shortest Paths26. Sparse Graphs27. String Matching28. Introduction to Complexity Classes
    COMP4121›Asymptotic Notations
    Analysis of AlgorithmsTopic 4 of 28

    Asymptotic Notations

    7 minread
    1,131words
    Intermediatelevel

    Asymptotic Notations

    In algorithm analysis, we use asymptotic notations to describe the performance or complexity of an algorithm in relation to the size of the input, especially as the input grows towards infinity. Asymptotic notations help in comparing algorithms and understanding their efficiency in a way that abstracts away constant factors and focuses on how the algorithm behaves for large inputs.

    The three most commonly used asymptotic notations are Big O (O), Omega (Ω), and Theta (Θ). There are also little o and little ω notations, which are less commonly used but still valuable in certain situations.


    1. Big O Notation (O)

    • Definition: Big O notation describes the upper bound of the time or space complexity of an algorithm. It provides an upper limit on the growth rate of the algorithm's complexity, ensuring that the algorithm will not take longer than a certain amount of time as the input size increases.
    • Usage: It is used to express the worst-case scenario (maximum growth) for an algorithm. In other words, Big O tells you the maximum amount of time or space an algorithm will take, regardless of the input.

    Common Examples of Big O:

    • O(1): Constant time – the algorithm's running time does not depend on the size of the input.

      • Example: Accessing an element in an array by index.
    • O(log n): Logarithmic time – the algorithm's running time grows logarithmically as the input size increases. Typically seen in divide-and-conquer algorithms.

      • Example: Binary search on a sorted array.
    • O(n): Linear time – the running time grows linearly with the size of the input.

      • Example: Linear search in an unsorted array.
    • O(n log n): Log-linear time – commonly seen in efficient sorting algorithms like MergeSort or QuickSort.

      • Example: MergeSort.
    • O(n²): Quadratic time – the running time grows quadratically with the input size. Common in algorithms with nested loops.

      • Example: Bubble sort, Selection sort, or Insertion sort.
    • O(2^n): Exponential time – the running time doubles with each additional input element. This is typical for algorithms that solve problems through brute force.

      • Example: Solving the traveling salesman problem with a brute-force approach.

    Example:

    If an algorithm has a time complexity of O(n²), it means that as the input size n increases, the running time grows proportional to the square of the input size.


    2. Omega Notation (Ω)

    • Definition: Omega notation describes the lower bound of an algorithm’s running time. It provides a guarantee that the algorithm will take at least a certain amount of time (in the best case) as the input size grows.
    • Usage: Omega notation is used to express the best-case scenario or the minimum time required by the algorithm.

    Common Examples of Omega Notation:

    • Ω(1): Constant time – even in the best case, the algorithm will take a constant amount of time.

      • Example: Accessing a specific element in an array.
    • Ω(n): Linear time – in the best case, the algorithm’s running time grows linearly with the input size.

      • Example: Linear search (best case when the target is at the beginning).

    Example:

    For a sorting algorithm, if it is guaranteed that it will always require at least Ω(n) operations (such as comparing elements), we know that the algorithm cannot be faster than O(n).


    3. Theta Notation (Θ)

    • Definition: Theta notation provides a tight bound on the running time of an algorithm, meaning it describes both the upper and lower bounds of the time complexity. In other words, if an algorithm has Θ(f(n)), it means the algorithm's running time is bounded both above and below by the function f(n) for large enough n.
    • Usage: It is used when we want to describe the algorithm's running time more precisely, without focusing on the worst or best case alone. It is the most precise way to represent the running time of an algorithm.

    Common Example of Theta Notation:

    • Θ(n log n): Log-linear time – this is the exact time complexity for algorithms like MergeSort and QuickSort on average.

    • Θ(n²): Quadratic time – when an algorithm has both its upper and lower bounds as quadratic.

      • Example: Bubble Sort in its worst, best, and average cases.

    Example:

    If an algorithm has Θ(n²), it means that both the upper bound (worst case) and the lower bound (best case) for the algorithm are quadratic in nature. In this case, the running time grows exactly like n² for large inputs.


    4. Little o Notation (o)

    • Definition: Little o notation represents an upper bound that is not tight. In other words, it describes the situation where the function grows strictly slower than the given asymptotic function. It indicates that the algorithm's complexity is strictly smaller than the given function for large input sizes.
    • Usage: It is used when you want to show that an algorithm’s time complexity grows strictly slower than a certain function.

    Example:

    If a function is o(n²), it means that as the input size increases, the running time grows strictly slower than n². So, an algorithm that runs in O(n log n) would have a time complexity of o(n²).


    5. Little ω Notation (ω)

    • Definition: Little ω notation represents a lower bound that is not tight. It indicates that the algorithm’s running time grows strictly faster than a given function for large inputs.
    • Usage: Little ω is used to show that an algorithm takes at least a certain amount of time, but strictly more than the given function.

    Example:

    If an algorithm runs in ω(n), it means that for large inputs, the algorithm’s running time grows strictly faster than n. For example, an algorithm running in O(n²) would have a lower bound of ω(n).


    6. Comparing Big O, Omega, and Theta

    Notation Description Best Case Worst Case Exact Bound
    Big O (O) Upper bound (worst case) No guarantee Maximum No exact bound
    Omega (Ω) Lower bound (best case) Minimum No guarantee No exact bound
    Theta (Θ) Tight bound (exact bound for both worst and best) Exact Exact Exact bound

    Summary

    Asymptotic notations allow us to describe the performance of algorithms in terms of their input size, especially for large inputs. These notations give us a way to abstract away constant factors and focus on the growth rate of the algorithm’s time or space complexity:

    • Big O (O): Upper bound, worst-case performance.
    • Omega (Ω): Lower bound, best-case performance.
    • Theta (Θ): Tight bound, both upper and lower bounds.
    • Little o (o): Upper bound that is not tight.
    • Little ω (ω): Lower bound that is not tight.

    By using these notations, we can efficiently compare algorithms and understand how their performance scales as the input size increases.

    Previous topic 3
    Analysis on Nature of Input and Size of Input
    Next topic 5
    Big-O Notation

    Past Papers

    Open this section to load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time7 min
      Word count1,131
      Code examples0
      DifficultyIntermediate