SlideShare a Scribd company logo
1 of 10
[object Object],[object Object],[object Object],[object Object],[object Object],A C D E F B Left Sub Tree Right Sub Tree Binary Tree --  A Tree is said to be a binary tree that every element in a binary tree has at the most two sub trees. ( means zero or one or two ) Types of binary trees -- Strictly binary tree -- Complete binary tree -- Extended binary tree ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Root
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],A B C D E Tree structure using  Doubly Linked List   /* a node in the tree structure */ struct node { struct node *lchild; int data ; struct node *rchild; }; -- The pointer lchild stores the address of left child node. -- The pointer rchild stores the address of right child node. -- if child is not available NULL is strored. -- a pointer variable root represents the root of the tree. Root A B - C - - - D E - -
struct node { struct node *lchild; char data; struct node *rchild; } *root=NULL; struct node *insert(char a[],int index) { struct node *temp=NULL; if(a[index]!='')  { temp = (struct node *)malloc( sizeof(struct node)); temp->lchild = insert(a,2*index+1); temp->data = a[index]; temp->rchild = insert(a,2*index+2); } return temp; } void buildtree(char a[])  { root = insert(a,0); } void inorder(struct node *r){ if(r!=NULL) { inorder(r->lchild); printf("%5c",r->data); inorder(r->rchild); } } void preorder(struct node *r){ if(r!=NULL) { printf("%5c",r->data);  preorder(r->lchild); preorder(r->rchild); } }   void postorder(struct node *r){ if(r!=NULL) { postorder(r->lchild); postorder(r->rchild); printf("%5c",r->data); } } void main() { char arr[] = { 'A','B','C','D','E','F','G','','','H','', '','','','','','','','','',''}; buildtree(arr);  printf("Pre-order Traversal : "); preorder(root); printf("In-order Traversal : "); inorder(root);  printf("In-order Traversal : "); inorder(root); }  Implementing Binary Tree Output :  Preorder Traversal : A B D E H C F G Inorder Traversal : D B H E A F C G Postorder Traversal : D H E B F G C A A B C D E F G H Tree Created :
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Binary Search Tree ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
struct node { struct node *lchild; int data; struct node *rchild; }; struct node *fnode=NULL,*parent=NULL; void insert(struct node **p, int n) { if(*p==NULL)  { *p=(struct node *)malloc(sizeof(struct node)); (*p)->lchild=NULL; (*p)->data = n; (*p)->rchild=NULL; return; } if(n < (*p)->data)  insert(&((*p)->lchild),n); else insert(&((*p)->rchild),n); } void inorder(struct node *t) { if(t!=NULL)  { inorder(t->lchild); printf(&quot;%5d&quot;,t->data); inorder(t->rchild); } } void preorder(struct node *t)  { if(t!=NULL)  { printf(&quot;%5d&quot;,t->data); Implementing Binary Search Tree preorder(t->lchild);  preorder(t->rchild); } } void postorder(struct node *t)  { if(t!=NULL)  { postorder(t->lchild);  postorder(t->rchild); printf(&quot;%5d&quot;,t->data); } } void search(struct node *r,int key){ struct node *q; ,  fnode=NULL;  q=r; while(q!=NULL)  { if(q->data == key) { fnode = q; return; } parent=q; if(q->data > key) q=q->lchild; else  q=q->rchild; }   } void delnode ( struct node **r,int key)  { struct node *succ,*fnode,*parent; if(*r==NULL)  { printf(&quot;Tree is empty&quot;); return; } parent=fnode=NULL;
search(*r,key); if(fnode==NULL) { printf(&quot;Node does not exist, no deletion&quot;); return; } if(fnode->lchild==NULL && fnode->rchild==NULL) { if(parent->lchild==fnode) parent->lchild=NULL; else parent->rchild=NULL; free(fnode); return; } if(fnode->lchild==NULL && fnode->rchild!=NULL) { if(parent->lchild==fnode) parent->lchild=fnode->rchild; else parent->rchild=fnode->rchild; free(fnode); return; } if(fnode->lchild!=NULL && fnode->rchild==NULL) { if(parent->lchild==fnode) parent->lchild=fnode->lchild; else parent->rchild=fnode->lchild; free(fnode); return; } Implementing Binary Search Tree ( continued ) if(fnode->lchild!=NULL && fnode->rchild!=NULL)  { parent = fnode; succ = fnode->lchild; while(succ->rchild!=NULL){ parent=succ; succ = succ->rchild; } fnode->data = succ->data; free(succ); succ=NULL; parent->rchild = NULL; } } void inorder(struct node *t)  { if(t!=NULL)  { inorder(t->lchild); printf(&quot;%5d&quot;,t->data); inorder(t->rchild); } } void preorder(struct node *t)  { if(t!=NULL)  { printf(&quot;%5d&quot;,t->data); preorder(t->lchild);  preorder(t->rchild); } }
void postorder(struct node *t) { if(t!=NULL)  { postorder(t->lchild);  postorder(t->rchild); printf(&quot;%5d&quot;,t->data); } } int main()  { struct node *root=NULL; int n,i,num,key; printf(&quot;Enter no of nodes in the tree : &quot;); scanf(&quot;%d&quot;,&n); for(i=0;i<n;i++)  { printf(&quot;Enter the element : &quot;); scanf(&quot;%d&quot;,&num); insert(&root,num); } printf(&quot;Preorder traversal :&quot;); preorder(root); printf(&quot;Inorder traversal :&quot;); inorder(root); printf(&quot;Postorder traversal :&quot;); postorder(root); printf(&quot;Enter the key of node to be searched : &quot;); scanf(&quot;%d&quot;,&key); search(root,key); if(fnode==NULL) printf(&quot;Node does not exist&quot;); else  printf(&quot;NOde exists&quot;); Implementing Binary Search Tree ( continued ) printf(&quot;Enter the key of node to be deleted : &quot;); scanf(&quot;%d&quot;,&key); delnode(&root,key); printf(&quot;Inorder traversal after deletion :&quot;); inorder(root); } Output : Enter no of nodes in the tree : 5 Enter the element : 18 Enter the element : 13 Enter the element : 8 Enter the element : 21 Enter the element : 20 Preorder traversal : 18  13  8  21  20 Inorder traversal : 8  13  18  20  21 Postorder traversal : 8  13  20  21  18 Enter the key of node to be searched : 13 Node exists Enter the key of node to be deleted : 20 Inorder traversal after deletion : 8  13  18  21
Arithmetic Expression Tree ,[object Object],[object Object],[object Object],[object Object],[object Object],Example: E xpression Tree for (2 * (a βˆ’ 1) + (3 * b)) + * * 2 - 3 b a 1 In-Order Traversal of Expression Tree Results In-fix Expression. 2 * ( a – 1 ) + ( 3 * b ) Post-Order Traversal of Expression Tree Results Post-fix Expression. 2 a 1 – *  3 b *  + To convert In-fix Expression to Post-fix expression, First construct an expression tree using infix expression and then do tree traversal in post order.
Graphs A Tree is in fact a special type of graph. Graph is a data structure having a group of nodes connecting with cyclic paths. A Graph contains two finite sets, one is set of nodes is called vertices and other is set of edges. A Graph is defined as G = ( V, E ) where. i) V is set of elements called nodes or vertices. ii) E is set of edges, identified with a unique pair ( v1, v2 ) of nodes. Here ( v1, v2 ) pair denotes that there is an edge from node v1 to node v2. A B C D E Set of vertices = { A, B, C, D, E } Set of edges = { ( A, B ) , ( A, C ) , ( B, D ),    ( C, D ),( C, E ) , ( D, E ) }  A graph in which every edge is undirected is known as Un directed graph. The set of edges are unordered pairs. Edge ( A, B ) and ( B, A ) are treated as same edge. A C D E Un-directed Graph Directed Graph Set of vertices = { A, B, C, D, E } Set of edges = { ( A, B ) , ( A, C ) , ( B, B ), ( B, D ), ( C, A ), ( C, D ), ( C, E ) , ( E, D ) }  A graph in which every edge is directed is known as Directed graph. The set of edges are ordered pairs. Edge ( A, B ) and ( B, A ) are treated as different edges. The edge connected to same vertex ( B, B ) is called loop. Out degree  : no of edges originating at a given node. In degree  : no of edges terminating at a given node. For node C - In degree is 1 and out degree is 3 and  total degree is 4. B
Representation of Graph A B C D E ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Adjacency Matrix A  B  C  D  E  A  0  1  1  1  0 B  1  0  1  1  0 C  1  1  0  1  1 D  1  1  1  0  1 E  0  0  1  1  0 Adjacency Matrix is a bit matrix which  contains entries of only 0 and 1  The connected edge between to vertices is  represented by 1 and absence of edge is  represented by 0. Adjacency matrix of an undirected graph is  symmetric. Linked List A B C D N E B C D NULL A B E NULL D A C D NULL A B E NULL C C D NULL

