hw02_sol - 2 ௞ିଵ ൈ 2 ൌ 2 ௞ିଵାଵ ൌ 2

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CS202 HW2 Solutions Question 1 (10 Points) PreOrder: A B D F C E G InOrder: F D B A C G E PostOrder: F D B G E C A Question 2 (10 Points) a) b) Delete 50 Delete 40 40 25 50 15 30 65 5 20 35 55 75 40 25 15 30 65 5 20 35 55 75 55 25 15 30 65 5 20 35 75
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Question 3 (15 Points) The maximum number of nodes that a binary tree may contain at level n is 2 ୬ିଵ . Proof by induction: Basis Case: The statement holds for nൌ1 which says that the maximum number of nodes at level 1 is 2 ୬ିଵ ൌ2 ଵିଵ ൌ1 , which is the root node only. Inductive Step: Assume that the maximum number of nodes that a binary tree may contain at level k is 2 ௞ିଵ . Consider for the level ݇൅1 , the maximum number of nodes equals to twice the number of nodes at level ݇ ; because, for every node in the previous level, there should be two children nodes. Therefore, the maximum number of nodes at level ݇൅1 is
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 2 ௞ିଵ ൈ 2 ൌ 2 ௞ିଵାଵ ൌ 2 ሺ௞ାଵሻିଵ . So it is shown that if the maximum number of nodes that a binary tree may contain at level ݇ is 2 ௞ିଵ , then the maximum number of nodes at level ݇ ൅ 1 is 2 ሺ௞ାଵሻିଵ . Since both the basis and the inductive step have been proved, it has now been proved by mathematical induction that the maximum number of nodes that a binary tree may contain at level n is 2 ୬ିଵ . Question 4 (15 Points) class TreeNode //full implementation can be found in slides { … TreeNode *leftChildPtr; TreeNode *rightChildPtr; … }; int numberOfNodes(TreeNode * node) { if (node == NULL) return 0; else return numberOfNodes(node-> leftChildPtr) + numberOfNodes(node-> rightChildPtr) + 1; }...
View Full Document

This note was uploaded on 02/01/2010 for the course CS cs-202 at Bilkent University.

Page1 / 2

hw02_sol - 2 ௞ିଵ ൈ 2 ൌ 2 ௞ିଵାଵ ൌ 2

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online