Full and Complete Binary Trees



Similar documents
Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child

If n is odd, then 3n + 7 is even.

Mathematical Induction. Lecture 10-11

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

Binary Search Trees CMPSC 122

MATHEMATICAL INDUCTION. Mathematical Induction. This is a powerful method to prove properties of positive integers.

3. Mathematical Induction

Binary Search Trees (BST)

Data Structures Fibonacci Heaps, Amortized Analysis

Analysis of Algorithms I: Binary Search Trees

Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products

WRITING PROOFS. Christopher Heil Georgia Institute of Technology

The Prime Numbers. Definition. A prime number is a positive integer with exactly two positive divisors.

6.3 Conditional Probability and Independence

Sample Induction Proofs

6.2 Permutations continued

Arkansas Tech University MATH 4033: Elementary Modern Algebra Dr. Marcel B. Finan

COUNTING SUBSETS OF A SET: COMBINATIONS

Algorithms and Data Structures

Basic Proof Techniques

A Non-Linear Schema Theorem for Genetic Algorithms

Introduction to Automata Theory. Reading: Chapter 1

Lecture 1: Course overview, circuits, and formulas

So let us begin our quest to find the holy grail of real analysis.

8 Divisibility and prime numbers

A binary search tree is a binary tree with a special property called the BST-property, which is given as follows:

root node level: internal node edge leaf node Data Structures & Algorithms McQuain

From Last Time: Remove (Delete) Operation

Section IV.1: Recursive Algorithms and Recursion Trees

A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called heap-order property

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

UNIVERSITY OF LONDON (University College London) M.Sc. DEGREE 1998 COMPUTER SCIENCE D16: FUNCTIONAL PROGRAMMING. Answer THREE Questions.

Union-Find Problem. Using Arrays And Chains

Binary Heaps. CSE 373 Data Structures

Indiana State Core Curriculum Standards updated 2009 Algebra I

TREE BASIC TERMINOLOGIES

GRAPH THEORY LECTURE 4: TREES

Lecture 17 : Equivalence and Order Relations DRAFT

Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

THE DIMENSION OF A VECTOR SPACE

Lecture 16 : Relations and Functions DRAFT

How To Create A Tree From A Tree In Runtime (For A Tree)

CHAPTER 3. Methods of Proofs. 1. Logical Arguments and Formal Proofs

Reading 13 : Finite State Automata and Regular Expressions

Graphs without proper subgraphs of minimum degree 3 and short cycles

Mathematical Induction

Mathematical Induction. Mary Barnes Sue Gordon


International Journal of Advanced Research in Computer Science and Software Engineering

This asserts two sets are equal iff they have the same elements, that is, a set is determined by its elements.

MATH 22. THE FUNDAMENTAL THEOREM of ARITHMETIC. Lecture R: 10/30/2003

MATH 4330/5330, Fourier Analysis Section 11, The Discrete Fourier Transform

Class Notes CS Creating and Using a Huffman Code. Ref: Weiss, page 433

Chapter 9: Distributed Mutual Exclusion Algorithms

CONTRIBUTIONS TO ZERO SUM PROBLEMS

Real Roots of Univariate Polynomials with Real Coefficients

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

Converting a Number from Decimal to Binary

Connectivity and cuts

Solutions to In-Class Problems Week 4, Mon.

ER E P M A S S I CONSTRUCTING A BINARY TREE EFFICIENTLYFROM ITS TRAVERSALS DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF TAMPERE REPORT A

Mathematical Induction

Cartesian Products and Relations

The ADT Binary Search Tree

Ordered Lists and Binary Trees

CHAPTER 2. Logic. 1. Logic Definitions. Notation: Variables are used to represent propositions. The most common variables used are p, q, and r.

ALGEBRAIC APPROACH TO COMPOSITE INTEGER FACTORIZATION

CS 103X: Discrete Structures Homework Assignment 3 Solutions

1.5 SOLUTION SETS OF LINEAR SYSTEMS

Undergraduate Notes in Mathematics. Arkansas Tech University Department of Mathematics

University of Ostrava. Reasoning in Description Logic with Semantic Tableau Binary Trees

Algorithms Chapter 12 Binary Search Trees

Binary Trees (1) Outline and Required Reading: Binary Trees ( 6.3) Data Structures for Representing Trees ( 6.4)

Solutions to Homework 6 Mathematics 503 Foundations of Mathematics Spring 2014

= = 3 4, Now assume that P (k) is true for some fixed k 2. This means that

I. GROUPS: BASIC DEFINITIONS AND EXAMPLES

Regular Languages and Finite Automata

Automata on Infinite Words and Trees

Operations: search;; min;; max;; predecessor;; successor. Time O(h) with h height of the tree (more on later).

Théorie de la décision et théorie des jeux Stefano Moretti

Similarity and Diagonalization. Similar Matrices

Math 55: Discrete Mathematics

arxiv:cs/ v1 [cs.dc] 30 May 2006

24. The Branch and Bound Method