More Related Content

What's hot

Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree TraversalDhrumil Panchal
Β 
Tree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanTree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanDaniyal Khan
Β 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeManishPrajapati78
Β 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniquesSyed Zaid Irshad
Β 
Data structure tree- advance
Data structure tree- advanceData structure tree- advance
Data structure tree- advanceMD. MARUFUZZAMAN .
Β 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURESbca2010
Β 
Binary tree and Binary search tree
Binary tree and Binary search treeBinary tree and Binary search tree
Binary tree and Binary search treeMayeesha Samiha
Β 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search treeKrish_ver2
Β 
non linear data structure -introduction of tree
non linear data structure -introduction of treenon linear data structure -introduction of tree
non linear data structure -introduction of treeSiddhi Viradiya
Β 
Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++Himanshu Choudhary
Β 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search TreeZafar Ayub
Β 
Binary Search Tree and AVL
Binary Search Tree and AVLBinary Search Tree and AVL
Binary Search Tree and AVLKatang Isip
Β 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)Trupti Agrawal
Β 
binary search tree
binary search treebinary search tree
binary search treeShankar Bishnoi
Β 

What's hot (20)

Binary Tree Traversal
Binary Tree TraversalBinary Tree Traversal
Binary Tree Traversal
Β 
Tree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal KhanTree Data Structure by Daniyal Khan
Tree Data Structure by Daniyal Khan
Β 
Data Structure (Tree)
Data Structure (Tree)Data Structure (Tree)
Data Structure (Tree)
Β 
Data Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary TreeData Structure and Algorithms Binary Tree
Data Structure and Algorithms Binary Tree
Β 
Tree traversal techniques
Tree traversal techniquesTree traversal techniques
Tree traversal techniques
Β 
Data structure tree- advance
Data structure tree- advanceData structure tree- advance
Data structure tree- advance
Β 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
Β 
Binary tree and Binary search tree
Binary tree and Binary search treeBinary tree and Binary search tree
Binary tree and Binary search tree
Β 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
Β 
non linear data structure -introduction of tree
non linear data structure -introduction of treenon linear data structure -introduction of tree
non linear data structure -introduction of tree
Β 
Tree-In Data Structure
Tree-In Data StructureTree-In Data Structure
Tree-In Data Structure
Β 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
Β 
Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++Types of Tree in Data Structure in C++
Types of Tree in Data Structure in C++
Β 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
Β 
Binary Search Tree and AVL
Binary Search Tree and AVLBinary Search Tree and AVL
Binary Search Tree and AVL
Β 
Trees
TreesTrees
Trees
Β 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
Β 
Lec19
Lec19Lec19
Lec19
Β 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
Β 
binary search tree
binary search treebinary search tree
binary search tree
Β 

