2. Contents
2
Introduction Review of Basic
concepts
What is Data Structure
Basic Data Structures
Data Structures Algorithms
Asymptotic Analysis of Recurrences
The Substitution method
3. Introduction
Data Structure:
Data Structure is a way to store and
organize data so that it can be used efficiently.
Data Structures are used to store and manage data in an
efficient and organised way for faster and easy access and
modification of Data.
3
4. Review of basic concepts
• Variables
• Data types
• Data structures
• Classification of data structure
• Different operations on data structures
• Algorithm
• Why the analysis of algorithms
• Goal of the analysis of algorithms
• What is running time analysis
• How to compare algorithms
• Types of analysis
4
7. Hashing
• Hashing is a technique to convert a range of
key values into a range of indexes of an array.
• Range of key values can be obtained by using
modulo operator
7
8. Hashing Algorithm:
• A hash algorithm is a function that converts a
data string into a numeric string output of fixed
length
• The output string is generally much smaller
than the original data
• Two of the most common hash algorithms are
the MD5 Message-Digest Algorithm5 and the
SHA – 1(Secure Hash Algorithm)
8
9. Hash Table
• Is a data structure used to store keys/value
pairs
• It uses hash function to compute an index into
an array in which an element will be inserted or
searched
• By using a good hash function, hashing can
work well
9
10. Different operations on Data structures
The basic operations that are performed on data structures are as follows:
• Insertion: Insertion means addition of a new data element in a data
structure.
• Deletion: Deletion means removal of a data element from a data
structure if it is found.
Searching: Searching involves searching for the specified data element
in a data structure.
• Traversal: Traversal of a data structure means processing all the data
elements present in it.
10
11. Continue…
Following two are special operations:
• Sorting: Arranging data elements of a data structure in a specified order
is called sorting.
• Merging: Combining elements of two similar data structures to form a
new data structure of the same type, is called merging
11
12. Abstract Data Types (ADTs)
• Before defining abstract data types, let us consider the different view of system-
defined data types. We all know that, by default, all primitive data types (int, float,
etc.) support basic operations such as addition and subtraction. The system provides
the implementations for the primitive data types.
• For user-defined data types we also need to define operations. The implementation
for these operations can be done when we want to actually use them. That means, in
general, user defined data types are defined along with their operations.
• To simplify the process of solving problems, we combine the data structures with
their operations and we call this Abstract Data Types (ADTs). An ADT consists of
two parts:
• 1. Declaration of data
• 2. Declaration of operations
12
13. Continue…
• Commonly used ADTs include: Linked Lists, Stacks, Queues, Priority
Queues, Binary Trees, Dictionaries, Disjoint Sets (Union and Find),
Hash Tables, Graphs, and many others.
• For example, stack uses LIFO (Last-In-First-Out) mechanism while
storing the data in data structures. The last element inserted into the
stack is the first element that gets deleted.
• Common operations of it are: creating the stack, pushing an element
onto the stack, popping an element from stack, finding the current top
of the stack, finding number of elements in the stack, etc.
13
14. Algorithm:
An Algorithm is a sequence of steps to
solve a problem
or
Step by step process to find a solution for
a particular task
14
16. Process of Algorithm:
• How to design Algorithm
• Validation of Algorithm
• Analysis of algorithm
• Algorithm testing
Debugging
Profiling
Psuedo code
16
17. Time Complexity
• Time complexity of an algorithm represents the amount of time
required by the algorithm to run to completion.
• Time requirements can be defined as a numerical function
T(n), where T(n) can be measured as the number of steps,
provided each step consumes constant time
17
18. Space Complexity
• Space Complexity As the name suggests, it
means how much space or memory will the
algorithm take in terms of N, where N is very
large.
18
19. Asymptotic analysis
• Asymptotic analysis is input bound
• i.e., if there's no input to the algorithm, it is concluded to work
in a constant time. Other than the "input" all other factors are
considered constant.
19
20. Asymptotic analysis of an algorithm
• Asymptotic analysis is the process of calculating the running
time of an algorithm in mathematical units to find the “run-time
performance” of a program.
• Analyzing an algorithm helps measures the efficiency of your
program
• The goal is to determine the best case, worst case and
average case time required to execute a given task.
20
22. .
• Usually, the time required by an algorithm falls under three
types −
• Best Case − Minimum time required for program execution.
• Average Case − Average time required for program execution.
• Worst Case − Maximum time required for program execution
22
23. Asymptotic Notations
Following are the commonly used asymptotic notations to calculate the
running time complexity of an algorithm.
• Ο Notation for Upper Bound – The worst case
• Ω Notation for Lower Bound – the best case
• θ Notation – the average case
23
24. Common Asymptotic Notations
constant − Ο(1)
logarithmic − Ο(log n)
linear − Ο(n)
n log n − Ο(n log n)
quadratic − Ο(n
2
)
cubic − Ο(n
3
)
polynomial − n
Ο(1)
exponential − 2
Ο(n)
24
Following is a list of some common asymptotic notations −
25. Big O notation
It’s the upper bound on the complexity of an algorithm.
Hence, it is used to denote the worst behavior of an algorithm.
25
27. Big Omega(Ω):
• Big Omega(Ω): Similar to Big O notation, the Ω notation is
used to define an asymptotic lower bound on the performance
of an algorithm. Hence, this is used for representing the best
case scenarios.
• The omega bound essentially means the minimum amount of
time that our algorithm will take to execute, irrespective of the
input.
27
29. Big theta notation
Big theta notation A tight bound on the behavior
of an algorithm, this notation defines the upper
and lower bounds for a function.
This is called a tight bound because we fix the
running time to within a constant factor above
and below.
29
31. .
• Whenever we compare different algorithms for solving a
particular problem, we don’t just focus on the time
complexities. Space complexity is also an important aspect for
comparing different algorithms. Yes, it’s true that we have a lot
of memory available these days and hence, space is something
which can be compromised on.
• Choosing your algorithm wisely helps to optimize both time
and space.
31
32. The substitution method
• The substitution method for solving recurrence relations
consists of three steps: Guess the form of the solution. Verify by
induction. Solve for constants.
32
33. Iterative algorithm
• An iterative algorithm executes steps in iterations.
• It aims to find successive approximation in sequence to reach
a solution.
• They are most commonly used in linear programs where large
numbers of variables are involved.
• To be continued on the next class…
33