Introduction To Algorithm & Data Structure
Introduction To Algorithm & Data Structure
Data Structure”
.
ALGORITHMS
ALGORITHM – PROBLEM SOLVING
COMPUTER :
“Computer is multi purpose Electronic Machine which is
used for storing , organizing and processing data by set of
program
Problem :
“Problem is defined as situation or condition which needs
to solve to achive goal”
3. Merging solution
6. Solve by analogy.
INTRODUCTION OF ALGORITHMS
DEFINITION :
“An algorithm is defined as a step-by-step procedure or method for
solving a problem by a computer in a finite number of steps.”
Step 1 − START
Step 6 − print c
ALGORITHM DESIGN TOOL
• There can be two tools :
1. Flowchart
2. Pseudo Code
Flowchart :
“ Flowchart is graphical representation of the algorithms”
Pseudo Code :
“It is simply an implementation of an algorithm in the form of
annotations and informative text written in plain English.
FLOWCHART
Symbol used in Flowchart
:
EXAMPLE OF
FLOWCHART
EXAMPLE FOR ALGORITH & FLOWCHART
Step1: Start
Step2: Initialize the count variable to zero
Step3: Initialize the sum variable to zero
Step4: Read a number say x
Step 5: Add 1 to the number in the count variable
Step6: Add the number x to the sum variable.
Step7: Is the count variable in the memory
greater
50? thanIf yes, display the sum: go to step 8. If
No, Repeat from step 4
Step8: Stop
Design an algorithm and flowchart to
input fifty numbers and calculate their
sum.
WRITE A PROGRAM FOR ADDING 10 NUMBERS
WRITE A PROGRAM TO FIND FACTORIAL OF
NUMBER
DIFFERENT APPROCHES TO DESIGN ALGORITHMS
Types of approach :
1. Top down approach
2. Bottom up approach
TOP DOWN APPROACH BOTTOM UP APPROACH
1. Larger problem divided into smaller Smaller pieces are combined together
2. Execution Start from top to down Execution start from bottom to top
Time complexity :
“The time which is required for analysis of given problem
of particular size is known as time complexity”
Space complexity :
“The amount of computer memory required tp solve the
given problem of particular size is called as space
complexity”
Data :
“Data is nothing but collection of information i.e.
facts or figures.”
“Data :
Data Object object is a of storage that
region
contains a value or group of value”
NEED OF DATA STRUCTURE
1. Stores huge data
6. Better algorithms
ABSTRACT DATA TYPE
ADT :
“Abstract data types are mathematical models of a set of data
values or information that share similar behavior or qualities and that can be
specified and identified independent of specific implementations. Abstract
data types, or ADTs, are typically used in algorithms.”
Another definition of
ADT is ADT is set of D, F
and A.
D – domain = Data
object
F – function = set of operation which cannt carried out on
TYPES OF DATA STRUCTURE
There are two types :
1. Primitives data structure
2. Non-primitive data structure
TYPES OF DATA STRUCTURE
1. Primitives data structure :
“Primitive data structures are those which are predefined way
of storing data by the system. ”
e.g. int, char, float etc
2. Merge sort
3. Recursive algorithm
4. Backtracking algorithms
5. Heuristic algorithms
disks. The objective of the puzzle is to move the entire stack to another
2)Each move consists of taking the upper disk from one of the stacks and
placing it on top of another stack i.e. a disk can only be moved if it is the
Algorithm Steps :
.
GREEDY STRATEGIES
2. Prims algorithm: Prim’s Algorithm also use Greedy approach to find
the minimum spanning tree. In Prim’s Algorithm we grow the spanning
tree from a starting position. Unlike an edge in Kruskal's, we add vertex
to the growing spanning tree in Prim's.
Algorithm Steps:
2.Find all the edges that connect the tree to new vertices, find the
minimum and add it to the tree.
.
Recurrence Relation
Types Recurrence relation :
1. Linear recurrence relations –
Following are some of the examples of recurrence relations based on linear
recurrence relation.
T(n) = T(n-1) + n for n>0 and T(0) = 1
These types of recurrence relations can be easily soled using substitution
method (Put link to substitution method).
For example,
T(n) = T(n-1) + n
= T(n-2) + (n-1) + n
= T(n-k) + (n-(k-1))….. (n-1) + n
Substituting k = n, we get
T(n) = T(0) + 1 + 2+….. +n = n(n+1)/2 = O(n^2)
Recurrence Relation
Types Recurrence relation :
1. Homogeneous linear recurrence relation –
Homogeneous refers to the fact that the total degree of each term is the
same (thus there is no constant term) Constant Coefficients refers to the
fact that c1,c2,...,ck are fixed real numbers that do not depend on n. ...
The recurrence relation An = (1.04)An−1 is a linear homogeneous
recurrence relation of degree one.
.
Type of Recurrence Relation
Generating Functions
Generating Functions represents sequences where each term of a sequence
is expressed as a coefficient of a variable x in a formal power series.
Mathematically, for an infinite sequence, say a0,a1,a2,…,ak,…,a0,a1,a2,…,ak,…, the
generating function will be −
Gx=a0+a1x+a2x2+⋯+akxk+⋯=∑akxk
Some Areas of Application
Generating functions can be used for the following purposes −
-For solving a variety of counting problems. For example, the number of ways to
make change for a Rs. 100 note with the notes of denominations Rs.1, Rs.2, Rs.5,
Rs.10, Rs.20 and Rs.50
- For solving recurrence relations
- For proving some of the combinatorial identities
- For finding asymptotic formulae for terms of sequences
.
THANK
YOU!!!