Docsity

Introduction to Tree Data Structures - Prof. Bungcaras, Summaries of Economics

Partial preview of the text

Download Introduction to Tree Data Structures - Prof. Bungcaras and more Summaries Economics in PDF only on Docsity!

Introduction to Tree in

Data Structures

The tree is a nonlinear hierarchical data

structure and comprises a collection of

entities known as nodes. It connects each

node in the tree data structure using

"edges”, both directed and undirected.

In the tree in data structures, the node that is the

predecessor of any node is known as a parent

node, or a node with a branch from itself to any

other successive node is called the parent node

Parent

The node, a descendant of any node, is known as

child nodes in data structures.

In a tree, any number of parent nodes can have

any number of child nodes.

Children

Trees in the data structure, the node with no child,

is known as a leaf node.

leaf nodes are also called external nodes or

terminal nodes.

Leaf

Trees in the data structure have at least

one child node known as internal nodes.

nodes other than leaf nodes are internal

nodes

Sometimes root nodes are also called

internal nodes if the tree has more than

one node.

Internal Nodes

In a tree, many edges from the root node

to the particular node are called the depth

of the tree.

The total number of edges from the root

node to the leaf node in the longest path is

known as "Depth of Tree".

Depth

In a tree data structure, the number of edges from

the leaf node to the particular node in the longest

path is known as the height of that node.

Height

A complete binary tree is just like a full

binary tree, but with two major differences

Every level must be completely filled and all

the leaf elements must lean towards the left

and the last leaf element might not have a

right sibling i.e. a complete binary tree

doesn't have to be a full binary tree.

Complete Binary

A perfect binary tree is a type of binary tree

in which every internal node has exactly two

child nodes and all the leaf nodes are at the

same level.

Perfect Binary

A binary tree in which for each node, value

of all the nodes in left subtree is lesser or

equal and value of all the nodes in right

subtree is greater.

IMPLEMENTATION BINARY SEARCH

TREE

That is the field to store data.

There is one field which is pointer to node.

Node asterisk means pointer to node.

This definition of node is very similar to

definition of node for doubly linked list.

 And here in the main function, we will have to

write statement like root equal insert and the

arguments.

 This root is already a pointer to node so its

address can be collected in a pointer to pointer.

 Creating empty tree and code to test the logic, ask

user to enter a number and If number is found,

print "FOUND"

 We wanted to insert and in the main function we

are building this link.

 Insert the data in BST, return address of root node.

 If tree is empty, we can simply create a new node

and set it as root.

 if data to be inserted is lesser, insert in left

subtree.

 else, insert in right subtree.