hw4
DESCRIPTION
HW4TRANSCRIPT
-
dsa homework #3due date : MAY 12, 2015
Name : Jui-Hui ChungID : B02202008
1 Trees
(1)
(2) Obviously if every node is put to the right of its parent, using the formula in the textbookwill give 2 (2 (2 1 + 1) + 1) + 1 . . . . . . equals 2n 1. The seven nodes is arranged as Idescrived.
(3) post(v) = pre(v) + desc(v) depth(v)
(4) identedParenthesis (T, p, number) //number initially 01 stack rightParenthesis2 perform "visit" to p3 if p is an internal node4 print { and newline and indent5 stack.push_back( number of indents plus } )6 number++7 for each child q of p do8 recursively traverse the subtree identedParenthesis (T, q, number)
2 Decision Trees
(1) Provided vm values are sorted, and numbers of positive and negative decisoin, startfrom the beginning of the sorted array we can calculate its total confusion by O(1) (bymemoizing the information of how many positive and negative have added up so far),needing a total time of O(M2)
(2)
1
-
(3)
Simply vectors and arrays. After finding a ideal branch, separate the vector of eachfeature with the correct threshold. Then recursivly called one half and the other.
2