{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

04-recursion

# 04-recursion - CSIS1118 oundations of Computer Science...

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 Document

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

View Full Document

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the 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

{[ snackBarMessage ]}

### Page1 / 19

04-recursion - CSIS1118 oundations of Computer Science...

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

View Full Document
Ask a homework question - tutors are online