Dsa Anwer Bank
Dsa Anwer Bank
1. Big-O Notation
We define an algorithm’s worst-case time complexity by using the Big-O notation,
which determines the set of functions grows slower than or at the same rate as the
expression. Furthermore, it explains the maximum amount of time an algorithm
requires to consider all input values.
2. Omega Notation
It defines the best case of an algorithm’s time complexity, the Omega notation
defines whether the set of functions will grow faster or at the same rate as the
expression. Furthermore, it explains the minimum amount of time an algorithm
requires to consider all input values.
3. Theta Notation
It defines the average case of an algorithm’s time complexity, the Theta notation
defines when the set of functions lies in
both O(expression) and Omega(expression), then Theta notation is used. This is
how we define a time complexity average case for an algorithm.
Measurement of Complexity of an Algorithm
Based on the above three notations of Time Complexity there are three cases to
analyze an algorithm:
1. Worst Case Analysis (Mostly used)
In the worst-case analysis, we calculate the upper bound on the running time of an
algorithm. We must know the case that causes a maximum number of operations to
be executed. For Linear Search, the worst case happens when the element to be
searched (x) is not present in the array. When x is not present, the search() function
compares it with all the elements of arr[] one by one. Therefore, the worst-case time
complexity of the linear search would be O(n).
2. Best Case Analysis (Very Rarely used)
In the best-case analysis, we calculate the lower bound on the running time of an
algorithm. We must know the case that causes a minimum number of operations to
be executed. In the linear search problem, the best case occurs when x is present at
the first location. The number of operations in the best case is constant (not
dependent on n). So time complexity in the best case would be Ω(1)
3. Average Case Analysis (Rarely used)
In average case analysis, we take all possible inputs and calculate the computing
time for all of the inputs. Sum all the calculated values and divide the sum by the
total number of inputs. We must know (or predict) the distribution of cases. For the
linear search problem, let us assume that all cases are uniformly
distributed (including the case of x not being present in the array). So we sum all the
cases and divide the sum by (n+1). Following is the value of average-case time
complexity.
Its examples are: array, stack, queue, While its examples are: trees and
6.
linked list, etc. graphs.
The insertion and deletion operations are Insertion and deletion are not
fixed i.e, done at the rear and front end fixed and it can be done in
2. respectively. any position.
In a circular queue, we
In a linear queue, we can easily fetch out the
cannot fetch out the peek
peek value.
6. value easily.
Application- Computer-
Application- People standing for the bus. controlled traffic signal
Cars lined on a bridge. In CPU scheduling and
memory management.
7.
10. Can lead to overflow if the rear reaches the Rear wraps around to the
end of the array. beginning of the array,
S.no. Linear Queue Circular Queue
preventing overflow.