Ds Report
Ds Report
( I-SCHEME)
“ on topic
We take this opportunity to thank all those who have directly and indirectly inspired,
directed and assisted us towards successful completion of this project report.
We express our sincere thanks to a Principle, Dr. R. K. Patil and the head of department Mrs.
sujata patil , Lecturer of Computer Engineering Department Mrs. Archana paike , for having allowed
us to submit this report as a part of our academic learning.
We express the sincere thanks to Mrs. Archana paike, Computer Engineering Department ,
Govt. Polytechnic Karad for her encouraging throughout this project report and guideline in
designing and working out this project.
We are also grateful to team " DSU" for their highly encouraging and co-operative
attitude. We express our sense of gratitude towards our friends and parents for their constant moral
support during.
Yours sincerely,
Zanzane shveta shailesh(1266), dagade shreya gorakh (1208),misal kajal aba (1237) have
completed the project report titled as , " TREE TRANSVERSAL DATA STRUCTURE – DSU, under the
guidance of Mrs. Archana paike and submitted it to Department of
Computer Engineering , Govt. Polytechnic Karad. The information presented in this project report has
not been submitted earlier .
Date:
A tree is a hierarchical data structure made up of nodes and connected by the edges.
HTML and XML are two markup languages that use a tree structure, in which the root
includes child branches, which may have their own child branches, and so on. Tree
traversal in a data structure is a type of graph traversal in computer science. It is the
process by which each node in a tree data structure is visited exactly once.
Tree traversal in a data structure is a type of graph traversal in the data structure that
refers to the process of visiting, verifying, and updating each node in a tree data
structure just once. The order in which you examine the nodes of the tree is used to
classify these traversals.
This first data structure is a stack, which is a container for added and
removed items according to the last-in-first-out (LIFO) principle.
Queue data structure
The second data structure is the queue data structure. The first-in, first-out
(FIFO) concept governs how you add and withdraw objects in linear data sets from a
queue. You will cover the varieties of tree traversal in the data structure next in this
data structure tutorial .
You can perform tree traversal in the data structure in numerous ways,
unlike arrays, linked lists, and other linear data structures, which are canonically
traversed in linear order. You can walk through them in either a depth-first search or a
breadth-first search. In-order, pre-order, and post-order are the three most frequent
ways to go over them in depth-first.
#include <stdio.h>
#include <stdlib.h>
enum traversal {preorder_travesal, inorder_travesal, postorder_traversal};
typedef enum traversal trav;
typedef struct node node;
struct node {
int x;
node* left_node, *right_node;
};
node* create_tree (int data) {
// creating tree
node->left_node=root->right_node= NULL;
root->x=data;
return root;
}
node->left_node = node-> right_node=NULL;
return node;
}
void release_tree (node*root){
//releasing tree
node* t=root;
if (!t)
return ;
release_tree (t->left_node);
release_tree (t->right_node);
if (!t-> left_node & &! t->right_node) {
free(t);
return ;
}
}
void displaytree (traversal trav, node*root){
if(! root)
return ;
switch (trav){
case (preorder_traversal): //pre-order travesal
printf("%d - >", root->x);
displaytree(trav, root->left_node);
displaytree (trav, root->right_node);
break;
case (inorder_traversal)://inorder traversal
displaytree (trav, root->left_node);
printf("%d->", root->x);
displaytree (trav, root->right_node);
break;
}
}
int main(){
node*root=create_tree(5);
root->left_node=create_node(10);
root->right_node=create_node(15);
root->left_node->left_node=create_node(20);
root->left_node->right_node=create_node(25);
root->right_node->left_node=create_node(30);
root->right_node->right_node=create_node(35);
printf("preorder transversing");
displaytree (preorder_travesal, root);
printf("postorder traversing \n");
displaytree (postorder_traversal, root);
release tree(root);
return 0;
}
Output of tree traversal code:
Preorder traversing
5->10->20->25->15->30->35->
Inorder traversing
20->10->25->5->30->15->35->
Postorder traversing
20->25->10->30->35->15->5->