This document discusses binary trees, including their basic definitions, traversal methods, node representations, and functions. It describes binary trees as having a root node that partitions the tree into two disjoint subsets, left and right subtrees. Traversal methods like preorder, inorder, and postorder are explained recursively. Applications of binary search trees for sorting and searching arrays are also covered.
The document discusses different types of binary tree traversal including inorder, preorder, and postorder traversal. It provides C code examples to perform each type of traversal on a binary search tree. The code inserts nodes into the tree, then performs the specified traversal by recursively navigating the tree and printing out the node values at each step according to the traversal type. Sample output is shown for building a binary search tree and performing various traversals on it by selecting options from a menu.
The document discusses various non-linear data structures, focusing on binary trees. It defines key terminology related to binary trees such as root, leaf nodes, ancestors, descendants, etc. It also covers different types of binary trees like strictly binary trees, complete binary trees, binary search trees. The document discusses various binary tree representations, traversals (inorder, preorder, postorder), and operations like searching, insertion, and deletion on binary search trees. It briefly introduces threaded binary trees at the end.
This document provides an overview of data structures and trees. It defines trees and their properties like hierarchical structure, parent-child relationships, and representation using arrays and linked lists. It describes binary trees and their properties. It also covers binary search trees, operations on binary trees like insertion, deletion and traversal, and balanced binary search trees like AVL trees.
Trees are hierarchical data structures that can represent relationships between data items. They are useful for representing organizational charts, file systems, and programming environments. Key tree concepts include the root node, internal and leaf nodes, ancestors and descendants, subtrees, depth, height, and degree. Common tree operations include traversing the tree using preorder, inorder, and postorder traversal methods, evaluating expression trees, and using trees for data compression through Huffman coding. Huffman coding assigns variable-length binary codes to characters based on their frequency, allowing more common characters to have shorter codes to reduce the overall file size.
The document discusses various tree data structures and algorithms related to binary trees. It begins with an introduction to different types of binary trees such as strict binary trees, complete binary trees, and extended binary trees. It then covers tree traversal algorithms including preorder, inorder and postorder traversal. The document also discusses representations of binary trees using arrays and linked lists. Finally, it explains algorithms for operations on binary search trees such as searching, insertion, deletion and rebalancing through rotations in AVL trees.
Tree and Binary search tree in data structure.
The complete explanation of working of trees and Binary Search Tree is given. It is discussed such a way that everyone can easily understand it. Trees have great role in the data structures.
The document discusses various tree data structures, including binary trees and binary search trees. It provides definitions and examples of binary trees, their terminology like root, left/right subtrees, and tree traversal methods including preorder, inorder and postorder. It also discusses applications of binary search trees for searching, as well as operations on trees like inserting, deleting and traversing nodes.
The document discusses different types of tree data structures, including general trees, binary trees, binary search trees, and their traversal methods. General trees allow nodes to have any number of children, while binary trees restrict nodes to having 0, 1, or 2 children. Binary search trees organize nodes so that all left descendants are less than the parent and all right descendants are greater. Common traversal orders for trees include preorder, inorder, and postorder, which differ in whether they process the root node before or after visiting child nodes.
This document discusses different types of tree data structures, including binary trees and binary search trees. It provides descriptions of key tree terminology like root, parent, child, leaf nodes, and different tree traversal methods. The document also covers operations on binary search trees like insertion, searching, and deletion. It provides pseudocode examples for these BST operations and discusses handling different cases that can occur during node deletion. Finally, it briefly introduces AVL trees and the concept of balance factors and rotations needed to maintain the balanced tree property.
The document discusses binary trees and binary search trees. It begins with definitions of tree, binary tree, and binary search tree. It describes the key properties and terminology used for trees including nodes, degrees, heights, paths, etc. It then covers various tree traversal methods like preorder, inorder and postorder traversal. Operations for binary search trees like searching, insertion and deletion of nodes are explained along with algorithms. Different representations of binary trees using arrays and linked lists are also presented.
The document discusses various tree traversal algorithms and operations on binary trees. It explains breadth-first traversal, depth-first traversal including preorder, inorder and postorder. It also covers searching, inserting and checking if two trees are the same in binary trees. Other topics covered include finding the size, height, root-to-leaf sums, checking if a tree is a binary search tree, and level order traversal. Iterative algorithms for postorder, preorder and inorder traversal using stacks are also presented.
The document discusses various non-linear data structures, focusing on trees. It defines what a tree is and provides examples. It then describes different tree terminologies like root, node, leaf, height, etc. It discusses binary trees in more detail, including their representation and types. It also covers various tree traversal techniques like inorder, preorder and postorder traversal. Finally, it discusses some applications of trees like binary search trees, expression trees, threaded binary trees and B-trees.
The document discusses binary trees, including their memory representations (sequential and linked), tree traversals (pre-order, in-order, and post-order), and algorithms for traversing binary trees using stacks. Binary tree traversal algorithms include recursively visiting nodes in a certain order (pre-order visits root then left then right subtrees, etc.) or using a stack to simulate the recursion.
This document discusses tree data structures and binary search trees. It begins by defining linear and non-linear data structures, with trees being a non-linear structure. It then defines general tree terminology like root, child, parent, leaves, etc. It describes tree traversal methods like preorder, inorder and postorder. It also discusses binary search trees and basic BST operations like insertion, deletion and searching. Finally, it discusses how BSTs can be used for sorting by inserting elements into a BST and then performing an inorder traversal.
This document discusses binary trees and their traversal. It defines binary trees, their properties such as levels and degrees of nodes. It describes different types of binary trees like complete, skewed, etc. It also explains different traversal techniques like preorder, inorder and postorder traversals and provides algorithms to implement these traversals recursively as well as using stacks. Memory representations of binary trees like sequential and linked are also summarized.
The document discusses binary trees and binary search trees. It begins with an overview of binary tree operations and traversals, including in-order, pre-order and post-order traversal. It then covers binary search trees, including their properties and operations like searching, finding the minimum/maximum values, and successors/predecessors. The document provides examples and pseudocode for traversing and performing operations on binary trees and binary search trees, including inserting and deleting nodes.
The document discusses trees and binary trees. It defines key tree terminology like nodes, edges, root, leaf, etc. It explains properties of binary trees including full, complete, and binary search trees. It describes techniques for traversing binary trees including preorder, inorder and postorder traversal using recursion and stacks. Searching and insertion operations in binary search trees are also summarized.
A binary tree is composed of nodes where each node contains a value and pointers to its left and right children. A binary tree traversal involves systematically visiting each node by traversing either breadth-first or depth-first. Breadth-first traversal visits nodes by level while depth-first traversal can be pre-order, in-order, or post-order depending on when the node is visited. Threaded binary trees reduce the number of null pointers by using them to point to other nodes for more efficient traversals.
Binary trees are a non-linear data structure that impose a hierarchical structure on a collection of items. They consist of nodes connected by edges, with one root node and no cycles. Binary trees have many applications including representing directory structures, organizational charts, and mathematical expressions. Common tree terminology includes root, child, parent, leaf, internal node, and sibling nodes. Traversing a binary tree involves visiting each node exactly once using preorder, inorder, or postorder traversal methods.
本資料「To CoT or not to CoT?」では、大規模言語モデルにおけるChain of Thought(CoT)プロンプトの効果について詳しく解説しています。
CoTはあらゆるタスクに効く万能な手法ではなく、特に数学的・論理的・アルゴリズム的な推論を伴う課題で高い効果を発揮することが実験から示されています。
一方で、常識や一般知識を問う問題に対しては効果が限定的であることも明らかになりました。
複雑な問題を段階的に分解・実行する「計画と実行」のプロセスにおいて、CoTの強みが活かされる点も注目ポイントです。
This presentation explores when Chain of Thought (CoT) prompting is truly effective in large language models.
The findings show that CoT significantly improves performance on tasks involving mathematical or logical reasoning, while its impact is limited on general knowledge or commonsense tasks.
The document discusses various tree data structures and algorithms related to binary trees. It begins with an introduction to different types of binary trees such as strict binary trees, complete binary trees, and extended binary trees. It then covers tree traversal algorithms including preorder, inorder and postorder traversal. The document also discusses representations of binary trees using arrays and linked lists. Finally, it explains algorithms for operations on binary search trees such as searching, insertion, deletion and rebalancing through rotations in AVL trees.
Tree and Binary search tree in data structure.
The complete explanation of working of trees and Binary Search Tree is given. It is discussed such a way that everyone can easily understand it. Trees have great role in the data structures.
The document discusses various tree data structures, including binary trees and binary search trees. It provides definitions and examples of binary trees, their terminology like root, left/right subtrees, and tree traversal methods including preorder, inorder and postorder. It also discusses applications of binary search trees for searching, as well as operations on trees like inserting, deleting and traversing nodes.
The document discusses different types of tree data structures, including general trees, binary trees, binary search trees, and their traversal methods. General trees allow nodes to have any number of children, while binary trees restrict nodes to having 0, 1, or 2 children. Binary search trees organize nodes so that all left descendants are less than the parent and all right descendants are greater. Common traversal orders for trees include preorder, inorder, and postorder, which differ in whether they process the root node before or after visiting child nodes.
This document discusses different types of tree data structures, including binary trees and binary search trees. It provides descriptions of key tree terminology like root, parent, child, leaf nodes, and different tree traversal methods. The document also covers operations on binary search trees like insertion, searching, and deletion. It provides pseudocode examples for these BST operations and discusses handling different cases that can occur during node deletion. Finally, it briefly introduces AVL trees and the concept of balance factors and rotations needed to maintain the balanced tree property.
The document discusses binary trees and binary search trees. It begins with definitions of tree, binary tree, and binary search tree. It describes the key properties and terminology used for trees including nodes, degrees, heights, paths, etc. It then covers various tree traversal methods like preorder, inorder and postorder traversal. Operations for binary search trees like searching, insertion and deletion of nodes are explained along with algorithms. Different representations of binary trees using arrays and linked lists are also presented.
The document discusses various tree traversal algorithms and operations on binary trees. It explains breadth-first traversal, depth-first traversal including preorder, inorder and postorder. It also covers searching, inserting and checking if two trees are the same in binary trees. Other topics covered include finding the size, height, root-to-leaf sums, checking if a tree is a binary search tree, and level order traversal. Iterative algorithms for postorder, preorder and inorder traversal using stacks are also presented.
The document discusses various non-linear data structures, focusing on trees. It defines what a tree is and provides examples. It then describes different tree terminologies like root, node, leaf, height, etc. It discusses binary trees in more detail, including their representation and types. It also covers various tree traversal techniques like inorder, preorder and postorder traversal. Finally, it discusses some applications of trees like binary search trees, expression trees, threaded binary trees and B-trees.
The document discusses binary trees, including their memory representations (sequential and linked), tree traversals (pre-order, in-order, and post-order), and algorithms for traversing binary trees using stacks. Binary tree traversal algorithms include recursively visiting nodes in a certain order (pre-order visits root then left then right subtrees, etc.) or using a stack to simulate the recursion.
This document discusses tree data structures and binary search trees. It begins by defining linear and non-linear data structures, with trees being a non-linear structure. It then defines general tree terminology like root, child, parent, leaves, etc. It describes tree traversal methods like preorder, inorder and postorder. It also discusses binary search trees and basic BST operations like insertion, deletion and searching. Finally, it discusses how BSTs can be used for sorting by inserting elements into a BST and then performing an inorder traversal.
This document discusses binary trees and their traversal. It defines binary trees, their properties such as levels and degrees of nodes. It describes different types of binary trees like complete, skewed, etc. It also explains different traversal techniques like preorder, inorder and postorder traversals and provides algorithms to implement these traversals recursively as well as using stacks. Memory representations of binary trees like sequential and linked are also summarized.
The document discusses binary trees and binary search trees. It begins with an overview of binary tree operations and traversals, including in-order, pre-order and post-order traversal. It then covers binary search trees, including their properties and operations like searching, finding the minimum/maximum values, and successors/predecessors. The document provides examples and pseudocode for traversing and performing operations on binary trees and binary search trees, including inserting and deleting nodes.
The document discusses trees and binary trees. It defines key tree terminology like nodes, edges, root, leaf, etc. It explains properties of binary trees including full, complete, and binary search trees. It describes techniques for traversing binary trees including preorder, inorder and postorder traversal using recursion and stacks. Searching and insertion operations in binary search trees are also summarized.
A binary tree is composed of nodes where each node contains a value and pointers to its left and right children. A binary tree traversal involves systematically visiting each node by traversing either breadth-first or depth-first. Breadth-first traversal visits nodes by level while depth-first traversal can be pre-order, in-order, or post-order depending on when the node is visited. Threaded binary trees reduce the number of null pointers by using them to point to other nodes for more efficient traversals.
Binary trees are a non-linear data structure that impose a hierarchical structure on a collection of items. They consist of nodes connected by edges, with one root node and no cycles. Binary trees have many applications including representing directory structures, organizational charts, and mathematical expressions. Common tree terminology includes root, child, parent, leaf, internal node, and sibling nodes. Traversing a binary tree involves visiting each node exactly once using preorder, inorder, or postorder traversal methods.
本資料「To CoT or not to CoT?」では、大規模言語モデルにおけるChain of Thought(CoT)プロンプトの効果について詳しく解説しています。
CoTはあらゆるタスクに効く万能な手法ではなく、特に数学的・論理的・アルゴリズム的な推論を伴う課題で高い効果を発揮することが実験から示されています。
一方で、常識や一般知識を問う問題に対しては効果が限定的であることも明らかになりました。
複雑な問題を段階的に分解・実行する「計画と実行」のプロセスにおいて、CoTの強みが活かされる点も注目ポイントです。
This presentation explores when Chain of Thought (CoT) prompting is truly effective in large language models.
The findings show that CoT significantly improves performance on tasks involving mathematical or logical reasoning, while its impact is limited on general knowledge or commonsense tasks.
International Journal of Advance Robotics & Expert Systems (JARES)jaresjournal868
Call For Papers!!!
International Journal of Advance Robotics & Expert Systems (JARES)
Web page Link: http://airccse.com/jares/index.html
Submission Deadline :June17, 2025
submission Link: http://airccse.com/submission/home.html
Contact Us : [email protected] or [email protected] or [email protected]
First Review PPT gfinal gyft ftu liu yrfut goSowndarya6
CyberShieldX provides end-to-end security solutions, including vulnerability assessment, penetration testing, and real-time threat detection for business websites. It ensures that organizations can identify and mitigate security risks before exploitation.
Unlike traditional security tools, CyberShieldX integrates AI models to automate vulnerability detection, minimize false positives, and enhance threat intelligence. This reduces manual effort and improves security accuracy.
Many small and medium businesses lack dedicated cybersecurity teams. CyberShieldX provides an easy-to-use platform with AI-powered insights to assist non-experts in securing their websites.
Traditional enterprise security solutions are often expensive. CyberShieldX, as a SaaS platform, offers cost-effective security solutions with flexible pricing for businesses of all sizes.
Businesses must comply with security regulations, and failure to do so can result in fines or data breaches. CyberShieldX helps organizations meet compliance requirements efficiently.
This presentation highlights project development using software development life cycle (SDLC) with a major focus on incorporating research in the design phase to develop innovative solution. Some case-studies are also highlighted which makes the reader to understand the different phases with practical examples.
May 2025: Top 10 Read Articles Advanced Information Technologyijait
International journal of advanced Information technology (IJAIT) is a bi monthly open access peer-reviewed journal, will act as a major forum for the presentation of innovative ideas, approaches, developments, and research projects in the area advanced information technology applications and services. It will also serve to facilitate the exchange of information between researchers and industry professionals to discuss the latest issues and advancement in the area of advanced IT. Core areas of advanced IT and multi-disciplinary and its applications will be covered during the conferences.
Impurities of Water and their Significance.pptxdhanashree78
Impart Taste, Odour, Colour, and Turbidity to water.
Presence of organic matter or industrial wastes or microorganisms (algae) imparts taste and odour to water.
Presence of suspended and colloidal matter imparts turbidity to water.
The development of smart cities holds immense significance in shaping a nation's urban fabric and effectively addressing urban challenges that profoundly impact the economy. Among these challenges, road accidents pose a significant obstacle to urban progress, affecting lives, supply chain efficiency, and socioeconomic well-being. To address this issue effectively, accurate forecasting of road accidents is crucial for policy formulation and enhancing safety measures. Time series forecasting of road accidents provides invaluable insights for devising strategies, enabling swift actions in the short term to reduce accident rates, and informing well-informed road design and safety management policies for the long term, including the implementation of flyovers, and the enhancement of road quality to withstand all weather conditions. Deep Learning's exceptional pattern recognition capabilities have made it a favored approach for accident forecasting. The study comprehensively evaluates deep learning models, such as RNN, LSTM, CNN+LSTM, GRU, Transformer, and MLP, using a ten-year dataset from the esteemed Smart Road Accident Database in Hubballi-Dharwad. The findings unequivocally underscore LSTM's superiority, exhibiting lower errors in both yearly (RMSE: 0.291, MAE: 0.271, MAPE: 6.674%) and monthly (RMSE: 0.186, MAE: 0.176, MAPE: 5.850%) variations. Based on these compelling findings, the study provides strategic recommendations to urban development authorities, emphasizing comprehensive policy frameworks encompassing short-term and long-term measures to reduce accident rates alongside meticulous safety measures and infrastructure planning. By leveraging insights from deep learning models, urban development authorities can adeptly shape the urban landscape, fostering safer environments and contributing to global safety and prosperity.
PREDICTION OF ROOM TEMPERATURE SIDEEFFECT DUE TOFAST DEMAND RESPONSEFOR BUILD...ijccmsjournal
In order to evaluate side-effect of power limitation due to the Fast Automated Demand Response
(FastADR) for building air-conditioning facilities, a prediction model on short time change of average
room temperature has been developed. A room temperature indexis defined as a weighted average of the
entire building for room temperature deviations from the setpoints. The index is assumed to be used to
divide total FastADRrequest to distribute power limitation commands to each building.In order to predict
five-minute-change of the index, our combined mathematical model of an auto regression (AR) and a
neural network (NN) is proposed.In the experimental results, the combined model showedthe root mean
square error (RMSE) of 0.23 degrees, in comparison with 0.37 and 0.26 for conventional single NN and AR
models, respectively. This result is satisfactory prediction for required comfort of approximately 1 degree
Celsius allowance.
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...gerogepatton
The International Journal of Artificial Intelligence & Applications (IJAIA) is a bi monthly open access peer-reviewed journal that publishes articles which contribute new results in all areas of the Artificial Intelligence & Applications (IJAIA). It is an international journal intended for professionals and researchers in all fields of AI for researchers, programmers, and software and hardware manufacturers. The journal also aims to publish new attempts in the form of special issues on emerging areas in Artificial Intelligence and applications.
Third Review PPT that consists of the project d etails like abstract.Sowndarya6
CyberShieldX is an AI-driven cybersecurity SaaS web application designed to provide automated security analysis and proactive threat mitigation for business websites. As cyber threats continue to evolve, traditional security tools like OpenVAS and Nessus require manual configurations and lack real-time automation. CyberShieldX addresses these limitations by integrating AI-powered vulnerability assessment, intrusion detection, and security maintenance services. Users can analyze their websites by simply submitting a URL, after which CyberShieldX conducts an in-depth vulnerability scan using advanced security tools such as OpenVAS, Nessus, and Metasploit. The system then generates a detailed report highlighting security risks, potential exploits, and recommended fixes. Premium users receive continuous security monitoring, automatic patching, and expert assistance to fortify their digital infrastructure against emerging threats. Built on a robust cloud infrastructure using AWS, Docker, and Kubernetes, CyberShieldX ensures scalability, high availability, and efficient security enforcement. Its AI-driven approach enhances detection accuracy, minimizes false positives, and provides real-time security insights. This project will cover the system's architecture, implementation, and its advantages over existing security solutions, demonstrating how CyberShieldX revolutionizes cybersecurity by offering businesses a smarter, automated, and proactive defense mechanism against ever-evolving cyber threats.
Rearchitecturing a 9-year-old legacy Laravel application.pdfTakumi Amitani
An initiative to re-architect a Laravel legacy application that had been running for 9 years using the following approaches, with the goal of improving the system’s modifiability:
・Event Storming
・Use Case Driven Object Modeling
・Domain Driven Design
・Modular Monolith
・Clean Architecture
This slide was used in PHPxTKY June 2025.
https://phpxtky.connpass.com/event/352685/
2. Trees
Outline
Introduction to Trees
Binary Trees: Basic Definitions
Traversing Binary Trees
Node Representation of Binary Trees
Primitive Functions in Binary Trees
3. Introduction to Trees
BINARY TREES: BASIC DEFINITIONS
A binary tree is a finite set of elements that are
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 of the original tree. A left or right subtree
can be empty.
Each element of a binary tree is called a node of the
tree. The following figure shows a binary tree with 9
nodes where A is the root.
5. BINARY TREES: BASIC
DEFINITIONS
If A is the root of a binary tree and B is the root of its
left or right subtrees, then A is said to be the father
of B and B is said to be the left son of A.
A node that has no sons is called the leaf.
Node n1 is the ancestor of node n2 if n1 is either
the father of n2 or the father of some ancestor of n2.
In such a case n2 is a descendant of n1.
Two nodes are brothers if they are left and right
sons of the same father.
7. BINARY TREES: BASIC
DEFINITIONS
If every nonleaf node in a binary tree has
nonempty left and right subtrees, the tree is
called a strictly binary tree.
8. BINARY TREES: BASIC
DEFINITIONS
The level of a node in a binary tree is defined
as follows: The root of the tree has level 0,
and the level of any other node in the tree is
one more than the level of its father.
The depth of a binary tree is the maximum
level of any leaf in the tree.
A complete binary tree of depth d is the
strictly binary all of whose leaves are at level
d. A complete binary tree with depth d has 2d
leaves and 2d-1 nonleaf nodes.
10. TRAVERSING BINARY TREES
One of the common operations of a binary tree is to
traverse the tree. Traversing a tree is to pass
through all of its nodes once. You may want to print
the contents of each node or to process the
contents of the nodes. In either case each node of
the tree is visited.
There are three main traversal methods where
traversing a binary tree involves visiting the root and
traversing its left and right subtrees. The only
difference among these three methods is the order
in which these three operations are performed.
11. TRAVERSING BINARY TREES
Traversing a binary tree in preorder
(depth-first order)
1. Visit the root.
2. Traverse the left subtree in preorder.
3. Traverse the right subtree in preorder.
13. TRAVERSING BINARY TREES
Traversing a binary tree in inorder
(or symmetric order)
1. Traverse the left subtree in inorder.
2. Visit the root.
3. Traverse the right subtree in inorder.
15. TRAVERSING BINARY TREES
Traversing a binary tree in postorder
1. Traverse the left subtree in postorder.
2. Traverse the right subtree in postorder.
3. Visit the root.
17. NODE REPRESENTATION OF
BINARY TREES
Each node in a binary tree contains info, left, right
and father fields. The left, right and father fields
points the node’s left son, right son and the father
respectively.
struct node{
int info; /* can be of different type*/
struct node *left;
struct node *right;
struct node *father;
};
typedef struct node *NODEPTR;
18. PRIMITIVE FUNCTIONS IN
BINARY TREES
The maketree function allocates a node and sets
it as the root of a single node binary tree.
NODEPTR maketree(int x)
{
NODEPTR p;
p = getnode();
p->info = x;
p->left = NULL;
p->right = NULL;
return p;
}
19. PRIMITIVE FUNCTIONS IN
BINARY TREES
The setleft and setright functions sets a node with
content x as the left son and right son of the node p
respectively.
void setleft(NODEPTR p, int x)
{
if(p == NULL){
printf(“void insertionn”);
else if (p->left != NULL)
printf(“invalid insertionn”);
else
p->left = maketree(x);
}
void setright(NODEPTR p, int x)
{
if(p == NULL){
printf(“void insertionn”);
else if (p->right != NULL)
printf(“invalid insertionn”);
else
p->right = maketree(x);
}
20. BINARY TREE TRAVERSAL
METHODS
Recursive functions can be used to perform
traversal on a given binary tree. Assume that
dynamic node representation is used for a given
binary tree.
In the following traversal methods, the tree is
traversed always in downward directions. Therefore
the father field is not needed.
The following recursive preorder traversal function
displays the info part of the nodes in preorder. Note
that the info part is integer number and tree is a
pointer to the root of the tree.
22. BINARY TREE TRAVERSAL
METHODS
The following recursive inorder traversal
function displays the info part of the nodes in
inorder.
Note that the info part is integer number and
tree is a pointer to the root of the tree.
24. BINARY TREE TRAVERSAL
METHODS
The following recursive postorder traversal
function displays the info part of the nodes in
postorder.
Note that the info part is integer number and
tree is a pointer to the root of the tree.
26. BINARY SEARCH TREE: AN
APPLICATION OF BINARY TREES
A binary tree, that has the property that all
elements in the left subtree of a node n are
less than the contents of n, and all elements
in the right subtree of n are greater than or
equal to the contents of n, is called a Binary
Search Tree or Ordered Binary Tree.
27. BINARY SEARCH TREE: AN
APPLICATION OF BINARY TREES
Given the following sequence of numbers,
14, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5
The following binary search tree can be
constructed.
29. BINARY SEARCH TREE: AN
APPLICATION OF BINARY TREES
The inorder (left-root-right) traversal of the
above Binary Search Tree and printing the
info part of the nodes gives the sorted
sequence in ascending order. Therefore,
the Binary search tree approach can easily
be used to sort a given array of numbers.
The inorder traversal on the above Binary
Search Tree is:
3, 4, 4, 5, 5, 7, 9, 9, 14, 14, 15, 16, 17, 18, 20
30. SEARCHING THROUGH THE
BINARY SEARCH TREE
Searching operation of the binary search tree
is always in downward direction. Therefore
the following node structure can be used to
represent the node of a given binary search
tree.
Note that the father link is not required.
31. SEARCHING THROUGH THE
BINARY SEARCH TREE
struct node{
int info; /* can be of different type*/
struct node *left;
struct node *right;
};
typedef struct node *NODEPTR;
32. SEARCHING THROUGH THE
BINARY SEARCH TREE
The following recursive function can be used
to search for a given key element in a given
array of integers. The array elements are
stored in a binary search tree. Note that the
function returns TRUE (1) if the searched key
is a member of the array and FALSE (0) if the
searched key is not a member of the array.
33. SEARCHING THROUGH THE
BINARY SEARCH TREE
int BinSearch(NODEPTR p, int key)
{
if(p == NULL)
return FALSE;
else {
if (key == p->info)
return TRUE;
else{
if(key < p->info)
return BinSearch(p->left, key);
else
return BinSearch(p->right, key);
}
}
}
34. INSERTING NODES INTO A
BINARY SEARCH TREE
The following recursive function can be used
to insert a new node into a given binary
search tree.
36. Application of Binary Search
Tree
Suppose that we wanted to find all duplicates in a list of
numbers. One way of doing this to compare each number with all
those that precede it. However this involves a large number of
comparison. The number of comparison can be reduced by using
a binary tree. The first number in the list is placed in a node that
is the root of the binary tree with empty left and right sub-trees.
The other numbers in the list is than compared to the number in
the root. If it is matches, we have duplicate. If it is smaller, we
examine the left sub-tree; if it is larger we examine the right sub-
tree. If the sub-tree is empty, the number is not a duplicate and is
placed into a new node at that position in the tree. If the sub-tree
is nonempty, we compare the number to the contents of the root
of the sub-tree and the entire process is repeated with the sub-
tree. A program for doing this follows .
37. #include <stdio.h>
#include <stdlib.h>
struct node {
struct node *left ;
int info ;
struct node *right;
};
typedef struct node *NODEPTR;
NODEPTR maketree(int);
NODEPTR getnode(void);
void intrav(NODEPTR);
void main()
{
int number;
NODEPTR root , p , q;
printf("%sn","Enter First number");
scanf("%d",&number);
root=maketree(number); /* insert first root item */
printf("%sn","Enter the other numbers");
38. while(scanf("%d",&number) !=EOF)
{ p=q=root;
/* find insertion point */
while((number !=p->info) && q!=NULL)
{p=q;
if (number <p->info)
q = p->left;
else
q = p->right;
}
q=maketree(number);
/* insertion */
if (number==p->info)
printf("%d is a duplicate n",number);
else if (number<p->info)
p->left=q;
else p->right=q;
}
printf("Tree Created n ");
/* inorder Traversing */
intrav(root);
}