Lecture #03
Lecture #03
ASYMPTOTIC NOTATION
• Understanding how to measure the efficiency of algorithms is crucial
in computer science. Asymptotic Notation in Data Structure helps
describe the running time or space requirements of an algorithm as
the input size grows.
• Let’s learn the basics of asymptotic notation, including Big O, Omega,
and Theta notations. Here, we have provided clear explanations and
practical examples to help you understand how to analyze and
compare the performance of different algorithms effectively.
WHAT IS ASYMPTOTIC NOTATION?
(DEFINITION)
• Asymptotic Notation in Data Structure is a way to describe how the time or
space of an algorithm grows as input size grows. It helps us understand
how efficient an algorithm is when we have very large inputs.
• Imagine you have different ways to solve a problem, like sorting a list of
numbers. Some ways are fast when the list is short, but they might
become very slow when the list is long. Asymptotic notation helps us
compare these methods by focusing on how they perform when the input
size gets really big.
• In simple terms, asymptotic notation helps us predict how an algorithm
will perform and make better choices when writing programs.
TYPES OF ASYMPTOTIC NOTATION
IN DATA STRUCTURE
• 1. Big O Notation (O)
• Big O Notation is used to describe the upper bound of an algorithm's running time. It tells us
the maximum time an algorithm could take to complete, given the size of the input.
• How it Measures the Upper Bound?
• Big O notation focuses on the worst-case scenario. It helps us understand the maximum time
or space an algorithm will require, regardless of the input's specifics.
• Common Examples:
• O(1): Constant time. The algorithm takes the same amount of time regardless of the input
size. Example: Accessing an element in an array.
• O(n): Linear time. The algorithm's running time grows linearly with the input size. Example:
Iterating through a list.
• O(n^2): Quadratic time. The running time grows quadratically as the input size increases.
Example: Bubble sort.
Cont.
• 2. Omega Notation (Ω)
• Omega Notation is used to describe the lower bound of an algorithm's running
time. It tells us the minimum time an algorithm will take to complete, given the
size of the input.
• How it Measures the Lower Bound?
• Omega notation focuses on the best-case scenario. It helps us understand the
least amount of time or space an algorithm will require.
• Common Examples:
• Ω(1): Constant time. The algorithm takes at least a constant amount of time,
regardless of the input size.
• Ω(n): Linear time. The algorithm takes at least linear time as the input size grows.
Cont.
• 3. Theta Notation (Θ)
• Theta Notation is used to describe the exact bound of an algorithm's running time. It
tells us the average-case scenario, where the running time is bound both above and
below by the same function.
• How it Measures the Exact Bound?
• Theta notation focuses on the typical running time of an algorithm. It shows that the
algorithm's running time is both at least and at most a certain function of the input
size.
• Common Examples:
• Θ(1): Constant time. The algorithm takes a constant amount of time, regardless of the
input size.
• Θ(n): Linear time. The algorithm's running time grows linearly with the input size.
LEARNING OUTCOME
CLO_1:
Describe basic ADTs (stack, queue, array, list, node list, priority
queue, tree, map and dictionary) and their related data structure
implementations(array, single linked structure, double linked
structure, heap, hash table, binary search tree, AVL tree).
LB UB
9 8 7 6 5 4 3 2 1 0
In above example index of first element is 0 and that of the last element index is 9. Thus,
Number of elements in the array = UB – LB +1
=9–0+1
= 10
To remove the last element of array (i.e. Bahrain) move to the last element
and then delete it by placing the null value.
To delete India at position 3, the contents of locations 4 and 5 are moved one
step towards the beginning of the array. Thus England will be shifted to
location 3 and Bahrain will be shifted to location 4.
Advantages:
It is used to represent multiple data items of same type by using only single name.
It can be used to implement other data structures like linked lists, stacks, queues, trees,
graphs etc.
2D arrays are used to represent matrices.
Disadvantages:
We must know in advance that how many elements are to be stored in array.
Array is static structure. It means that array is of fixed size. The memory which is allocated to
array can not be increased or reduced.
Since array is of fixed size, if we allocate more memory than requirement then the memory space
will be wasted.
The elements of array are stored in consecutive memory locations. So insertions and deletions are
very difficult and time consuming.
College of Computer Science & Information Systems, Najran Un 24
iversity, KSA
?
?
?
?
QUESTIONS? ?
?
?
?
?