# Lect5 - General Trees Binary Trees CSC212 1 Trees Previous...

This preview shows pages 1–10. Sign up to view the full content.

1 CSC212

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Trees Previous data structures (e.g. lists, stacks, queues) have a linear structure. Linear structures represent one-to-one relation between data elements. Trees have a nested or a hierarchical structure. Hierarchical structures represent one-to- many relation between data elements.
3 Trees Examples of situations were one-to-many relations exist… these can be represented as trees. Relation between a parent and his children. Relation between a person and books he owns. Relation between a basketball team and the players on the team. Card catalog in a library.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
4 Trees: Some Terminology A tree is represented as a set of nodes connected by edges . Nodes Edges A Tree Root Leafs
5 Trees: Comparison with Lists A List Unique first element. Unique last element. Each element, other than the first and the last, has a unique predecessor and a unique successor. A Tree Unique first node called root . Each node has successors, called its children . Each node has one predecessor, called parent . Leafs have no children. Root has no parent.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
6 Trees: More Terminology Simple path : a sequence of distinct nodes in the tree. Path length : number of nodes in a path. Siblings : two nodes that have the same parent. Ancestors : given a node A in a tree, the parent of the node A and the ancestors of the parent of A, are ancestors of A.
7 Trees: More Terminology Parent : a parent of a node is its predecessor. Child : a child of a node is its successor. Root : a unique node without any predecessor. Leafs : nodes without any children. Descendents : given a node A in a tree, the children of A and all descendents of the children of A are descendents of A.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
8 Trees: More Terminology A G F E B C I D H J Sub-Tree Rooted at G A-B-F is a Path Level 1 Level 2 Level 3 Level 4 Height?
9 Binary Trees A binary tree is a tree with the following: 1. Each node can have at most two subtrees and therefore at most two children. 2.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 05/18/2010 for the course COMPUTER S CSC212 taught by Professor Shah during the Winter '09 term at King Saud University.

### Page1 / 29

Lect5 - General Trees Binary Trees CSC212 1 Trees Previous...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online