Leaves are represented with L and non-leaf with N in a tree. Each node has either 0 or 2 children. so if given preorder traversal of this tree, construct the tree.
@Anonymous no since each node in the tree has either 0 or 2 nodes ,so preorder traversal will always be unique..please check this taking some example ..:)
@Anonymous in your example 5 is leaf node in tree 1 so it will be representd in above tree as L and in second tree it is non leaf so it will be represented as N(Non-leaf).so they are not same..:)
Given an integer n, write a function that returns count of trailing zeroes in n!. Examples: Input: n = 5 Output: 1 Factorial of 5 is 20 which has one trailing 0. Input: n = 20 Output: 4 Factorial of 20 is 2432902008176640000 which has 4 trailing zeroes. Input: n = 100 Output: 24
but the tree wont be unique...we can have many such trees...pls elaborate..
ReplyDelete@Anonymous no since each node in the tree has either 0 or 2 nodes ,so preorder traversal will always be unique..please check this taking some example ..:)
ReplyDeleteeg.
ReplyDeleteconsider the preorder 1 2 4 5 6 7 3
Tree 1:
2,3 are child of 1
4,7 are child of 2
5,6 are child of 4
Tree 2:
2,3 are child of 1
4,5 are child of 2
6,7 are child of 5
@Anonymous in your example 5 is leaf node in tree 1 so it will be representd in above tree as L and in second tree it is non leaf so it will be represented as N(Non-leaf).so they are not same..:)
ReplyDelete