Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
CSE 326: Data Structures
Binary Search Trees
y
Today s
Todays Outline
Dictionary ADT / Search ADT
Q i k Tree Review
Quick T
R i
Binary Search Trees
ADTs Seen So Far
Stack
Push
Pop
Queue
Enqueue
Dequeue
Priority Queue
Insert
DeleteMin
Then ther
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
BTrees
V. Balasubramanian
AP/CSE
SSNCE
BTrees
Although all of the search trees we have seen so far are
binary, there is a popular search tree that is not binary.
This tree is known as a Btree.
A Btree of order m is a tree with the following structural
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
AVL Trees
V. Balasubramanian
AP/CSE
SSNCE
Binary Search Tree
Arrange keys in a binary tree with the binary search
tree property:
K
<K
Example: 5, 3, 1, 10, 12, 7, 9
>K
Dictionary Operations on Binary Search Trees
Searching straightforward
Insertion search
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
Binary Search Tree
V. Balasubramanian
Example
BST structure
typedef struct tree_node *tree_ptr;
struct tree_node
cfw_
element_type element;
tree_ptr left;
tree_ptr right;
;
typedef tree_ptr SEARCH_TREE;
Make NULL
This operation is mainly for initializati
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
Data Structures
V. Balasubramanian
AP/CSE
SSNCE
Introduction
The study has 2 objectives: 1. to identify and create useful
mathematical entity and operations and to determine what class of
problems can be solved.
2. to determine the representation of these
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
Chapter 24
The Disjoint Set Class
Lets revisit Minimum Spanning Trees
A spanning tree of an undirected graph is a tree formed by graph edges that connect all
the vertices of the graph.
A minimum spanning tree is a connected subgraph of G that spans all ve
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
Path Compression
V. Balasubramanian
AP/CSE
SSNCE
Path Compression
The union/find algorithm, as described so far, is quite
acceptable for most cases. It is very simple and linear on
average for a sequence of m instructions (under all models).
However, the
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
Algorithms for Minimum
Spanning Tree Generation
1
Problem: Laying Telephone Wire
Central office
2
Wiring: Nave Approach
Central office
Expensive!
3
Wiring: Better Approach
Central office
Minimize the total length of wire connecting the customers
4
Minimum
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
CS2201 Data Structures
 An introduction
 Mrs. R. Kanchana
[email protected]
r
Course Outline
Linked lists
Stacks and Queues
Trees
Binary trees
Binary Search trees
AVL trees
Splay Trees
B Trees
Binary heaps
Sets
Hash table
Graphs
Applications
29Jun1
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
Threaded Binary Trees
Threaded Binary Trees
Given a binary tree with n nodes,
the total number of links in the tree is 2n.
Each node (except the root) has exactly one incoming arc
only n  1 links point to nodes
remaining n + 1 links are null.
One can use
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
Trees
Contents
General Trees
Binary Trees
16Jul10
2
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, ., T
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
Array Implementation of ListADT
List ADT
List is a term used to refer to a linear collection of data
items.
A general list of the form a1,a2, an. The size of the list is
N.
Special list of size 0 empty list.
In the list ai+1 follows ai and that ai1preced
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
Data Structures
V. Balasubramanian
AP/CSE
SSNCE
Stack applications
a
a
a
a
a
a
Balancing symbols
Evaluating arithmetic expressions
Towers of Hanoi
Function Calls
8 Queens Problem
Reversing the string
Reversing a list
a
a
a
a
a
a
a
Head , push a
top> a
Pu
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
ThreadedBinaryTree
Threaded Binary Tree
V.Balasubramanian
ThreadedBinaryTree
Threaded Binary Tree
Lemma3.2impliesthatabinarytreewithn
e
a 3.
p es t at a b a y t ee t
nodeshasn+1nulllinks.Thesenulllinkscanbe
replacedbypointerstonodescalledthreads.
Threads
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
Pseudocode: An Introduction
Flowcharts were the first design tool to be widely used, but unfortunately they do not
very well reflect some of the concepts of structured programming. Pseudocode, on the
other hand, is a newer tool and has features that make
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
SSN College of Engineering, Kalavakkam
Department of Computer Science and Engineering
29.07.2011
BE (CSE) III, V, and VII semester JulNov 2011
Schedule for UNIT TESTS
Time : 08.00 a.m. to 09.30 a.m.
Sl.
No.
Sem
Subject Code & Name
Unit
Test I
Unit
Test I
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
SSN COLLEGE OF ENGINEERING
SSN NAGAR 603 110
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING
LESSION PLAN
CS141301 DATA STRUCTURES
CS 141301
DATA STRUCTURES
3 1 0 4
Aim: To master the design and applications of linear, tree, balanced tree, hashing, set,
an
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
B Trees
Dictionary for Secondary storage
The AVL tree is an excellent dictionary structure
when the entire structure can fit into the main
memory.
following or updating a pointer only requires a memory cycle.
When the size of the data becomes so large
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
Splay Trees
Splay Trees
Splay trees are binary search trees (BSTs) that:
Are not perfectly balanced all the time
Allow search and insertion operations to try to balance the
tree so that future operations may run faster
Based on the heuristic:
If X is a
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
Graph Traversal
Algorithms
1
Graph Traversal
Problem: Search for a certain node or
traverse all nodes in the graph
Depth First Search
Once a possible path is found, continue the search
until the end of the path
Breadth First Search
Start several path
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
26
Applications of Set
Used for implementing Kruskal's algorithm to find the
minimum spanning tree of a graph.
Find connected components on an undirected graph.
For classifying a set of atoms into molecules or fragments
Maze generation
27
Applications
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
1
Central office
2
Central office
Expensive!
3
!
Central office
Minimize the total length of wire connecting the customers
4
"
#
(see Weiss, Section 24.2.2)
A minimum spanning tree is a subgraph of an
undirected weighted graph G, such that
" $
$%
#
V
V
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
Minimum Spanning Trees
Examples
Definition
A Minimum Spanning Tree (MST) is a
subgraph of an undirected graph such that
the subgraph spans (includes) all nodes, is
connected, is acyclic, and has minimum
total edge weight
Algorithm Characteristics
Both Pri
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
Shortest path
Algorithms
Unweighted shortest paths
2. Weighted shortest paths
 Dijkstras Algorithm
1.
Shortest path Algorithms
Shortest path algorithms are considered with two
different ways. They are:
(i) Single source shortest path problem :
Given as i
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
Heaps and Heapsort
Heaps and Heapsort
Definition A heap is a binary tree with keys at its nodes (one
key per node) such that:
It is essentially complete, i.e., all its levels are full except
possibly the last level, where only some rightmost keys may
be m
Anna University Chennai  Regional Office, Coimbatore
data structures
CS 141301

Fall 2011
Hashing
Introduction
We have discussed the search tree ADT, which allowed
various operations on a set of elements.
Hash table ADT it supports only a subset of the
operations allowed by binary search trees.
The implementation of hash tables is frequently c