Insert elements into a red/black tree that just require color changes and no rotations? - red-black-tree

How can I find a sequence of elements that, if inserted into a red/black tree, would be balanced purely by changing colors rather than performing rotations?

You would need to ensure that the new node is always filling out the bottom-most unfilled layer of the RB tree. For example if you had a tree with two nodes it would always be the unbalanced side, like wise if your tree was of four nodes it would be one of the three remaining slots on the third 'row'.
Being able to do this with arbitrary data would pretty much require that arbitrary data to already be sorted (whether in an array or otherwise). Of course, if you're creating an RB tree from already sorted data you shouldn't even need color changes, all the upper-level nodes can be black while any nodes in an unfilled layer (of which there can only be one) will be red if there are missing nodes, or can be all red or all black if there are no missing nodes. If your data is not sorted you will eventually run into a situation where the next available nodes don't fit the available slots.

Related

Binary Search Tree Updating

How can I update values in Binary Search Tree without affecting its properties (all the nodes in the left subtree have values that are less than the value of the root node and all the nodes of the right subtree have values that are greater than the value of the root node).
I tried deleting and inserting the new Value, but It's an assignment and my teacher wants different solution using rotations or swaps.

Unreal Engine 5 - Change Base Color based on random value for each item in mesh

I am learning Unreal and currently building tree models. I am wanting to change the colour of the leaves between 3 texture samples based on random numbers, and while I have created a blueprint that can compare between numbers and output the correct colour, I can't find an input node that will assign a random number to each of the leaves.
The tree model is all one mesh however the vertices for the leaves are not connected between leaves. If I go into Unreals Modelling Mode and choose the TriSel (Triangle Select) tool I can select each leaf separately with one click, though I cant figure out any way to use this in the material editor.
I have attached a screenshot of the node group to select the base colour image below (the output of this group goes to the "Base Color" input). Currently the "Temp" value is changed manually (which changes the colour of all the leaves with this material), however that is where I want to input the random value for each leaf, if I can.
Thanks,
Dan

Issue on hiding multiple columns with NatTable

I need to programmatically hide multiple columns of a NatTable.
To do that, I compute an array of indices with a method and then I
invoke the MultiHideCommand as follows.
int[] indexArray = idxToHide.stream().mapToInt(i -> i).toArray();
_tableView.doCommand(new MultiColumnHideCommand(_tableView,indexArray));
What I get is that only a bunch of columns are hidden, but not all the columns in the indexArray.
I read that the ColumnHideShowLayer has been designed with UI interaction in mind.
Is there a right way to programmatically remove multiple columns?
First, the command takes the positions as parameter, not the indexes. Second, the positions need to be based on the layer that is used as first parameter. If a ViewportLayer is involved, non-visible columns won't be taken into account.
So you could try to calculate the positions based on some lower layer, e.g. the SelectionLayer, and then pass in the SelectionLayer and the positions based on the SelectionLayer on the command. That should work in theory.

How i can manage iterations in WTX reading a copybook

I have a copybook with an array of 30 products that I need to map to a XML message and a field that content the number of iterations that have information, but if there are not the 50 products some iteration come empty.
Actually I have a WTX map that map the array, but the map iterate over all the array even some iterations dont have information.
How can I map/validate only the iteration with information? Or how can i use the field en the copy book that indicate the number of iterations that have information to only map this ocurrences without go through all the array?
If you have a copybook with a fixed number of elements, all the elements are always there. That's how copybooks work - a fixed record size makes it easy to find a record's position in a file.
If you don't want to map all of them, you will have to add an IF testing for some condition telling you that the slot is not empty. Like whether part_number (or something) is greater than zero (or not blank, depending on your data types).

Neo4j indexing bug?

After asking about Neo4j caches, without having a definitive solution I kept testing Neo4j as the database that probably we are using in production. However, I am facing now a new problem with indexing attributes with specific labels.
The thing is that somehow, Neo4j is not getting the right data if I request a node by label and attribute (that accidentally have the same name). I've took some screenshots of what is happening hoping that it helps to understand the way I deduced that could be a bug. These are two examples of what is happening with two different labels.:
I have label A and label B, and attributes a and b. If you read from bottom to top, you can see that I am following these steps:
I request nodes with attribute a (no label) <- works
I request nodes with label A and attribute a <- doesn't work (using index)
I request nodes with label A and attribute b <- works
I request nodes with label B and attribute a <- works
I request nodes with label B and attribute b <- works (using index)
I also added extra columns to my request (they have no influence) to check that both columns have the same value, and also checking the labels.
I am having this issue only if the attribute is indexed using a label with the same name. That means, label A and attribute a. However, this is not happening with label B and attribute b. Not this time at least, because reproducing same scenario with other label an attribute name (following the rule A ... a) is causing the same problem.
I don't need to say that there is no influence from outside, so I have full control of what is happening in my database.
EDIT:
Your #1 did not really "work", since you should have gotten (at least) 2 rows (one for each label).
In your RETURN statements, you should include id(n) so that you can see which nodes are being returned. Right now, it is not clear.
EDITED
OK, with the IDs listed, it is now clear that we are talking about a single node with multiple labels. So, this certainly looks like a weird bug. If you are seeing this in the latest release, you should think about creating an issue for this at github.com/neo4j/neo4j/issues.