If you know the order of a B-tree, how do you figure out the maximum number of descendants from a page?
The maximum number of descendants is just the number of points in the node, since each pointer points to a descendant.
It depends on the current depth below that page, then it's just arithmetic.
Related
Given a network of a binary tree of nodes with edge capacities c_e. There are data at the leaf nodes and each has data size s_v. L_e is the set of all leaves in the subtree below edge e. Our aim is to find subset S of leaves such that the number of data size transmitted to the root r is maximized, but for all the edges that the data passes through the capacity constraint must hold. It is assumed that c_e and s_v are non negative integers and let m be their maximum. Using dynamic programming on trees it should run in O(nm^2) time.
I have working on this for hours but haven't really come up woth a working solution. Any hints would be appreciated.
edit:
The data must be transmitted as a whole or not at all. for example if a leaf has 10 the algorithm can only take 10 or 0 at all.
for example,
v4=1, v5=3, v6=2, v7=2.
e1=(v1,r), e2=(v2,v1) and e3=(v3,v1) and so on.
assume that the capacity for e4, e5,e6 and e7 satisfied. But c1=5, c2=3 and c3=4
if we focused on finding the maximum of each subtree, we will end up taking v5 and v6+v7 which is not optimal. how to make dynamic programming rule that can tackle this problem and find the correct optimal solution?
Similar to the dynamic programming solution for subset sum...
For each node, calculate the set of attainable sums for subsets of the leaves, and for each attainable sum, remember the last contributing child and the previous sum. You can use this information to reconstruct the set that produces the sum.
While doing a postorder traversal of the tree, you can calculate this set for each node using only the information on its children.
When you get to the root, pick the maximum attainable sum and reconstruct the leaves that produce it.
Can somebody help me in understanding the below algorithm of how to find the maximum difference between any two nodes in a Binary Tree.
http://www.geeksforgeeks.org/maximum-difference-between-node-and-its-ancestor-in-binary-tree/
I'm not understanding why they are trying to get minimum value from left subtree and right subtree when in actual we want max difference & not min difference. So, Shouldn't we be getting the max difference recursively from left & right subtrees & use it to calculate our result?
Thanks in advance !!
To find maximum difference it suffices to subtract maximum from minimum. The link you provided is describing algorithm for a different problem: find maximum difference |A-B| where A is ancestor of B.
As usual, there are several ways of performing this, and yours might work just as well as the one presented by geeksforgeeks, though it seems harder to implement to me.
The maximum difference between the current node and any other is obtained by substracting the minimum value from the current subtree from the current value. This is why they are taking the minimum value of the right and left subtree. The maximum difference so far is contained in the ref pointer, which is updated if needed.
In samsung technical test Question was asked whether this statement is true or not:
Maximum number of nodes in a binary tree is 2^(h+1)-1 where h is the height of tree.
I think it's false because according to Schaum's Series TMH height is defined as the maximum number of nodes till the leaf is reached.
Is it correct or not?
The statement is correct. A zero-height binary tree has at most one node, a tree of height one has at most 3 nodes and so on.
There are two conventions to define the height of binary 1) Maximum Number of nodes from root to leaf 2) Maximum Number of edges from root to leaf
Please refer following article
http://www.geeksforgeeks.org/iterative-method-to-find-height-of-binary-tree/
True, Maximum number is reached when each node has two children - so we have power of 2. Just draw the tree with all leafs at each level and you will see the formula.
according to this wikipedia article that statement is true
Given a very large binary tree (i.e. with millions of nodes), how to handle determining the number of nodes in the tree? In other words, given the root node of this tree to a function, the function should return the number of nodes in the tree.
Or let's say how do you check if the Binary Tree is BST if the tree has very large number of nodes?
Walk all nodes and check whatever conditions/metric you need. There is nothing else you can do without additional knowledge about the tree.
You can enforce particular conditions at the time when tree is created (i.e. must be balanced/sorted/whatever) or collect information about tree at creation time (i.e. store and constantly update number of children).
To check if it's a VALID bst you have to visit every node depth first and ensure each node is smaller than the previous.
If you want to evaluate how long that will take for a balanced BST you could get a quick approximation of the size by counting the length of one leg, I believe the total size will be between 2^(n-1) and 2^n-1 inclusive
Why are there duplicate nodes like 9, 1 and 6 in the wikipedia article on rope?
Am I missing something, or those nodes are fully redundant?
they (the non-leaf nodes with single children) seem completely pointless. there doesn't seem to be anything in the linked to paper from boehm et al that is equivalent (there they use "normal" balanced trees).
they make no sense to me.
From the article:
Each node has a "weight" equal to the length of its string plus the sum of all the weights in its left subtree.
Those numbers appear to represent a weight of the node, based on the size of its children. So two nodes with value 6 do not have to have the same values. There is a Hello_ of weight 6 and a _Simon of weight 6.
Edit
For non-leaf values, the duplicates appear to be there to make the leaves at the same depth.
Those nodes could come about after a delete. Eventually you would want to rebalance so every node has two children (or a leaf) and the depth of each branch would be the same.