Algebraic Structures II

Randomized Binary Search Trees

1. Prove that the empty set is a subset of every set.

Handout #1: Mathematical Reasoning

Handout #Ch7 San Skulrattanakulchai Gustavus Adolphus College Dec 6, Chapter 7: Digraphs

CONTENTS 1. Peter Kahn. Spring 2007

The Goldberg Rao Algorithm for the Maximum Flow Problem

Cardinality. The set of all finite strings over the alphabet of lowercase letters is countable. The set of real numbers R is an uncountable set.

JUST THE MATHS UNIT NUMBER 1.8. ALGEBRA 8 (Polynomials) A.J.Hobson

V. Adamchik 1. Graph Theory. Victor Adamchik. Fall of 2005

Big Data and Scripting. Part 4: Memory Hierarchies

Factorizations: Searching for Factor Strings

Analysis of Algorithms I: Optimal Binary Search Trees

Physical Data Organization

Chapter 6. Orthogonality

Transcription:

Full and Complete Binary Trees Binary Tree Theorems 1 Here are two important types of binary trees. Note that the definitions, while similar, are logically independent. Definition: a binary tree T is full if each node is either a leaf or possesses exactly two child nodes. Full but not complete. Definition: a binary tree T with n levels is complete if all levels except possibly the last are completely full, and the last level has all its nodes to the left side. Neither complete nor full. Complete but not full. Full and complete.

Full Binary Tree Theorem Binary Tree Theorems 2 Let T be a nonempty, full binary tree Then: (a) If T has I internal nodes, the number of leaves is L = I + 1. (b) If T has I internal nodes, the total number of nodes is N = 2I + 1. (c) If T has a total of N nodes, the number of internal nodes is I = (N 1)/2. (d) If T has a total of N nodes, the number of leaves is L = (N + 1)/2. (e) If T has L leaves, the total number of nodes is N = 2L 1. (f) If T has L leaves, the number of internal nodes is I = L 1. Basically, this theorem says that the number of nodes N, the number of leaves L, and the number of internal nodes I are related in such a way that if you know any one of them, you can determine the other two.

Proof of Full Binary Tree Theorem Binary Tree Theorems 3 proof of (a):we will use induction on the number of internal nodes, I. Let S be the set of all integers I 0 such that if T is a full binary tree with I internal nodes then T has I + 1 leaf nodes. For the base case, if I = 0 then the tree must consist only of a root node, having no children because the tree is full. Hence there is 1 leaf node, and so 0 S. Now suppose that for some integer K 0, every I from 0 through K is in S. That is, if T is a nonempty binary tree with I internal nodes, where 0 I K, then T has I + 1 leaf nodes. Let T be a full binary tree with K + 1 internal nodes. Then the root of T has two subtrees L and R; suppose L and R have I L and I R internal nodes, respectively. Note that neither L nor R can be empty, and that every internal node in L and R must have been an internal node in T, and T had one additional internal node (the root), and so K + 1=I L + I R + 1. Now, by the induction hypothesis, L must have I L +1 leaves and R must have I R +1 leaves. Since every leaf in T must also be a leaf in either L or R, T must have I L + I R + 2 leaves. Therefore, doing a tiny amount of algebra, T must have K + 2 leaf nodes and so K + 1 S. Hence by Mathematical Induction, S = [0, ). QED

Limit on the Number of Leaves Binary Tree Theorems 4 Let T be a binary tree with levels. Then the number of leaves is at most 2-1. proof: We will use strong induction on the number of levels,. Let S be the set of all integers 1 such that if T is a binary tree with levels then T has at most 2-1 leaf nodes. For the base case, if = 1 then the tree must have one node (the root) and it must have no child nodes. Hence there is 1 leaf node (which is 2-1 if = 1), and so 1 S. Now suppose that for some integer K 1, all the integers 1 through K are in S. That is, whenever a binary tree has M levels with M K, it has at most 2 M-1 leaf nodes. Let T be a binary tree with K + 1 levels. If T has the maximum number of leaves, T consists of a root node and two nonempty subtrees, say S 1 and S 2. Let S 1 and S 2 have M 1 and M 2 levels, respectively. Since M 1 and M 2 are between 1 and K, each is in S by the inductive assumption. Hence, the number of leaf nodes in S 1 and S 2 are at most 2 K-1 and 2 K-1, respectively. Since all the leaves of T must be leaves of S 1 or of S 2, the number of leaves in T is at most 2 K-1 + 2 K-1 which is 2 K. Therefore, K + 1 is in S. Hence by Mathematical Induction, S = [1, ). QED

More Useful Facts Binary Tree Theorems 5 Let T be a binary tree. For every k 0, there are no more than 2 k nodes in level k. Let T be a binary tree with λ levels. Then T has no more than 2 λ 1 nodes. Let T be a binary tree with N nodes. Then the number of levels is at least log (N + 1). Let T be a binary tree with L leaves. Then the number of levels is at least log L + 1.