ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCOMP4121Asymptotic Notations
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    COMP4121

    Analysis of Algorithms

    Progress0 / 28 done
    Topics28
    1Introduction2Role of Algorithms in Computing3Analysis on Nature of Input and Size of Input4Asymptotic Notations5Big-O Notation6Big-Ω Notation7Big-Θ Notation8Little-o Notation9Little-ω Notation10Sorting Algorithm Analysis11Loop Invariants12Recursion and Recurrence Relations13Algorithm Design Techniques14Brute Force Approach15Divide-and-Conquer Approach16Merge Sort17Quick Sort18Greedy Approach19Dynamic Programming20Elements of Dynamic Programming21Search Trees22Heaps23Hashing24Graph Algorithms25Shortest Paths26Sparse Graphs27String Matching28Introduction to Complexity Classes
    7 min read
    Topic 4 of 28
    Topic Study Note Illustration
    04

    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...

    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 view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    7mremaining
    1.1kwords
    Intermediatelevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Analysis of Algorithms