You are on page 1of 18

TREES

LINEAR DATA STRUCTURE

ARRAY
LINKED LIST
STACK
QUEUE
THIS ARE BASICALLY COLLECTIONS OF DIFFERENT
KINDS IN WHICH DATA IS ARRANGED IN A
SEQUENTIAL MANNER.
IN ALL THIS WE HAVE A LOGICAL START AND
A LOGICAL END.
AS WE UNDERSTAND, THESE DATA
STRUCTURES ARE WAYS TO STORE AND
ORGANIZE DATA IN COMPUTERS.
WHERE DO WE USE TREE AS DATA STRUCTURE?
TREE DATA STRUCTURE IS USED TO REPRESENT
HIERARCHICAL DATA
FOR EXAMPLE:
A FAMILY TREE

ORGANIZATIONAL CHART
PARTS OF THE TREE

NODES - COLLECTION OF ENTITIES


ROOT - TOPMOST NODE OF THE TREE
CHILDREN - A LINK OR REFERENCE TO SOME OTHER NODES
LINK - ARROW IN THE STRUCTURE
LEAF - A NODE THAT HAS NO CHILD
DEPTH - LENGTH OF THE PATH FROM ROOT TO NODE X
HEIGHT - NUMBER OF EDGES IN LONGEST PATH FROM THAT
NODE TO A LEAF NODE.
BINARY TREE

- A TREE IN WHICH EACH NODE CAN HAVE AT


MOST 2 CHILDREN.
APPLICATIONS OF TREE

1. storing naturally hierarchical data e.g: File System


2. organize data for quick search, insertion, deletion e.g. Binary search tree
(Binary Search Tree is a node-based binary tree data structure which has the
following properties:
• -The left subtree of a node contains
only nodes with keys lesser than the node’s key.
• -The right subtree of a node contains
only nodes with keys greater than the node’s key.
• -The left and right subtree each
must also be a binary search tree.)
3. Trie is used for dictionary
4. network routing algorithm
POST ORDER TREE
POST-ORDER TRAVERSAL

• In this traversal method, the root node is visited last, hence the name. First we
traverse the left subtree, then the right subtree and finally the root node.
• We start from A, and following Post-order traversal, we first visit the left
subtree B. B is also traversed post-order. The process goes on until all the
nodes are visited. The output of post-order traversal of this tree will be −
•D→E→B→F→G→C→A
ALGORITHM

• Until all nodes are traversed −


• Step 1 − Recursively traverse left subtree.
• Step 2 − Recursively traverse right subtree.
• Step 3 − Visit root node.

You might also like