hw4

2
dsa homework #3 due date : MAY 12, 2015 Name : Jui-Hui Chung ID : B02202008 1 Trees (1) (2) Obviously if every node is put to the right of its parent, using the formula in the textbook will give 2 · (2 · (2 · 1 + 1) + 1) + 1 ...... equals 2 n - 1. The seven nodes is arranged as I descrived. (3) post(v)= pre(v)+ desc(v) - depth(v) (4) identedParenthesis (T, p, number) //number initially 0 1 stack rightParenthesis 2 perform "visit" to p 3 if p is an internal node 4 print { and newline and indent 5 stack.push_back( number of indents plus } ) 6 number++ 7 for each child q of p do 8 recursively traverse the subtree identedParenthesis (T, q, number) 2 Decision Trees (1) Provided v m values are sorted, and numbers of positive and negative decisoin, start from the beginning of the sorted array we can calculate its total confusion by O(1) (by memoizing the information of how many positive and negative have added up so far), needing a total time of O(M 2 ) (2) 1

Upload: ahui-chung

Post on 18-Dec-2015

212 views

Category:

Documents


0 download

DESCRIPTION

HW4

TRANSCRIPT

  • 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