Viewers also liked

computer notes - Traversal of a binary tree
computer notes - Traversal of a binary treecomputer notes - Traversal of a binary tree
computer notes - Traversal of a binary treeecomputernotes
Β 
Non Linear Data Structures
Non Linear Data StructuresNon Linear Data Structures
Non Linear Data StructuresAdarsh Patel
Β 
Tree Traversals (In-order, Pre-order and Post-order)
Tree Traversals (In-order, Pre-order and Post-order)Tree Traversals (In-order, Pre-order and Post-order)
Tree Traversals (In-order, Pre-order and Post-order)raj upadhyay
Β 
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....Shail Nakum
Β 
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...widespreadpromotion
Β 
Tree data structure
Tree data structureTree data structure
Tree data structureDana dia
Β 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)Arvind Devaraj
Β 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its typesNavtar Sidhu Brar
Β 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsAakash deep Singhal
Β 

Viewers also liked (10)

computer notes - Traversal of a binary tree
computer notes - Traversal of a binary treecomputer notes - Traversal of a binary tree
computer notes - Traversal of a binary tree
Β 
Non Linear Data Structures
Non Linear Data StructuresNon Linear Data Structures
Non Linear Data Structures
Β 
Tree Traversals (In-order, Pre-order and Post-order)
Tree Traversals (In-order, Pre-order and Post-order)Tree Traversals (In-order, Pre-order and Post-order)
Tree Traversals (In-order, Pre-order and Post-order)
Β 
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
TYPES DATA STRUCTURES( LINEAR AND NON LINEAR)....
Β 
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
Β 
Binary tree
Binary  treeBinary  tree
Binary tree
Β 
Tree data structure
Tree data structureTree data structure
Tree data structure
Β 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)
Β 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
Β 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
Β 

