How to understand segmented binomial heaps described in <Purely Functional Data Structures> - haskell

In chapter 6.3.1 of the thesis Purely Functional Data Structures, says:
Then, whenever we create a new tree from a new element and a segment
of trees of ranks 0... r-1, we simply compare the new element with the
first root in the segment (i.e.,the root of the rank 0 tree). The
smaller element becomes the new root and the larger element becomes
the rank 0 child of the root.
T0' is the new tree has rank 0
T0..T(r-1) are the original trees rank 0 to r-1
The smaller element becomes the new root and the larger element becomes rank 0 child of the root
The question is that step 3 result in two rank 1 trees, which is conflict with the binomial heaps.
Am I misunderstanding?

We are creating a tree of rank r. The structure of a tree of rank r is a root node with r children of ranks 0..r-1.
What the part you quoted means is this.
When we get a new element x we compare it to the element in T0
We create a new tree T0' of rank 0 containing the greater of the two compared elements
We create a new node T containing the lesser of the two compared elements and with T0',T1,T2...T(r-1) as children
Now T is a binomial tree of rank r and it is in heap order.

Related

What does the value list mean in a Decision Tree graph

While viewing this question scikit learn - feature importance calculation in decision trees, I have trouble understanding the value list of the Decision Tree. For example, the top node has value=[1,3]. What exactly are 1 and 3? Does it mean if X[2]<= 0.5, then 1 false, 3 true? If so, the value list is [number of false cases, number of true cases]. If so, what about the value lists of the leaves?
Why do three right leaves have [0,1] and one left leaf has [1,0]?
What does [1,0] or [0,1] mean anyway? One false zero true or zero false one true? But there's no condition on the leaves (like something <=.5). Then what is true what is false?
Your advice is highly appreciated!
value=[1,3] means that, in this exactly leaf of the tree (before applying the filter x[2] <=0.5), you have:
1 sample of the class 0
3 sample of the class 1
Once you are going down the tree, you are filtering. Your objective is have perfectly separated classes. So you tend to have something like value=[0,1], which means that after applying all filters, you have 0 samples of class 0 and 1 samples of class 1.
You can also check that the sum of value is always similar to the samples. This makes completely sense since value is only telling you how all samples that arrived this leaf are distributed.

0/K knapsack. How to solve?

I am trying to learn Dynamic programming. I came across: https://youtu.be/U4O3SwDamA4?t=1407
I know basics of DP although they are not yet intuitive for me. Now, he talks about
0/1 knapsack
0/inf knap sack
and finally 0/k knapsack
While i tried to search 0/k knapsack, I am getting optimised solution (O(nS)) and not the solution that is extracted from 0/1 directly and have complexity of O(nKS). Anyone having nay resource to share or having a good grasp for the same is welcomed :) Thank you
I think the "naïve" solution the presenter is briefly mentioning has runtime complexity O(KS), given the way he defined K to be the sum of all the item limits. The idea is to convert it into a 0/1 problem by making ki copies of each item type.
Assume you've got k0 items of type 0, k1 items of type 1, and so on (so those are the limits to how many items you may take of each type). K is the total number of items (the sum of all the ki). Now, if you take this collection of items and start considering every item to be distinct from all the others, you have a 0/1 problem! The first item of type 0 is now item 0 in our new problem, the second item of type 0 is item 1 in our new problem, the last item of type 0 is item k0 - 1 in our new problem - and they all have weight w0 and value v0. The first item of type 1 is item k0 in our new problem, and so on. So we can now solve this as a 0/1 knapsack problem, but it's got K items instead of n; thus, the complexity is O(KS). However, if you define K to be the average of all the ki, or if every item has the same limit K, the complexity is indeed O(nKS).

Proof by induction that every non-empty tree of height h contains fewer than 2^n+1 nodes

I am stuck on the induction case of a problem.
The problem:
Define the height of a tree as the maximum number of edges between the
root and any leaf. We consider the height of an empty tree to be -1, and
the height of a tree consisting of a single node to be 0. Prove by induction that every non-empty binary tree of height h contains
fewer than 2 (h+1) nodes.
So I started:
Base case: h = 0 (Since a non-empty tree consists of a single node
or
more, the first case would be an empty node)
= 2 (0+1) = 2(1)= 2
When height is 0 the tree consists of a single, so yes 1 node is
less than 2 nodes.
Inductive step = h less than or greater to 0
This is where I am stuck... I know that the statement is true, since
the height will always be 1 less than the number of nodes, I just
don't know how to prove it algebraically.
Thanks in advance.
Suppose you have a tree with the height of n+1.
Both it's left subtree and right subtree have their height bound by n.
By induction, each subtree has less than 2^(n+1) nodes, meaning at most 2^(n+1) - 1 nodes.
Since we have two subtrees, we have at most 2 * (2^(n+1) - 1 ) = 2^(n+2) - 2.
Add one for the root, and the tree of height n+1 has at most 2^(n+2) - 1, which is less than 2^(n+2), as required.

About affine transform (translation )

For affine 4*4 transformation, I saw two representation in different text
one is
L T
0 1
Another is
L 0
T 1
L is the linear part, T is the translation part; I am wondering which is correct?
Both forms are correct. The first is used in left-multiply matrix by column vector
ResultVector = Matrix*V (for example, in OpenGL), and the second - in right-multiply convention with row vector V*Matrix (for example, in DirectX)

Binary Search Tree Generation from increasing index

I have a vector of parent pointers [ 0 1 1 2 2 3 3 5 5 ....] which is basically a binary tree. The index is the child and the corresponding value represents the index of its parent in the same vector.
e.g: in the above vector, if you count to index 5, the element is 2, which means that its parent lies at index 2. Again at index 2, the element is 1 which means the parent lies at index 1. At index 1 is the element is 0 which is the root node.
How can I create a binary search tree from this?
OR,
I am generating data in binary tree format in which I know the parent and corresponding children, how can I store them in a binary search tree?
Index for children will always be greater than the parent, as shown in the vector above.
An example is: I take node 1, divide it into two nodes, 2 and 3. Then take node 2 and divide it into 4 and 5. Then I take node 4 and divide it into 6 and 7 and so on.
I want to keep the parent child relationship in the binary search tree.
Best Regards
Wajahat
Generate a binary tree with empty elements according to you specification in the vector.
Upon new element arrival, find a place to put it: traverse the tree according to binary search tree rules - all the children in the left subtree are smaller than an element and all the children in the right subtree are larger. Fill the node corresponding to the element in the binary tree.
E.g., if you have this tree at some point of time:
and new value 3 arrives, it will fill the right child of node with value 2.
However, if 5 arrives, there is no place to put it in the predefined tree structure.

Resources