A heap is a complete binary tree (nodes filled from top
to bottom level and in each level from left to right)
with the following properties:
Structure property:
For any node i, the following formulas apply:
The index of its parent = i / 2
Index of le
Start with unordered array of data
Array representation:
21 15 25 3
5
12 7
19 45 2
9
Binary tree representation:
21
15
25
3
19
5
45
2
12
7
9
Prof. Gayathri. P, SCSE, VIT University
1
Max heap for sorting in ascending order
Min heap for sorting in desce
Polynomial Manipulation
Representation of a Polynomial:
A polynomial is an expression that contains more than two terms.
A term is made up of coefficient and exponent.
An example of polynomial is P(x) = 4x3+6x2+7x+9
A polynomial may be represented usi
Binary tree traversal:
Visiting each node in the tree exactly only once
Types:
Preorder, Inorder, and Postorder
Example:
Preorder traversal:
To traverse a binary tree in Preorder, following operations are carried-out
(i)
Visit the root
(ii)
Traverse the l
Definition of Tree
A tree is a finite set of one or more nodes
such that:
There is a specially designated node called
the root.
The remaining nodes are partitioned into n>=0
disjoint sets T1, ., Tn, where each of these sets is
a tree.
We call T1, ., Tn th
ADT List using Dynamic arrays
A dynamic data structure is one that changes size, as
needed, as items are inserted or removed
Dynamic arrays are arrays that grow (or shrink) as required
Prof. Gayathri. P, SCSE, VIT University
1
Dynamic Array
top = 4
6
1
CSE2003 - DSA
Prof. Gayathri. P, SCOPE, VIT
1
Abstract Data Type (ADT)
ADT = object + operations
An ADT describes an object together with a set of operations
Example: Integer
Operations addition, subtraction, multiplication,
division and modulus
Ther
Construct The Binary Tree from Preorder and
Inorder Sequence
Every binary tree has a unique pair of preorder /
inorder sequences.
Give preorder and inorder sequence as follows.
preorder sequence A B C D E F G H I
Inorder sequence B C A E D G H F I
Use
CSE2003 Data Structures and Algorithms
CSE 2003 DATA STRUCTURES AND
ALGORITHMS
Dr. CHANDRA MOULI P.V.S.S.R.
Dr. CHANDRA MOULI P.V.S.S.R.
CSE 2003 DATA STRUCTURES AND ALGORITHMS
1 / 27
MODULE I
Introduction to DSA
Syllabus
Module-1 Syllabus
Overview and im
#include<iostream>
using namespace std;
#include<conio.h>
int part(int a[],int p,int q);
void quick(int a[],int p,int r)
cfw_
if (p<r)
cfw_
int q=part(a,p,r);
quick(a,p,q-1);
quick(a,q+1,r);
int part(int a[],int s,int w)
cfw_
int x=a[w];
int t;
int i=s-
#include<iostream>
#include<conio.h>
using namespace std;
class queue
cfw_
public:
int q[5];
int rear,front;
queue()
cfw_
rear=-1;
front=-1;
void insert(int x)
cfw_
if(rear>5)
cout<"queue over flow"<endl;
else
q[+rear]=x;
cout<"insreted"<endl;
void dele
#include<iostream>
using namespace std;
#include<conio.h>
class a
cfw_
public:
int dis,pi;
a()
cfw_
dis=99999;
pi=0;
;
int main()
cfw_
int n,dis;
cout<"enter no of nodes :"<endl;
cin>n;
a obj[n];
int mat[n][n];
for(int j=0;j<n;j+)
cfw_
cout<"enter "<j<"
A Practical Introduction to
Data Structures and Algorithm
Analysis
Third Edition (Java Version)
Clifford A. Shaffer
Department of Computer Science
Virginia Tech
Blacksburg, VA 24061
January 19, 2010
c
Copyright 2009-2010
by Clifford A. Shaffer.
This docum
A Practical Introduction to
Data Structures and Algorithm
Analysis
Third Edition (Java Version)
Clifford A. Shaffer
Department of Computer Science
Virginia Tech
Blacksburg, VA 24061
January 19, 2010
c
Copyright 2009-2010
by Clifford A. Shaffer.
This docum
Mastering Algorithms with C
By Kyle Loudon
Publisher: O'Reilly
Pub Date: August 1999
ISBN: 1-56592-453-3
Table of
Pages: 560
Contents
Index
Reviews
Examples
Reader
Reviews
Errata
This book offers robust solutions for everyday programming tasks,
provid
Asymptotic Notations and efficiency
Prof. Ramesh Ragala
Asymptotic Notations
Arrays Where the input size n
become large or tends to infinity, the
complexity of algorithm is complex.
To get the complexity of algorithm in
that case we use conventions like
a
Asymptotic Notations: The program step count in step count is inexact,
because the step count is one for either instruction x=y or x = y+(x*y).
But the running time for latter instruction is high. So this step count is
not very useful comparative purpose
Graph Algorithms
Shortest path problems
[Adapted from K.Wayne]
Graph Algorithms
All-Pairs Shortest Paths
Given graph (directed or undirected) G = (V,E) with
weight function w: E R find for all pairs of vertices
u,v V the minimum possible weight for path f
Reg. No.:
Name:
Sample Question Paper
Term End Examination
Programme
Course
Faculty
Time
:
:
:
:
BTech (CSE)
Data Structures and Algorithms
Jenila Livingston L.M.
3 Hours
Semester
Code
Slot(s)
Max. Marks
:
: CSE220
:
: 100
Answer all the Questions
Q. Sub.
Topological Sort
A topological ordering is possible if
and only if the graph has no
directed cycles, that is, if it is a
directed acyclic graph(DAG).
Greedy Approach
The topological ordering can also be
used to quickly compute
shortest pathsthrough aweigh
Priority Queues
Presentation by,
Dr. Jenila Livingston
1
Priority Queue
A Special form of queue from which items are removed
according to their designated priority and not the order in
which they entered.
Job # 1
Manager
Job # 4
Supervisor
Job # 2
Preside
Binary Trees
Presentation by
Dr. Jenila Livingston L.M.
Intuitive Representation of Tree Node
List Representation
( A ( B ( E ( K, L ), F ), C ( G ), D ( H ( M ), I, J ) ) )
The root comes first, followed by a list of links to sub-trees
Tree of Degree k
D
Graphs
Presentation by
Jenila Livingston
What is a graph?
A data structure that consists of a set of nodes
(vertices) and a set of edges that relate the nodes
to each other
The set of edges describes relationships among the
vertices
Formal definition of
Minimum Spanning Trees
1
Concrete example
Imagine:Youwishtoconnectallthecomputersinan
officebuildingusingtheleastamountofcable
aweightedgraphproblem!
EachvertexinagraphGrepresentsacomputer
Eachedgerepresentstheamountofcableneededto
connectallcomputers
Fin
Data Structures and Algorithms
CSE220
Prof. Ramesh Ragala
July 29, 2015
Prof. Ramesh Ragala
Data Structures and Algorithms CSE220
July 29, 2015
1 / 14
Asymptotic Notations
The step count for estimating Time Complexity is inexact.
Reason: The step count is
Proceedings of the 26th Academic Council held on 18.5.2012
CSE220DATASTRUCTURESANDALGORITHMS
VersionNo.
Course
Prerequisites
Computer Programming
Mathematical Structures.
and
Problem
Solving
L T P C
3 1 2 5
and
Discrete
Objectives
1. To understand various
Directed Depth First Search
A
Adjacency Lists
C
D
F
E
G
A:
B:
C:
D:
E:
F:
G:
H:
I:
F G
A H
A D
C F
C D G
E:
:
B:
H:
1
Directed Depth First Search
A
C
G
D
F
E
dfs(A)
A-F A-G
Function call
2
Directed Depth First Search
A
C
G
D
F
E
visit(F)
F-E
dfs(A)
A-F A-
Data Structures and Algorithms
CSE220
Prof. Ramesh Ragala
July 22, 2015
Prof. Ramesh Ragala
Data Structures and Algorithms CSE220
July 22, 2015
1 / 31
Algorithm Examples
Algorithm for summation of N numbers
Algorithm Sum(a,n)
1: cfw_
2: sum 0;
3: for i 1