Similar to Unit8 C

Admissions in india 2015
Admissions in india 2015Admissions in india 2015
Admissions in india 2015Edhole.com
Β 
Trees in data structrures
Trees in data structruresTrees in data structrures
Trees in data structruresGaurav Sharma
Β 
TREE DATA STRUCTURE SLIDES dsa dsa .pptx
TREE DATA STRUCTURE SLIDES dsa dsa .pptxTREE DATA STRUCTURE SLIDES dsa dsa .pptx
TREE DATA STRUCTURE SLIDES dsa dsa .pptxasimshahzad8611
Β 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structuresNiraj Agarwal
Β 
Introduction to data structure by anil dutt
Introduction to data structure by anil duttIntroduction to data structure by anil dutt
Introduction to data structure by anil duttAnil Dutt
Β 
#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docx#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docxajoy21
Β 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data StructureOm Prakash
Β 
Mca admission in india
Mca admission in indiaMca admission in india
Mca admission in indiaEdhole.com
Β 
Binary tree and operations
Binary tree and operations Binary tree and operations
Binary tree and operations varagilavanya
Β 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13ecomputernotes
Β 
Trees unit 3
Trees unit 3Trees unit 3
Trees unit 3praveena p
Β 
VCE Unit 05.pptx
VCE Unit 05.pptxVCE Unit 05.pptx
VCE Unit 05.pptxskilljiolms
Β 
Chapter 5_Trees.pdf
Chapter 5_Trees.pdfChapter 5_Trees.pdf
Chapter 5_Trees.pdfssuser50179b
Β 
Threaded binary tree
Threaded binary treeThreaded binary tree
Threaded binary treeArunaP47
Β 

Similar to Unit8 C (20)

Data Structures
Data StructuresData Structures
Data Structures
Β 
Trees
TreesTrees
Trees
Β 
Admissions in india 2015
Admissions in india 2015Admissions in india 2015
Admissions in india 2015
Β 
Trees in data structrures
Trees in data structruresTrees in data structrures
Trees in data structrures
Β 
TREE DATA STRUCTURE SLIDES dsa dsa .pptx
TREE DATA STRUCTURE SLIDES dsa dsa .pptxTREE DATA STRUCTURE SLIDES dsa dsa .pptx
TREE DATA STRUCTURE SLIDES dsa dsa .pptx
Β 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
Β 
Introduction to data structure by anil dutt
Introduction to data structure by anil duttIntroduction to data structure by anil dutt
Introduction to data structure by anil dutt
Β 
#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docx#include iostream using namespace std; const int nil = 0; cl.docx
#include iostream using namespace std; const int nil = 0; cl.docx
Β 
Trees in Data Structure
Trees in Data StructureTrees in Data Structure
Trees in Data Structure
Β 
Mca admission in india
Mca admission in indiaMca admission in india
Mca admission in india
Β 
Tree
TreeTree
Tree
Β 
Binary tree and operations
Binary tree and operations Binary tree and operations
Binary tree and operations
Β 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13
Β 
Data Structure
Data StructureData Structure
Data Structure
Β 
Trees unit 3
Trees unit 3Trees unit 3
Trees unit 3
Β 
VCE Unit 05.pptx
VCE Unit 05.pptxVCE Unit 05.pptx
VCE Unit 05.pptx
Β 
Unit7 C
Unit7 CUnit7 C
Unit7 C
Β 
Chapter 5_Trees.pdf
Chapter 5_Trees.pdfChapter 5_Trees.pdf
Chapter 5_Trees.pdf
Β 
Tree
TreeTree
Tree
Β 
Threaded binary tree
Threaded binary treeThreaded binary tree
Threaded binary tree
Β 

