ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,

Slides:



Advertisements
Similar presentations
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Advertisements

ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Laplace Transform Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2008 by Douglas Wilhelm Harder.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Topics in Applied Mathematics Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Tort Law: Negligence Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada ece.uwaterloo.ca.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Fixed-Point Iteration Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2007 by Douglas Wilhelm.
MATH 212 NE 217 Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Welcome to ECE 204 Numerical Methods for Computer Engineers Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo.
Proof by Induction.
MATH 212 NE 217 Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Binary Numbers Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2007 by Douglas Wilhelm Harder.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
MATH 212 NE 217 Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada ece.uwaterloo.ca.
Problems with Floating-Point Representations Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Decimal Numbers Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2007 by Douglas Wilhelm Harder.
Double-Precision Floating-Point Numbers Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Copyright © 2007.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada ece.uwaterloo.ca.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
1 Introduction In this course, we will look at: –Algorithms for solving problems efficiently –Data structures for efficiently storing, accessing, and modifying.
MATH 212 NE 217 Douglas Wilhelm Harder Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada Copyright © 2011.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
1 The tree data structure Outline In this topic, we will cover: –Definition of a tree data structure and its components –Concepts of: Root, internal, and.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
1 N -ary trees This topic quickly looks at a generalization of a binary tree, where each node has up to N children –Definition –Perfect N -ary trees –Complete.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
1 Complete binary trees Outline Introducing complete binary trees –Background –Definitions –Examples –Logarithmic height –Array storage.
Outline In this topic we will look at:
AVL Trees.
Outline Introducing perfect binary trees Definitions and examples
Multiway Search Trees.
All-pairs shortest path
Presentation transcript:

ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada ece.uwaterloo.ca © by Douglas Wilhelm Harder. Some rights reserved. Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo, Ontario, Canada ece.uwaterloo.ca © by Douglas Wilhelm Harder. Some rights reserved. Binomial Trees

2 Binomial trees Background A binomial tree is an alternate optimal tree to a perfect binary tree

3 Binomial trees The Idea The recursive definition is as follows: –A single node is a binomial tree of order h = 0 –A binomial tree B of order h is two binomial trees B 1 and B 2 of height h – 1 where The root of B 1 is the root of B, and B 2 is a sub-tree of B 1

4 Binomial trees Recursive Definition Thus, we start with a binomial tree of height 0:

5 Binomial trees Recursive Definition A binomial tree of height h = 1 is: –A binomial tree of height 0 with a sub-tree of height 0

6 Binomial trees Recursive Definition A binomial tree of order h = 1 :

7 Binomial trees Recursive Definition A binomial tree of order h = 2 is: –A binomial tree of order 1 with an additional sub-tree of order 1

8 Binomial trees Recursive Definition Like perfect trees, binomial trees are not defined for three nodes

9 Binomial trees Recursive Definition A binomial tree of order h = 3 is: –A binomial tree of order 2 with an additional sub-tree of order 2

10 Binomial trees Recursive Definition A binomial tree of order h = 3 is: –A binomial tree of order 2 with an additional sub-tree of order 2 –Here we have 8 nodes

11 Binomial trees Recursive Definition A binomial tree of order h = 4 is: –A binomial tree of order 3 with an additional sub-tree of order 3

12 Binomial trees Recursive Definition A binomial tree of order h = 4 is: –A binomial tree of order 3 with an additional sub-tree of order 3 –Here we have 16 nodes

13 Binomial trees Recursive Definition A binomial tree of order h = 5 is: –A binomial tree of order 4 with an additional sub-tree of order 4

14 Binomial trees Recursive Definition A binomial tree of order h = 5 is: –A binomial tree of order 4 with an additional sub-tree of order 4

15 Binomial trees Recursive Definition As a last example, a binomial tree of order h = 6 is: –A binomial tree of order 5 with an additional sub-tree of order 5

16 Binomial trees Various Theorems Theorem A binomial tree of order h has height h Proof: By induction, a binomial tree of order h = 0 has height 0, Assume it is true that a binomial tree of order h has height h, and A binomial tree of order h + 1 consists of: A binomial tree of order h and therefore height h, and An additional sub-tree of order h and therefore height h Thus, a binomial tree order h has a height of max(h, h + 1) = h + 1 We will use the terms “order h ” and “height h ” interchangable

17 Binomial trees Various Theorems Theorem A binomial tree of height h has 2 h nodes Proof: By induction, a binomial tree of height h = 0 has 1 = 2 0 nodes, Assume it is true for a binomial tree of height h, and A binomial tree of height h + 1 consists of: A binomial tree of height h with 2 h nodes, and An additional sub-tree of height h with 2 h additional nodes Thus, a binomial tree of height h + 1 has 2 h = 2 h + 1 nodes

18 Binomial trees Various Theorems Corollary A binomial tree with n nodes has a height of lg(n)

19 Binomial trees Various Theorems Theorem A binomial tree of height h has nodes at depth k Proof: By induction, a binomial tree of height h = 0 has 1 = 2 0 nodes, Assume it is true for a binomial tree of height h, and A binomial tree of height h + 1 has only one root node and one node at depth h + 1 : The number of nodes at depth k in a tree of height h + 1 has All the nodes of a binomial tree of height h at depth k, and All the nodes of a binomial tree of height h at depth k + 1 Thus,

20 Binomial trees Alternate Definition An alternate definition of a binomial tree is: A binomial tree of height h is a root node and has h sub-trees which are binomial trees of heights 0, 1, 2, …, h – 1

21 Binomial trees Alternate Definition For example, this binomial tree of height h = 6 has six sub-trees of heights 5, 4, 3, 2, 1 and 0

22 Binomial trees Various Theorems Theorem The degree of a root of a binomial tree of height h is h Proof: This follows trivially from the alternate definition Corollary The degree of the root is lg(n)

23 Binomial trees Various Theorems Theorem The root has the maximum degree of any node in a binomial tree Proof: Every other node is the root of a binomial tree of height less than h and therefore can only have less than h children

24 Binomial trees Applications We will use binomial trees in two applications: –The worst-case scenario for the depth of a disjoint set data structure –Binomial heaps—very fast priority queues

25 Binomial trees Summary This topic has covered binomial trees: –A tree of height h with 2 h nodes –Same idea as a perfect binary tree –The root has degree h –There are with nodes at depth k

26 Binomial trees References [1]Cormen, Leiserson, Rivest and Stein, Introduction to Algorithms, 2 nd Ed., MIT Press, 2001, §19.1, pp [2]Weiss, Data Structures and Algorithm Analysis in C++, 3 rd Ed., Addison Wesley, §6.8.1, p.240.

27 Binomial trees Usage Notes These slides are made publicly available on the web for anyone to use If you choose to use them, or a part thereof, for a course at another institution, I ask only three things: –that you inform me that you are using the slides, –that you acknowledge my work, and –that you alert me of any mistakes which I made or changes which you make, and allow me the option of incorporating such changes (with an acknowledgment) in my set of slides Sincerely, Douglas Wilhelm Harder, MMath