Binary Search Tree Updating - binary-search-tree

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.

Related

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

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

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.

Submit nested UDTTs to a stored procedure in set based notation

I am helping a colleague with a system he has been tasked with where we have a form that has multiple sections and many of those sections can have sub-sections and those 2nd level sub-sections can have (third level) sub-sections themselves.
So, we have multiple User Defined Table Types, one that has the top level table structure, then inside of the first section there is a UDTT (let's call it subject as it is both sides of the problem in question), then inside of each 'side' we have another UDTT, perhaps their contact information, multiple phone numbers with a type column for each.
And there are n top level sections where up to n of them can have second or even third level UDTTs associated with them.
Now, I like using UDTTs to import large datasets from some kind of external source (usually a webpage where somebody has uploaded a large Excel or CSV file), but I have never had the circumstance where I have needed to pass multilevel UDTTs to a single stored procedure and I am not even sure how that would work, but in my quest for efficiency I am trying to find a way to do this without a while or for loop.
So... any suggestions?
You can't submit UDTT in a nested structure because a UDTT cannot contain a UDTT as a column within it.
However you can solve the problem by flattening the data and using a key field to links the children to the parent. For this you would need 1 parameter per different UDTT structure you are using and then rows within those parameters are linked using the key field to build your hierarchy.
You can then recover you original structure within the stored procedure depending on what actions you wish to take.

BigQuery position function for element within a nested element

How do I get the position for a field nested in multiple level of records:
select position(repeatedRec.rec1.field)
where repeatedRec is a repeated record, and rec1 is a non-repeated record? Assume that repeatedRec doesn't have any other leaves. I need to know what is repeatedRec position for the element in which rec1.field resides.
This doesn't seem to work, and all I get is 1 (as if the system is treating the field as a non repeated field).
have you tried
select position(repeatedRec.rec1.field) WHITHIN repeatedRec.rec1 as f1
https://developers.google.com/bigquery/docs/data#within
see this link for a small documentation on within

Order By in nhibernate column mapping

I have a parent - child node pattern the parent node has a collection of children nodes. The nodes have a property of position for ordering. I use this position property in my mapping file to order by. This works ok until I come to eager load the children which creates an left outer join and the position column is then ambigous. I have tried just adding Children.Position to the order by statement and this creates an error of unknown bound column. If there any way to specify this column?
Thanks
You'll have better luck by using an indexed collection (<list/>).