More from arnold 7490

More from arnold 7490 (20)

Les14
Les14Les14
Les14
Β 
Les13
Les13Les13
Les13
Β 
Les11
Les11Les11
Les11
Β 
Les10
Les10Les10
Les10
Β 
Les09
Les09Les09
Les09
Β 
Les07
Les07Les07
Les07
Β 
Les06
Les06Les06
Les06
Β 
Les05
Les05Les05
Les05
Β 
Les04
Les04Les04
Les04
Β 
Les03
Les03Les03
Les03
Β 
Les02
Les02Les02
Les02
Β 
Les01
Les01Les01
Les01
Β 
Les12
Les12Les12
Les12
Β 
Unit 8 Java
Unit 8 JavaUnit 8 Java
Unit 8 Java
Β 
Unit 6 Java
Unit 6 JavaUnit 6 Java
Unit 6 Java
Β 
Unit 5 Java
Unit 5 JavaUnit 5 Java
Unit 5 Java
Β 
Unit 4 Java
Unit 4 JavaUnit 4 Java
Unit 4 Java
Β 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
Β 
Unit 2 Java
Unit 2 JavaUnit 2 Java
Unit 2 Java
Β 
Unit 1 Java
Unit 1 JavaUnit 1 Java
Unit 1 Java
Β 

Recently uploaded

Tech Startup Growth Hacking 101 - Basics on Growth Marketing
Tech Startup Growth Hacking 101  - Basics on Growth MarketingTech Startup Growth Hacking 101  - Basics on Growth Marketing
Tech Startup Growth Hacking 101 - Basics on Growth MarketingShawn Pang
Β 
VIP Call Girls In Saharaganj ( Lucknow ) πŸ” 8923113531 πŸ” Cash Payment (COD) πŸ‘’
VIP Call Girls In Saharaganj ( Lucknow  ) πŸ” 8923113531 πŸ”  Cash Payment (COD) πŸ‘’VIP Call Girls In Saharaganj ( Lucknow  ) πŸ” 8923113531 πŸ”  Cash Payment (COD) πŸ‘’
VIP Call Girls In Saharaganj ( Lucknow ) πŸ” 8923113531 πŸ” Cash Payment (COD) πŸ‘’anilsa9823
Β 
Call Girls In DLf Gurgaon βž₯99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon βž₯99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon βž₯99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon βž₯99902@11544 ( Best price)100% Genuine Escort In 24...lizamodels9
Β 
Event mailer assignment progress report .pdf
Event mailer assignment progress report .pdfEvent mailer assignment progress report .pdf
Event mailer assignment progress report .pdftbatkhuu1
Β 
Sales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for SuccessSales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for SuccessAggregage
Β 
HONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsHONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsMichael W. Hawkins
Β 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdfRenandantas16
Β 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Dipal Arora
Β 
Understanding the Pakistan Budgeting Process: Basics and Key Insights
Understanding the Pakistan Budgeting Process: Basics and Key InsightsUnderstanding the Pakistan Budgeting Process: Basics and Key Insights
Understanding the Pakistan Budgeting Process: Basics and Key Insightsseri bangash
Β 
Insurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageInsurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageMatteo Carbone
Β 
Progress Report - Oracle Database Analyst Summit
Progress  Report - Oracle Database Analyst SummitProgress  Report - Oracle Database Analyst Summit
Progress Report - Oracle Database Analyst SummitHolger Mueller
Β 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayNZSG
Β 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Neil Kimberley
Β 
Call Girls in Gomti Nagar - 7388211116 - With room Service
Call Girls in Gomti Nagar - 7388211116  - With room ServiceCall Girls in Gomti Nagar - 7388211116  - With room Service
Call Girls in Gomti Nagar - 7388211116 - With room Servicediscovermytutordmt
Β 
Grateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfGrateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfPaul Menig
Β 
Forklift Operations: Safety through Cartoons
Forklift Operations: Safety through CartoonsForklift Operations: Safety through Cartoons
Forklift Operations: Safety through CartoonsForklift Trucks in Minnesota
Β 
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Delhi Call girls
Β 
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999Tina Ji
Β 
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service JamshedpurVIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service JamshedpurSuhani Kapoor
Β 

