tree:

Count Complete Tree Nodes

Given a complete binary tree, count the number of nodes. Note Definition of a complete binary tree from Wikipedia: In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as possible. It can have between 1 and 2hnodes inclusive at the last level h. Example: Input: 1 / \ 2 3 / \ / 4 5 6 Output: 6 Solution # Definition for a binary tree node.

by lek tin in "algorithm" access_time 1-min read

Subtree of Another Tree

Given two non-empty binary trees s and t, check whether tree t has exactly the same structure and node values with a subtree of s. A subtree of s is a tree consists of a node in s and all of this node’s descendants. The tree s could also be considered as a subtree of itself. Example 1 Given tree s: 3 / \ 4 5 / \ 1 2 Given tree t:

by lek tin in "algorithm" access_time 2-min read