This preview shows pages 1–8. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CSIS1118 oundations of Computer Science Foundations of Computer Science Recursion Recursion Hubert Chan ([O1,O3]; Chapters 4.3, 4.4) 1 athematical Induction Mathematical Induction Theorem: P(n) for all positive integers n. A proof by mathematical induction consists of two steps. asis step: (1) is true. Basis step: P(1) is true. Inductive step: for any positive integer k, if P(k) is true, then P(k+1) is true When we complete both steps, we have proved that P(n) is true for all positive integer n 1. Basic philosophy : [ P (1) k> 0 ( P ( k ) P ( k +1))] 2 n ≥ 1 P ( n ) ecursive Construction of Positive Integers Recursive Construction of Positive Integers Base Case : 1 is a positive integer Recursive Definition : If k is a positive integer, then (k+1) is also a positive integer. 3 ull Binary Trees ull Binary Trees hapter 4 3) hapter 4 3) Full Binary Trees Full Binary Trees (Chapter 4.3) (Chapter 4.3) Full Binary Trees (FBT) can be defined recursively Basis step : a single vertex (root) is a FBT Recursive step : If T 1 and T 2 are FBT’s, a root with 2 edges, ne connecting to the root of T nd the other to the root one connecting to the root of T 1 and the other to the root of T 2 , is also a FBT. Basis step Step 1 4 Step 2 ree Terminology ree Terminology Tree Terminology Tree Terminology Root: Top node (has no parent) root r Internal node: Node with children Leaf: Node with no children Internal ode x node y z leaf 5 Structural Induction Structural Induction Theorem. For any full binary tree T, int(T) = #. of internal nodes, leaf(T) = #. of leaves. Then, leaf(T) = int(T) + 1. 6 ecursive Algorithms ecursive Algorithms Recursive Algorithms Recursive Algorithms To solve P ( n ) for n ≥ 1, where P ( n ) is a problem of size n when n = 1, solve P (1) directly when n > 1, solve...
View
Full
Document
This note was uploaded on 02/05/2012 for the course FBE BUSI1007 taught by Professor Lin during the Spring '11 term at HKU.
 Spring '11
 Lin

Click to edit the document details