Tree Data Structure, Binary Tree - Data Stuctures - Lecture Slides, Slides of Data Structures and Algorithms

Tree Data Structures, Binary Tree, Code for Simulation, Priority Queue, Recursive definition, Not a Tree, Binary Tree Terminology, Level of a Binary Tree Node, Complete Binary Tree are some of data structures topics and terms you will learn in these lecture slides.

Typology: Slides

2011/2012

Uploaded on 11/03/2012

ekna
ekna 🇮🇳

4.2

(5)

75 documents

1 / 26

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Code for Simulation
// print the final avaerage wait time.
double avgWait = (totalTime*1.0)/count;
cout << "Total time: " << totalTime << endl;
cout << “Customer: " << count << endl;
cout << "Average wait: " << avgWait << endl;
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a

Partial preview of the text

Download Tree Data Structure, Binary Tree - Data Stuctures - Lecture Slides and more Slides Data Structures and Algorithms in PDF only on Docsity!

Code for Simulation

// print the final avaerage wait time. double avgWait = (totalTime1.0)/count; cout << "Total time: " << totalTime << endl; cout << “Customer: " << count << endl; cout << "Average wait: " << avgWait << endl;*

Priority Queue

#include "Event.cpp" #define PQMAX 30 class PriorityQueue { public: PriorityQueue() { size = 0; rear = -1; }; ~PriorityQueue() {}; int full(void) { return ( size == PQMAX )? 1 : 0; };

Priority Queue

int insert(Event e) { if( !full() ) { rear = rear+1; nodes[rear] = e; size = size + 1; sortElements(); // in ascending order return 1; } cout << "insert queue is full." << endl; return 0; }; int length() { return size; }; };*

Tree Data Structures

• There are a number of applications where

linear data structures are not appropriate.

• Consider a genealogy tree of a family.

Mohammad Aslam Khan Sohail Aslam Javed Aslam Yasmeen Aslam Haaris Saad Qasim Asim Fahd Ahmad Sara Omer

Binary Tree

• A binary tree is a finite set of elements that is

either empty or is partitioned into three disjoint

subsets.

• The first subset contains a single element called

the root of the tree.

• The other two subsets are themselves binary

trees called the left and right subtrees.

• Each element of a binary tree is called a node of

the tree.

Binary Tree

• Binary tree with 9 nodes.

A

B

D

H

C

E

F

G

I

Binary Tree

• Recursive definition

A

B

D

H

C

E

F

G

Left subtree I root Right subtree

Binary Tree

• Recursive definition

A

B

D

H

C

E

F

G

I

Left subtree root

Binary Tree

• Recursive definition

A

B

D

H

C

E

F

G

I

root Right subtree

Binary Tree

• Recursive definition

A

B

D

H

C

E

F

G

I

root Right subtree Left subtree

Not a Tree

• Structures that are not trees.

A

B

D

H

C

E

F

G

I

Not a Tree

• Structures that are not trees.

A

B

D

H

C

E

F

G

I

Binary Tree

• If every non-leaf node in a binary tree has non-

empty left and right subtrees, the tree is termed

a strictly binary tree.

A

B

D

H

C

E

F

G

I

J

K

Level of a Binary Tree Node

• The level of a node in a binary tree is

defined as follows:

 Root has level 0,

 Level of any other node is one more than the

level its parent (father).

• The depth of a binary tree is the maximum

level of any leaf in the tree.