0% found this document useful (0 votes)
14 views12 pages

Dsa Anwer Bank

The document discusses different types of complexity analysis notations used to analyze algorithms including Big-O, Omega, and Theta notations. It explains what each notation defines such as worst case, best case, and average case time complexities. The document also discusses which type of analysis is generally used and the benefits of worst case analysis.

Uploaded by

rajoni8225
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views12 pages

Dsa Anwer Bank

The document discusses different types of complexity analysis notations used to analyze algorithms including Big-O, Omega, and Theta notations. It explains what each notation defines such as worst case, best case, and average case time complexities. The document also discusses which type of analysis is generally used and the benefits of worst case analysis.

Uploaded by

rajoni8225
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Popular Notations in Complexity Analysis of Algorithms

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.

Which Complexity analysis is generally used?


Below is the ranked mention of complexity analysis notation based on popularity:
1. Worst Case Analysis:
Most of the time, we do worst-case analyses to analyze algorithms. In the worst
analysis, we guarantee an upper bound on the running time of an algorithm which is
good information.
2. Average Case Analysis
The average case analysis is not easy to do in most practical cases and it is rarely
done. In the average case analysis, we must know (or predict) the mathematical
distribution of all possible inputs.
3. Best Case Analysis
The Best Case analysis is bogus. Guaranteeing a lower bound on an algorithm
doesn’t provide any information as in the worst case, an algorithm may take years to
run.
What is Data Structure?
⮚ A data structure is a storage that is used to store and organize data. It
is a way of arranging data on a computer so that it can be accessed and
updated efficiently.
⮚ A data structure is not only used for organizing the data. It is also used
for processing, retrieving, and storing data.
⮚ The data structure is not any programming language like C, C++, java,
etc. It is a set of algorithms that we can use in any programming language to
structure the data in the memory.
Full array in Unit-2 pdf
(implement One Reverse order array)

Full stack in Unit-2 pdf


an algorithm of PUSH, PEEP, DISPLAY and POP Method.
There are two types of data structures:

1.Primitive data structure

2.Non-primitive data structure

S.NO Linear Data Structure Non-linear Data Structure

In a linear data structure, data


elements are arranged in a linear In a non-linear data structure, data
1. order where each and every element elements are attached in
is attached to its previous and next hierarchically manner.
adjacent.

In linear data structure, single level Whereas in non-linear data structure,


2.
is involved. multiple levels are involved.

Its implementation is easy in While its implementation is complex


3. comparison to non-linear data in comparison to linear data
structure. structure.

While in non-linear data structure,


In linear data structure, data elements
4. data elements can’t be traversed in a
can be traversed in a single run only.
single run only.

5. In a linear data structure, memory is While in a non-linear data structure,


S.NO Linear Data Structure Non-linear Data Structure

memory is utilized in an efficient


not utilized in an efficient way. way.

Its examples are: array, stack, queue, While its examples are: trees and
6.
linked list, etc. graphs.

Applications of linear data structures Applications of non-linear data


7. are mainly in application software structures are in Artificial
development. Intelligence and image processing.

Non-linear data structures are useful


Linear data structures are useful for for representing complex
8. simple data storage and relationships and data hierarchies,
manipulation. such as in social networks, file
systems, or computer networks.

Performance is usually good for


Performance can vary depending on
simple operations like adding or
the structure and the operation, but
9. removing at the ends, but slower for
can be optimized for specific
operations like searching or
operations.
removing elements in the middle.
S.no. Linear Queue Circular Queue

1. Arranges the data in a linear pattern. Arranges the data in a


S.no. Linear Queue Circular Queue

circular order where the rear


end is connected with the
front end.

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.

It requires less memory


Linear queue requires more memory space.
3. space.

In the case of a linear queue, the element


In the case of circular queue,
added in the first position is going to be
the order of operations
deleted in the first position. The order of
performed on an element
operations performed on any element is fixed
may change.
4. i.e, FIFO.

It is inefficient in comparison to a circular It is more efficient in


5. queue. comparison to linear queue.

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.

If there are 10 spaces then in


If there are 10 spaces then in the best case all
the best case 9 spaces can be
the 10 spaces in the queue can be filled
8. filled at a time

Good for applications where


Good for applications where overflow is not
efficient use of memory is
a concern.
9. important.

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.

Suitable for real-time


Not suitable for real-time systems where
systems where continuous
overflow can lead to data loss.
11. data insertion is required.

Need Of Data Structure:


The structure of the data and the synthesis of the algorithm are relative to each other.
Data presentation must be easy to understand so the developer, as well as the user,
can make an efficient implementation of the operation.
Data structures provide an easy way of organising, retrieving, managing, and storing
data.
Here is a list of the needs for data.
 Data structure modification is easy.
 It requires less time.
 Save storage memory space.
 Data representation is easy.
 Easy access to the large database

You might also like