15
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE nformation Technology , 3’rd Semester Lecture 13 : Trees

DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE

Embed Size (px)

Citation preview

DATA STRUCTURE

Presented By: Mahmoud Rafeek Alfarra

Using C#

MINISTRY OF EDUCATION & HIGHER EDUCATIONCOLLEGE OF SCIENCE AND TECHNOLOGYKHANYOUNIS- PALESTINE

Information Technology , 3’rd Semester

Lecture 13 :Trees

Outline

Classification of Data Structures The definition of a tree Terminology of Tree Binary Trees Binary Search Tree Emank X Mezank !!

Classification of Data Structures3

Presented & Prepared by: Mahmoud R. Alfarra

The definition of a tree

A tree is a set of nodes connected by edges. An example of a tree is a company’s organization chart

4

Presented & Prepared by: Mahmoud R. Alfarra

The definition of a tree5

Presented & Prepared by: Mahmoud R. Alfarra

The purpose of an organization chart is to communicate

to the viewer the structure of the organization.

leaf nodes

root node

internal nodes

Terminology of Tree6

Presented & Prepared by: Mahmoud R. Alfarra

Tree: A collection of data whose entries have a

hierarchical organization

Node: An entry in a tree

Root node: The node at the top

Terminal or leaf node: A node at the bottom

Terminology of Tree7

Presented & Prepared by: Mahmoud R. Alfarra

Parent: The node immediately above a specified node

Child: A node immediately below a specified node

Ancestor: Parent, parent of parent, etc.

Descendent: Child, child of child, etc.

Siblings: Nodes sharing a common parent

Terminology of Tree8

Presented & Prepared by: Mahmoud R. Alfarra

Binary tree: A tree in which every node has at most two children

Depth: The number of nodes in longest path from root to leaf

Terminology of Tree9

Presented & Prepared by: Mahmoud R. Alfarra

Binary Trees10

Presented & Prepared by: Mahmoud R. Alfarra

Tree nodes contain two or more links Most of other data structures we have discussed only contain one

In Binary trees All nodes contain two links

None, one, or both of which may be NULL

The root node is the first node in a tree.

Each link in the root node refers to a child

A node with no children is called a leaf node

Binary Trees11

Presented & Prepared by: Mahmoud R. Alfarra

Allow the head (and the rear) to be moving targets

B

A D

C

Binary Tree Definitions12

Presented & Prepared by: Mahmoud R. Alfarra

Leaf: node that has no left and right children

Parent: node with at least one child node

Level of a node: number of branches on the

path from root to node

Height of a binary tree: number of nodes no

the longest path from root to node

Binary search trees14

Presented & Prepared by: Mahmoud R. Alfarra

Binary search trees

Not a binary search tree

5

10

30

2 25 45

5

10

45

2 25 30

5

10

30

2

25

45

Emank X Mezank !!

أعظم أسبـاب النجاة

استعن استعن باللهبالله

Next Lecture

Examples (Implementation of tree and

then Practices )