7.2-binary_tree

7.2-binary_tree - CMPT 225 Binary Tree CMPT 225 Bin-ary...

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

View Full Document Right Arrow Icon
CMPT 225 Binary Tree
Background image of page 1

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

View Full DocumentRight Arrow Icon
CMPT 225 Bin-ary Tree • Definition: N-ary tree where N = 2 • Property: If binary tree T has height H then T has between H and 2 H -1 nodes
Background image of page 2
CMPT 225 Binary Tree Operations • Create a Binary Tree • Empty binary tree • 1 node binaby tree (root) • Insert a subtree as left subtree of root • Insert a subtree as right subtree of root • Remove left subtree of root • Remove right subtree of root • Size of Binary Tree (# of elements stored in Binary Tree)
Background image of page 3

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

View Full DocumentRight Arrow Icon
CMPT 225 Insertion • Insert an element into a Binary Tree? • How does this operation work? • Answer: • Given a root, we can insert an element as either its left or its right subtree • Throw an exception if there is already a subtree
Background image of page 4
CMPT 225 Removal • Remove an element from a Binary Tree? • How does this operation work? • Answer: • Given a root, we can remove either its left or its right subtree • Throw an exception if there are no left/right subtrees • However, if we want to remove a specific element,
Background image of page 5

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

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

Page1 / 7

7.2-binary_tree - CMPT 225 Binary Tree CMPT 225 Bin-ary...

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

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