Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Trees

Part I

Lecture 10
Lecture Objectives

⚫ Tree
⚫ Binary Tree
Introduction Why Trees ?
Before Tree we were using

List Linked List

Advantage : Good for Advantage : It allows quick


Searching algorithms insertion and deletion of
elements
Disadvantage : Insertion and Disadvantage : Searching is
Deletion of Elements require difficult
Data movements
What about a Tree?

A tree combines the advantages of an ordered array and a linked list

Searching, Insertion/Deletion of Elements was Quick


Where Trees are Used?
Trees are widely used in computer science

To represent algebraic formulas A Tree

For searching large, dynamic lists Node

And in applications such as Branch

Artificial intelligence systems

And encoding algorithms

Tree : Definition

A Tree consists of a finite set of element, called nodes and a finite set of directed
lines called branches, that connect the nodes
Indegree:
Basic Concepts When a branch is directed toward the node

When a branch is directed Outward from a


A Tree Outdegree:
node

Degree:

Root: Node which has a Indegree as Zero

estor :
ny node in the path from
to the node
Indegree:
Basic Concepts When a branch is directed toward the node

When a branch is directed Outward from a


A Tree Outdegree:
node

Degree: Guess

Root: Node which has a Indegree as Zero

Ancestor :
Is any node in the path
from root to the node

Descendant :
all nodes in the path from
that node to leaf
Data node
Structure & Algorithms ‹#›
Basic Concepts A Tree may be divided into SUBTREEs

SubTree
What is a Sub Tree ?

It is a Connected Structure below the root.


First node in the subtree is the ROOT of the
sub tree

The concept of subtrees lead us to recursive


definition of a tree

How ? empty

or
A Tree is a set of nodes that are
Has a node
called root

From which we descend to zero or more subtrees which is also trees


Tree Representation
Trees are generally implemented in the computer using pointers

Outside the Computer

It is the Organization Chart Format


General Tree
Each node can have unlimited Outdegree

Indented List They have little use in Computers

Parenthetical List

A ( B (C D) E F (G H I ))

You might also like