Recently uploaded (20)

Tech Startup Growth Hacking 101 - Basics on Growth Marketing
Tech Startup Growth Hacking 101  - Basics on Growth MarketingTech Startup Growth Hacking 101  - Basics on Growth Marketing
Tech Startup Growth Hacking 101 - Basics on Growth Marketing
Β 
VIP Call Girls In Saharaganj ( Lucknow ) πŸ” 8923113531 πŸ” Cash Payment (COD) πŸ‘’
VIP Call Girls In Saharaganj ( Lucknow  ) πŸ” 8923113531 πŸ”  Cash Payment (COD) πŸ‘’VIP Call Girls In Saharaganj ( Lucknow  ) πŸ” 8923113531 πŸ”  Cash Payment (COD) πŸ‘’
VIP Call Girls In Saharaganj ( Lucknow ) πŸ” 8923113531 πŸ” Cash Payment (COD) πŸ‘’
Β 
Call Girls In DLf Gurgaon βž₯99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon βž₯99902@11544 ( Best price)100% Genuine Escort In 24...Call Girls In DLf Gurgaon βž₯99902@11544 ( Best price)100% Genuine Escort In 24...
Call Girls In DLf Gurgaon βž₯99902@11544 ( Best price)100% Genuine Escort In 24...
Β 
Event mailer assignment progress report .pdf
Event mailer assignment progress report .pdfEvent mailer assignment progress report .pdf
Event mailer assignment progress report .pdf
Β 
Sales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for SuccessSales & Marketing Alignment: How to Synergize for Success
Sales & Marketing Alignment: How to Synergize for Success
Β 
HONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael HawkinsHONOR Veterans Event Keynote by Michael Hawkins
HONOR Veterans Event Keynote by Michael Hawkins
Β 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
Β 
Nepali Escort Girl Kakori \ 9548273370 Indian Call Girls Service Lucknow β‚Ή,9517
Nepali Escort Girl Kakori \ 9548273370 Indian Call Girls Service Lucknow β‚Ή,9517Nepali Escort Girl Kakori \ 9548273370 Indian Call Girls Service Lucknow β‚Ή,9517
Nepali Escort Girl Kakori \ 9548273370 Indian Call Girls Service Lucknow β‚Ή,9517
Β 
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Call Girls Navi Mumbai Just Call 9907093804 Top Class Call Girl Service Avail...
Β 
Understanding the Pakistan Budgeting Process: Basics and Key Insights
Understanding the Pakistan Budgeting Process: Basics and Key InsightsUnderstanding the Pakistan Budgeting Process: Basics and Key Insights
Understanding the Pakistan Budgeting Process: Basics and Key Insights
Β 
Insurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usageInsurers' journeys to build a mastery in the IoT usage
Insurers' journeys to build a mastery in the IoT usage
Β 
Progress Report - Oracle Database Analyst Summit
Progress  Report - Oracle Database Analyst SummitProgress  Report - Oracle Database Analyst Summit
Progress Report - Oracle Database Analyst Summit
Β 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 May
Β 
Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023Mondelez State of Snacking and Future Trends 2023
Mondelez State of Snacking and Future Trends 2023
Β 
Call Girls in Gomti Nagar - 7388211116 - With room Service
Call Girls in Gomti Nagar - 7388211116  - With room ServiceCall Girls in Gomti Nagar - 7388211116  - With room Service
Call Girls in Gomti Nagar - 7388211116 - With room Service
Β 
Grateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfGrateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdf
Β 
Forklift Operations: Safety through Cartoons
Forklift Operations: Safety through CartoonsForklift Operations: Safety through Cartoons
Forklift Operations: Safety through Cartoons
Β 
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Best VIP Call Girls Noida Sector 40 Call Me: 8448380779
Β 
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
Β 
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service JamshedpurVIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
VIP Call Girl Jamshedpur Aashi 8250192130 Independent Escort Service Jamshedpur
Β 

