In the analysis of algorithms, asymptotic notations are used to evaluate the performance of an algorithm by providing an exact order of growth.
- Tteta Notation provides an exact bound on time or space complexity as it bounds a function from both upper and lower side,
- Compared to Big O or Big Omega , It gives more information in cases where we have exact bound available and should be preferred. For example, for Merge Sort, we can say that time is Θ(n Log n) and for Binary Search, we can say worst case time is Θ(Log n).
Definition: Let g and f be the function from the set of natural numbers to itself. The function f is said to be Θ(g), if there are constants c1, c2 > 0 and a natural number n0 such that c1* g(n) ≤ f(n) ≤ c2 * g(n) for all n ≥ n0
Θ (g(n)) = {f(n): there exist positive constants c1, c2 and n0 such that 0 ≤ c1 * g(n) ≤ f(n) ≤ c2 * g(n) for all n ≥ n0}
Note: Θ(g) is a set
The above definition means, if f(n) is theta of g(n), then the value f(n) is always between c1 * g(n) and c2 * g(n) for large values of n (n ≥ n0). The definition of theta also requires that f(n) must be non-negative for values of n greater than n0.

In simple language, Big - Theta(Θ) notation specifies asymptotic bounds (both upper and lower) for a function f(n) and provides the
Example: Consider an example to find whether a key exists in an array or not using linear search. The idea is to traverse the array and check every element if it is equal to the key or not.
The pseudo-code is as follows:
bool linearSearch(int a[], int n, int key)
{
for (int i = 0; i < n; i++) {
if (a[i] == key)
return true;
}
return false;
}
Below is the implementation of the above approach:
// C++ program for the above approach
#include <bits/stdc++.h>
using namespace std;
// Function to find whether a key exists in an
// array or not using linear search
bool linearSearch(int a[], int n, int key)
{
// Traverse the given array, a[]
for (int i = 0; i < n; i++) {
// Check if a[i] is equal to key
if (a[i] == key)
return true;
}
return false;
}
// Driver Code
int main()
{
// Given Input
int arr[] = { 2, 3, 4, 10, 40 };
int x = 10;
int n = sizeof(arr) / sizeof(arr[0]);
// Function Call
if (linearSearch(arr, n, x))
cout << "Element is present in array";
else
cout << "Element is not present in array";
return 0;
}
// Java program for the above approach
import java.lang.*;
import java.util.*;
class GFG {
// Function to find whether a key exists in an
// array or not using linear search
static boolean linearSearch(int a[], int n, int key)
{
// Traverse the given array, a[]
for (int i = 0; i < n; i++) {
// Check if a[i] is equal to key
if (a[i] == key)
return true;
}
return false;
}
// Driver code
public static void main(String[] args)
{
// Given Input
int arr[] = { 2, 3, 4, 10, 40 };
int x = 10;
int n = arr.length;
// Function Call
if (linearSearch(arr, n, x))
System.out.println(
"Element is present in array");
else
System.out.println(
"Element is not present in array");
}
}
// This code is contributed by avijitmondal1998
# Python3 program for the above approach
# Function to find whether a key exists in an
# array or not using linear search
def linearSearch(a, n, key):
# Traverse the given array, a[]
for i in range(0, n):
# Check if a[i] is equal to key
if (a[i] == key):
return True
return False
# Driver Code
arr = 2, 3, 4, 10, 40
x = 10
n = len(arr)
if (linearSearch(arr, n, x)):
print("Element is present in array")
else:
print("Element is not present in array")
// C# program for above approach
using System;
class GFG{
// Function to find whether a key exists in an
// array or not using linear search
static bool linearSearch(int[] a, int n,
int key)
{
// Traverse the given array, a[]
for(int i = 0; i < n; i++)
{
// Check if a[i] is equal to key
if (a[i] == key)
return true;
}
return false;
}
// Driver Code
static void Main()
{
int[] arr = { 2, 3, 4, 10, 40 };
int x = 10;
int n = arr.Length;
if (linearSearch(arr, n, x))
Console.Write("Element is present in array");
else
Console.Write("Element is not present in array");
}
}
// Function to find whether a key exists in an array using linear search
function linearSearch(arr, key) {
for (let i = 0; i < arr.length; i++) {
if (arr[i] === key) {
return true;
}
}
return false;
}
// Driver code
const arr = [2, 3, 4, 10, 40];
const x = 10;
// Function call
if (linearSearch(arr, x)) {
console.log("Element is present in array");
} else {
console.log("Element is not present in array");
}
Output
Element is present in array
In a linear search problem, let's assume that all the cases are uniformly distributed (including the case when the key is absent in the array). So, sum all the cases (when the key is present at position 1, 2, 3, ......, n and not present, and divide the sum by n + 1.
Average case time complexity =
\frac{\sum_{i=1}^{n+1}\theta(i)}{n + 1} ⇒
\frac{\theta((n+1)*(n+2)/2)}{n+1} ⇒
\theta(1 + n/2) ⇒
\theta(n) (constants are removed)
When to use Big - Θ notation: Big - Θ analyzes an algorithm with most precise accuracy since while calculating Big - Θ, a uniform distribution of different type and length of inputs are considered, it provides the average time complexity of an algorithm, which is most precise while analyzing, however in practice sometimes it becomes difficult to find the uniformly distributed set of inputs for an algorithm, in that case, Big-O notation is used which represent the asymptotic upper bound of a function f.