AVLTrees
Balanced binary tree
The disadvantage of a binary search tree is
that its height can be as large as N1
This means that the time needed to perform
insertion and deletion and many other
operations can be O(N) in the worst case
We want a tree with
MultiWay Search Trees
(B Trees)
Multiway Search Trees
An mway search tree is a tree in which, for
some integer m called the order of the tree,
each node has at most m children.
If n <= m is the number of children of a node,
then it contains exactly n1
B+ Tree
What is a B+ Tree
A B+ tree is a balanced tree in which every path from
the root of the tree to a leaf is of the same length.
Each nonleaf node of the tree has between [n/2] and
[n] children, where n is fixed for a particular tree.
It contains in
StackQueues
Lecture 4
Different kinds of list
Commonly used variation of lists are:
Stack
Queue
Dequeue
Stack
A stack is a data structure that works like a
stack of items, such as pile of plates in
cafeteria.
Items can be placed onto top of the stack
Data Structure
Lecture 3
Data Structure
Formally define Data structure as:
DS describes not only set of objects but the
ways
they are related,
the set of operations which may be applied to the
elements of data object.
Example: INTEGER data structure con
Graph  1
Acknowledgement:
Material taken from Fundamentals of Data
Structures in C, Ellis Horowitz and Sartaj Sahni
1
Definition
A graph, G=(V, E), consists of two sets:
a finite set of vertices(V), and
a finite, set of edges(E), may possibly be empty
Graph  2
Minimum Spanning Trees
1
Some Graph Operations
Traversal
Given G=(V,E) and vertex v, find all wV,
such that w connects v.
Depth First Search (DFS)
preorder tree traversal
Breadth First Search (BFS)
level order tree traversal
Connected Componen
Balanced Binary Trees
RedBlack Trees
RedBlack Trees
What are they?
A redblack tree is a data structure which is a
type of selfbalancing binary search tree.
Their relation to 24 trees (Btrees of
order 4)
24 trees are search Trees (but not binary
se
Priority Queues
What is a PRIORITY QUEUE?
2
Queue that gives access ONLY to the MINIMUM item
Items ARRIVE in ANY order
Items EXIT in MINIMUM order
Priority Queue as an Abstract Data Structure
Priority queue
A priority queue is leastfirstout
The smalles
1
What is C+ ?
C+ is a Object oriented programming
language. Initially named as C with
classes.
C+ was developed at AT & T Bell
Labs.
C+ is superset of C.
Three important facilities are added
onto C.
Classes
Functions overloading
Operator overloading
Graph  3
ShortestPath Problems
ShortestPath problems
Singlesource (singledestination). Find a shortest
path from a given source (vertex s) to each of the
vertices.
Singlepair. Given two vertices, find a shortest path
between them. Solution to sing
1
Brief Notes on C
Structure of C program
Include files
#include <stdio.h>
/for input/output functions
Define Constant
#define const_name value
main program
main()
cfw_ /* each declarations and
statements are separated by
semi colon */
/ declarations
vari
1
Inheritance : Extending classes
C+ strongly supports the concept of
reusability.
C+ classes can be reused by creating
new classes and reusing the properties of
existing classes.
New class can be derived from an old
class. It is called inheritance.
O
1
Features of OOP
Emphasis on data rather than
procedure.
Programs are divided into objects.
Data structures are designed such
that they characterize the objects.
Functions that operate on the data of
an object are tied together in the data
structure.
Trie Structure
Tries Lexicographical Search
Tree
Name comes from middle letters of
word retrieval, rhymes with pie
Represents strings of any type such as
characters
Each path from root to a leaf is one
word
To avoid confusion, can use endmarker
symbol $
P
Threaded Binary Tree
Threaded Binary Trees
Two many null pointers (n+1) in current
representation of binary trees
n: number of nodes
number of nonnull links: n1
total links: 2n
null links: 2n(n1)=n+1
Replace these null pointers with some useful
thread
Performance evaluation
LectureModule2
What is a Good Algorithm?
Efficient:
Running time
Space used
Efficiency as a function of input size:
The number of bits in an input number
Number of data elements (numbers, points)
Measuring the Running Time
How shou
Introduction  Data structure
LectureModule1
Data Structure
Data structures in computer science deal with
the problem of structuring or
organizing data in computer so that it can be used
efficiently and processed by algorithms.
To a certain extent, dat
15.082 and 6.855J
The Shortest Augmenting Path
Algorithm for the Maximum Flow
Problem
Shortest Augmenting Path
4
2
3
s
5
1
1
2
3
4
1
1
4
2
t
3
This is the original network,
and the original residual
network.
3
Initialize Distances
2
5
3
4
3
s
2
2
2 s
1
3
15.082J and 6.855J
March 4, 2003
Introduction to Maximum Flows
The Max Flow Problem
G
xij =
=
(N,A)
flow on arc (i,j)
uij
=
capacity of flow in arc (i,j)
s
t
=
=
source node
sink node
Maximize
v
Subject to
j xij
j xsj
=

k xki=
0 for each i s,t
v
0 xi
(2,4) Trees
What are they?
They are search Trees (but not binary search trees)
They are also known as 24, 234 trees
Multiway Search Trees
Each internal node of a multiway search tree T:
has at least two children
stores a collection of items of the
A simple example
finding the maximum of a set S of n numbers
Time complexity
Time complexity:
T(n)=
Calculation of T(n):
Assume n = 2k,
T(n) = 2T(n/2)+1
= 2(2T(n/4)+1)+1
= 4T(n/4)+2+1
:
=2k1T(2)+2k2+4+2+1
=2k1+2k2+4+2+1
=2k1 = n1
2T(n/2)+1 , n>2
AVL Trees
AVL Trees
1
Insertion
Inserting a node, v, into an AVL tree changes the
heights of some of the nodes in T.
The only nodes whose heights can increase are
the ancestors of node v.
If insertion causes T to become unbalanced, then
some ancestor of