Unit8 C

  • 1.
  • 2.
  • 3. struct node { struct node *lchild; char data; struct node *rchild; } *root=NULL; struct node *insert(char a[],int index) { struct node *temp=NULL; if(a[index]!='') { temp = (struct node *)malloc( sizeof(struct node)); temp->lchild = insert(a,2*index+1); temp->data = a[index]; temp->rchild = insert(a,2*index+2); } return temp; } void buildtree(char a[]) { root = insert(a,0); } void inorder(struct node *r){ if(r!=NULL) { inorder(r->lchild); printf(&quot;%5c&quot;,r->data); inorder(r->rchild); } } void preorder(struct node *r){ if(r!=NULL) { printf(&quot;%5c&quot;,r->data); preorder(r->lchild); preorder(r->rchild); } } void postorder(struct node *r){ if(r!=NULL) { postorder(r->lchild); postorder(r->rchild); printf(&quot;%5c&quot;,r->data); } } void main() { char arr[] = { 'A','B','C','D','E','F','G','','','H','', '','','','','','','','','',''}; buildtree(arr); printf(&quot;Pre-order Traversal : &quot;); preorder(root); printf(&quot;In-order Traversal : &quot;); inorder(root); printf(&quot;In-order Traversal : &quot;); inorder(root); } Implementing Binary Tree Output : Preorder Traversal : A B D E H C F G Inorder Traversal : D B H E A F C G Postorder Traversal : D H E B F G C A A B C D E F G H Tree Created :
  • 4.
  • 5. struct node { struct node *lchild; int data; struct node *rchild; }; struct node *fnode=NULL,*parent=NULL; void insert(struct node **p, int n) { if(*p==NULL) { *p=(struct node *)malloc(sizeof(struct node)); (*p)->lchild=NULL; (*p)->data = n; (*p)->rchild=NULL; return; } if(n < (*p)->data) insert(&((*p)->lchild),n); else insert(&((*p)->rchild),n); } void inorder(struct node *t) { if(t!=NULL) { inorder(t->lchild); printf(&quot;%5d&quot;,t->data); inorder(t->rchild); } } void preorder(struct node *t) { if(t!=NULL) { printf(&quot;%5d&quot;,t->data); Implementing Binary Search Tree preorder(t->lchild); preorder(t->rchild); } } void postorder(struct node *t) { if(t!=NULL) { postorder(t->lchild); postorder(t->rchild); printf(&quot;%5d&quot;,t->data); } } void search(struct node *r,int key){ struct node *q; , fnode=NULL; q=r; while(q!=NULL) { if(q->data == key) { fnode = q; return; } parent=q; if(q->data > key) q=q->lchild; else q=q->rchild; } } void delnode ( struct node **r,int key) { struct node *succ,*fnode,*parent; if(*r==NULL) { printf(&quot;Tree is empty&quot;); return; } parent=fnode=NULL;
  • 6. search(*r,key); if(fnode==NULL) { printf(&quot;Node does not exist, no deletion&quot;); return; } if(fnode->lchild==NULL && fnode->rchild==NULL) { if(parent->lchild==fnode) parent->lchild=NULL; else parent->rchild=NULL; free(fnode); return; } if(fnode->lchild==NULL && fnode->rchild!=NULL) { if(parent->lchild==fnode) parent->lchild=fnode->rchild; else parent->rchild=fnode->rchild; free(fnode); return; } if(fnode->lchild!=NULL && fnode->rchild==NULL) { if(parent->lchild==fnode) parent->lchild=fnode->lchild; else parent->rchild=fnode->lchild; free(fnode); return; } Implementing Binary Search Tree ( continued ) if(fnode->lchild!=NULL && fnode->rchild!=NULL) { parent = fnode; succ = fnode->lchild; while(succ->rchild!=NULL){ parent=succ; succ = succ->rchild; } fnode->data = succ->data; free(succ); succ=NULL; parent->rchild = NULL; } } void inorder(struct node *t) { if(t!=NULL) { inorder(t->lchild); printf(&quot;%5d&quot;,t->data); inorder(t->rchild); } } void preorder(struct node *t) { if(t!=NULL) { printf(&quot;%5d&quot;,t->data); preorder(t->lchild); preorder(t->rchild); } }
  • 7. void postorder(struct node *t) { if(t!=NULL) { postorder(t->lchild); postorder(t->rchild); printf(&quot;%5d&quot;,t->data); } } int main() { struct node *root=NULL; int n,i,num,key; printf(&quot;Enter no of nodes in the tree : &quot;); scanf(&quot;%d&quot;,&n); for(i=0;i<n;i++) { printf(&quot;Enter the element : &quot;); scanf(&quot;%d&quot;,&num); insert(&root,num); } printf(&quot;Preorder traversal :&quot;); preorder(root); printf(&quot;Inorder traversal :&quot;); inorder(root); printf(&quot;Postorder traversal :&quot;); postorder(root); printf(&quot;Enter the key of node to be searched : &quot;); scanf(&quot;%d&quot;,&key); search(root,key); if(fnode==NULL) printf(&quot;Node does not exist&quot;); else printf(&quot;NOde exists&quot;); Implementing Binary Search Tree ( continued ) printf(&quot;Enter the key of node to be deleted : &quot;); scanf(&quot;%d&quot;,&key); delnode(&root,key); printf(&quot;Inorder traversal after deletion :&quot;); inorder(root); } Output : Enter no of nodes in the tree : 5 Enter the element : 18 Enter the element : 13 Enter the element : 8 Enter the element : 21 Enter the element : 20 Preorder traversal : 18 13 8 21 20 Inorder traversal : 8 13 18 20 21 Postorder traversal : 8 13 20 21 18 Enter the key of node to be searched : 13 Node exists Enter the key of node to be deleted : 20 Inorder traversal after deletion : 8 13 18 21
  • 8.
  • 9. Graphs A Tree is in fact a special type of graph. Graph is a data structure having a group of nodes connecting with cyclic paths. A Graph contains two finite sets, one is set of nodes is called vertices and other is set of edges. A Graph is defined as G = ( V, E ) where. i) V is set of elements called nodes or vertices. ii) E is set of edges, identified with a unique pair ( v1, v2 ) of nodes. Here ( v1, v2 ) pair denotes that there is an edge from node v1 to node v2. A B C D E Set of vertices = { A, B, C, D, E } Set of edges = { ( A, B ) , ( A, C ) , ( B, D ), ( C, D ),( C, E ) , ( D, E ) } A graph in which every edge is undirected is known as Un directed graph. The set of edges are unordered pairs. Edge ( A, B ) and ( B, A ) are treated as same edge. A C D E Un-directed Graph Directed Graph Set of vertices = { A, B, C, D, E } Set of edges = { ( A, B ) , ( A, C ) , ( B, B ), ( B, D ), ( C, A ), ( C, D ), ( C, E ) , ( E, D ) } A graph in which every edge is directed is known as Directed graph. The set of edges are ordered pairs. Edge ( A, B ) and ( B, A ) are treated as different edges. The edge connected to same vertex ( B, B ) is called loop. Out degree : no of edges originating at a given node. In degree : no of edges terminating at a given node. For node C - In degree is 1 and out degree is 3 and total degree is 4. B
  • 10.