Introduction and Analysis of an Algorithm
Introduction and Analysis of an Algorithm
Examples
• Phone contact list
• Dictionary
• Library bookshelf
Simple real-life examples where data structures are used:
1. Phonebook or Contact List-
Data Structure: Array or Linked List
How it works: Stores names and phone numbers of contacts, allowing for
efficient insertion, deletion, search, and sorting.
2. Music Playlist-
Data Structure: Linked List or Stack-
How it works: Stores songs in a specific order, allowing for efficient addition and
removal of songs, as well as playback in a specific order.
5. Library Bookshelf-
Data Structure: Array or Linked List-
How it works: Stores books in a specific order, allowing for efficient
addition and removal of books, as well as searching for specific books.
2. Fast Data Retrieval: Data structures enable fast retrieval of data, making it
possible to perform operations quickly.
4. Scalability: Data structures can handle large amounts of data, making them
scalable.
5. Improved Performance: Data structures can improve the performance
of algorithms by reducing the time complexity.
Insertion Operations
1. Insert: Add a new element to the data structure.
2. Push: Add a new element to the top of a stack or queue.
3. Enqueue: Add a new element to the end of a queue.
Deletion Operations
1. Delete: Remove a specific element from the data structure.
2. Pop: Remove an element from the top of a stack or queue.
3. Dequeue: Remove an element from the front of a queue.
Modification Operations
1. Update: Modify the value of an existing element in the data structure.
2. Replace: Replace an existing element with a new one.
Miscellaneous Operations
1. Size: Return the number of elements in the data structure.
2. IsEmpty: Check if the data structure is empty.
3. Clear: Remove all elements from the data structure.
Abstract data type
• An abstract data type (ADT) is a high-level description of a data structure that
defines its behaviour and operations, without specifying how it is implemented.
• An ADT is a mathematical model that defines the interface and behaviour of a
data structure, without worrying about the details of how it is stored or
manipulated.
An ADT typically includes:
• A set of values: The ADT defines the type of values it can hold.
• A set of operations: The ADT defines the operations that can be performed
on the values, such as insertion, deletion, search, etc.
• A set of axioms: The ADT defines the rules and constraints that govern the
behaviour of the operations.
Examples
Stack: push and pop operations
Queue: enqueue and dequeue operations
Concreate Data structure Vs Abstract data type
S. No. Abstract Data Types or structure (ADT) Concrete Data Types or structure (CDT)
Abstract Data Types or structures describe the data and Concrete data types or structures provide how these
1
the operations to manipulate and change it. operations are actually implemented.
5 It is usable beyond its original use. It is rarely reusable beyond its original use.
Step - 8
Life Cycle Steps
Step - 4
Develop the
algorithm
Analysis of algorithm
• WHY
• WHAT
• HOW
Needs of Analysis (WHY?)
• Performance comparison to find out efficient solution (algorithm)
• To determine resource consumption
(WHAT?) Time, space, register, cost
✓Drawback
• Will not give real/actual values in unit
• Estimates/ approximates
Components of analytic frame work
• A language( pseudo) for describing algorithm steps
• A computation modal(RAM model) that the algorithm
executes within it
• A matric for measuring algorithm running tie
• An approach/ notation to characterize running time.
algorithm test Step count Methode
{
x y + z;
for i 1 to n
a b + c; Each fundamental operation/
basic operation takes one unit of
for i 1 to n time { RAM model of
{ computation}
for i 1 to n
a b + c;
}
}
Order of magnitude
To determine the time of algorithm
under aproiri analysis
• Order of magnitude of a statement/ step of the algorithm refers to
the frequency/ count of the fundamental operation in the
statement/ step
Polynomial Exponential
Logarithmic
1. Big oh : O 1. Little oh : o
2. Big omega : Ω 2. Little omega : 𝜔
3. Theta : 𝜃
Big O – Notation
• This notation gives an upper bound on the Time
complexity of an algorithm. It is used to describe c g(n)
the worst-case scenario, i.e., the maximum
amount of time or space an algorithm requires.
• It represent upper bound f(n)
C
Sp
Input space + Work space
Additional space
for computation
Input space steps like stack,
linked list etc…
S(P) = C + Sp
Thank You