Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS2420: Lecture 15 Vladimir Kulyukin Computer Science Department Utah State University.

Similar presentations


Presentation on theme: "CS2420: Lecture 15 Vladimir Kulyukin Computer Science Department Utah State University."— Presentation transcript:

1 CS2420: Lecture 15 Vladimir Kulyukin Computer Science Department Utah State University

2 Outline Trees (Chapter 4)

3 Binary Tree Heights and Leaves For any binary tree with L leaves and height H

4 Binary Tree Properties Property 1: A binary tree with N > 0 nodes has exactly N-1 edges. Proof: Every node, except the root, receives exactly one edge from its parent.

5 Binary Tree Properties Property 2: If T is a binary tree of height h≥0, T has at least h+1 and at most 2 h+1 - 1 nodes. Proof: Since T is of height h, T has h+1 levels. There must be at least one node on each level. So the number of nodes is at least h+1. Each level j has at most 2 j nodes. Thus, the number of nodes is at most 2 h+1 – 1.

6 Property 2: Lower Bound

7 Property 2: Upper Bound

8 Property 2: Upper and Lower Bounds on N

9 Binary Tree Properties

10

11 Binary Tree: Formula-Based Representation Formula-based representation –This assumes that the array counting starts with 1. –Parent(i) = i/2 –LeftChild(i) = 2i –RightChild(i) = 2i+1

12 Binary Tree: Linked Representation Linked representation –Each node is a structure containing data, and two pointers (LeftChild, RightChild).

13 BT Node: 2 Node Structures KEYDATA LEFT CHILD PTR RIGHT CHILD PTR KEY= DATA LEFT CHILD PTR RIGHT CHILD PTR


Download ppt "CS2420: Lecture 15 Vladimir Kulyukin Computer Science Department Utah State University."

Similar presentations


Ads by Google