How do I implement a remove/delete function for a Patricia Trie? - patricia-trie

I have partially implemented a Patricia Trie, it's still not complete since it lacks a delete/remove function which is used to remove nodes from the Trie, I have found this article describing the structure, which comes with an implementation in C++, there's a remove/delete function, but I can't figure out what's the idea behind the implementation.
How do I remove a node from the Trie and leave the Trie in a proper state?

I've implemented a PATRICIA in C recently. In order to remove a node, find the down-trie node which points backward up the trie to the victim (this may be the victim node itself.)
Once found, if the victim node is NOT the backward-referer, switch the victim with its referer. This puts the victim close to being a "leaf" node, and its backward reference will be to itself. The removal is very simple, then.

Related

Calculate points inside the mesh of other instances with Geometry Nodes

I'm working on a procedural terrain generator using Geometry Nodes and I want to include the option of having buildings or other objects placed inside a collection that the terrain uses as a reference for where not to put grass, pebbles and rocks. The issue I have is that I've been only able to do it with the faces of the objects in the collection, and when they are big enough, that causes the points to be distributed inside the object. Here's a capture:
I've scoured the internet for help, but since the change in the geometry nodes on 3.0, most of the answers I can find use the old system and I can't find a way to adapt it, so I'm asking for help here, because I ran out of ideas. Here's the current set up I have to make the selection to know where not to put points for the grass:
I did try using the Mesh Boolean approach, but it is too resource heavy. For the buildings is not a problem, but when I use it for avoiding grass from spawning inside the big rocks, it makes the entire geometry nodes really heave resources wise.
Any Help is appreciated, I've been fighting this "bug" for three days now and it's driving me crazy. Thanks!
After many searches, I've managed to find a solution that works! It is using the method explained in this tutorial: https://www.youtube.com/watch?v=tvb2aCeTANM
Basically, you create a raycast on top of the scene and use a Boolean Math node to detect if it's hitting or not. In my case, for deleting the Geometry in the mesh where the points are distributed, I used a "Or" operation. You can see the node setup here: New Node Setup
Hope this helps anyone else having the same problem :). Of course if anyone can think of a better solution, feel free to add it!
Just use Raycast node with position node to evaluate a dot product
and then add map range with clamp checkbox

Where to insert in a linked list and why?

Applying open hashing the linked list inserts a new node at the front or at the back, but what's preferable and why, or doesn't it matter?
The principle of open hashing is that the useful values of the array as part of the hash table are singly linked lists (= SLL) (&)
Each node of the SLL consists of a key value pair and refers to the next node or null.
When adding a new node, this can be done at the very front, i.e. at the 'connection' of the SLL to the array, or at the very back, i.e. at the tail of the SLL (for the completeness: somewhere randomly in between is possible)
On some websites and in some books, one illustrates the addition at open hashing by adding AT THE BACK. Other websites and books add AT THE FRONT.
My question: what is desirable? What is most commonly used? Or doesn't that play any role? How does, what is described here, happen in Java? And in C#?
Illustrations:at the front: https://www.cs.usfca.edu/~galles/visualization/OpenHash.html and
at the back: https://visualgo.net/en/hashtable
(&) or is the use of a doubly linked list mandatory / advisable?
I apologize if this question was asked already but after searching I found explanations for the fact that the linked list is growing but no one explains exactly how in the sense of at the front or at the back and why so.

D* / D* Lite query (dynamic pathfinding algorithms)

I'm writing a paper comparing D*, D* Lite and LPA* and how useful they are in navigating an agent across a dynamic environment.
If anyone has any info that would be helpful for this please leave below.
Specifically, can anyone explain in simple terms why D* and D* lite traverse from goal to start rather than start to goal like LPA*? I understand the g value would then be the distance from the goal but confused as to what benefits this has.
Thanks in advance.
When you search outwards from the start state, all of the outward paths also give you routes back to the start, making it easy to get back there. Then, when you get to the goal, you have one path to the goal, but many paths from other states back to the start.
If the world isn't changing it doesn't matter whether you search backwards or forwards (or bidirectionally), in the end you have a path that you can use.
But, if the world changes and you lose your one path to the goal from a forward search, it can be hard to re-connect to that single path. If instead you search outwards from the goal, you still have many paths back to the goal. If the world changes, you can then search to reconnect the invalidated states back to any path that leads to the goal (of which there are many). Although it may not be optimal, it may only require a small and simple repair.

Meaning of values in SCIP_NodeType

Is there a combination of parameter settings so that the search tree only contains "simple" node types, i.e. not SCIP_NODETYPE_{PROBINGNODE, DEADEND, JUNCTION, PSEUDOFORK, FORK, SUBROOT, REFOCUSNODE}? Even if it means disabling some functionality.
I'm also not really sure about what the different node types really mean, so any pointers to documentation would also be very useful.
The meaning of the different node types is explained here. If you have a closer look, you will understand that those types reflect the internal organization of the tree. They necessarily occur during tree search and cannot be skipped via parameters.
If you insist: setting limits/nodes = 1 will process only the root node of SCIP, and the tree will only consist of a focus node and its 2 children.

Interview task on binary trees

Task: transfer a server side binary tree to client.
I got this task in an interview. Is there any efficient way to do this?
I don't understand the task very well myself.
This is what I came up with, but not sure about server to client trasfer. Any ideas?
void copyInOrder(TNode *orgTree, Tnode *& copyTree)
{
if(orgTree !=NULL){
//left side
TNode newLeftNode = cloneNode(orgTree->left_link);
copyTree->left_link = newLeftNode;
copyInOrder(orgTree->left_link, copyTree->left_link);
//right side
TNode newRightNode = cloneNode(orgTree->right_link);
copyTree->right_link = newRightNode;
copyInOrder(orgTree->right_link, copyTree->right_link);
}
}
Honestly, defining "efficient" would be a good first step. What is considered important? Network bandwidth? Server side computation involved? Client side computation involved?
Along the same lines, what is the data?
For example, if the data is integers and network bandwidth is important, you could do construct an array of ints from the tree, transfer that with minimal overhead, and then convert it back to a binary tree on the user's end.
If server side load is the most important thing, you'd go a different route. If client side load, possibly yet another.
Its worth noting that, since this is an interview question, discussing with the interviewer what they find important for efficiency and how it affects the solution may be just as important as the actual solution you come up with.
To me, the problem seems to be not so much about the transfer itself, but how one would package the data to be transferred. The important thing to note is that since you are transferring bytes, as opposed to C++ objects, you will not be able to preserve the structure of the tree so easily during the transfer.
Therefore, I would suggest that you serialize the tree, and then send it over the network. You would obviously need to a pre-determined serialization scheme that the client knows about, so that the client can recreate the tree from the bytes it receives.
It suffices to show how to convert a given binary tree T to a sequence S of values in such a way that we can reconstruct T from S at the client side. One possible way is to use the well know fact:
We can construct a binary tree uniquely from its inorder and preorder
traversals.
Thus we can let S be the inorder traversal followed by the preorder traversal. Check the answer of this question.