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

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

View Full Document Right Arrow Icon
1 CSC212
Background image of page 1

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

View Full DocumentRight Arrow Icon
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.
Background image of page 2
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.
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Trees: Some Terminology A tree is represented as a set of nodes connected by edges . Nodes Edges A Tree Root Leafs
Background image of page 4
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.
Background image of page 5

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

View Full DocumentRight Arrow Icon
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.
Background image of page 6
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.
Background image of page 7

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

View Full DocumentRight Arrow Icon
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?
Background image of page 8
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.
Background image of page 9

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

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 29

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online