I have been studying Tarjan's articulation points finding algorithm and it says that the root node is an articulation point if it has more that 1 child. But if the graph is strongly connected, the root node shouldn't be an articulation point even if it has more than 1 child. Can someone please explain?
If a graph is strongly connected then its root will never have 2 child.
Remember , we are talking about DFS tree here. Hence in strongly connected graph , DFS-tree's root will only have one child and thats for sure.Try it urself.
Related
Could anybody please clarify how (as I have not found any clear example anywhere) The MCTS algorithm iterates for the second player.
Everything I seem just seems to look like it is playing eg P1 move every time.
I understand the steps for one agent but I never find anything showing code where P2 places its counter, which surely must happen when growing the tree.
Essentially I would expect:
for each iter:
select node Player1
expand Player1
select node Player2
expand player 2
rollout
backpropogate
next iter
Is this right?? Could anybody please spell out some psuedocode showing that? Either iteratively or recursion i don't mind.
Thanks for any help.
The trick is in backpropagation part, where you update "wins" variable from the point of view of player whose move led into this position.
Code for MCTS
Notice under UCT function, specially the comments:
#Backpropagate
while node != None: # backpropagate from the expanded node and work back to the root node
node.Update(state.GetResult(node.playerJustMoved)) # state is terminal. Update node with result from POV of node.playerJustMoved
node = node.parentNode
IF you follow the function call, you would realize visit variable is always updated; wins however, is not.
I understand the logic of using a queue to visit the nodes in a binary search tree level by level.
However i tried to implemment in C but i'am stuck because i don't know how to enqueue them properly. Starting with the root i can create a Queue but after that if i add the children of the root to the queue i will lose the children of those new nodes since iam modifying the connections in the Queue every time a add a new node.
I could create a new data type that has one more link to use in the linked list Queue, that should work. What is the best approach here?
visit[ing] the nodes in a binary search tree level by level
has a name: it is called a "breadth-first" traversal of the tree. Starting with an empty queue, you enqueue the root node and then repeatedly dequeue the first node in the queue, process it somehow, and enqueue all that node's children, until there are no more nodes enqueued. When exactly you should enqueue a node's children relative to other processing of that node may depend on exactly what processing you intend to perform, especially if it involves structurally modifying the tree.
As long as the per-node processing can affect only the subtree rooted at the then-current node, this is all fine. If you need to be able to affect other parts of the overall tree, however, then a breadth-first traversal probably is not appropriate for your task.
You said
[I] don't know how to enqueue them properly. Starting with the root [I] can create a Queue but after that if [I] add the children of the root to the queue [I] will lose the children of those new nodes since [I] am modifying the connections in the Queue every time a add a new node.
The key concept here is that membership and position in the queue are separate and independent from membership and position in the tree. You could manage that by adding additional links to the node structures themselves, or by creating a new structure for the queue elements that contains a pointer to the enqueued BST node. The latter decouples the tree from the queue, which many, including me, would consider preferable for most purposes.
I have to solve the "rush hour puzzle" by iterative deepening algorithm. I have read a lot of topics here on stackoverflow and also on the internet. I think that I understand the iterative deepening algorithm. Basically you just go deeper into the tree and try to find the solution.
I figured that I need to create a graph or a tree from the puzzle, but I really don't have an idea how. Also, if I would have the tree, then how would I tell if something is a valid move or a final state?
There were answers that the nodes should be possible moves and the edges are between the nodes that can be reached in one move. I can imagine this, but somehow I'm getting trouble in see how this can be useful or better yet how can this solve the problem.
Please help me, I'm not asking for complete solution or code sample, I just need some easy explanation of the problem.
There is a reason you need to use the deepening algorithm. Imagine you name each car A, B, C, D... The root node of your tree is the initial board state. Now, move car A. You go down one node in the tree. Move car A back. You are at the initial state, but you made two moves to get here, so you are two nodes down the tree. Repeat over and over. You will never hit a final state.
The root node of your tree is the initial board state. Given that node, add a child node to it for every possible valid move. So, each child node will be what the initial tree looks like after one move. Now, for each of those child nodes, do the same thing: make a child node where each node is one move off the original child node.
Eventually, you will hit a solution to the puzzle. When that happens, you print the moves from the root node to the solution child node and quit. This algorithm ensures that you find a solution with the least number of moves.
My question is : how do you read the version of a (child) frozen node?
More details :
- Lets imagine the following situation : node A has two children node B and node C.
- All three nodes are versionable nodes (have the mixin type)
- Let's say node A has 7 versions from 1.0 to 1.6 : at version 1.2 we added node B, at version 1.4 we added node C.
I have a routine that prints the "output" of node A at version 1.5.
//I already obtained the Version object version associated to node A version 1.5
NodeIterator nodeIterator = version.getNodes();
while (nodeIterator.hasNext()) {
Node currentNode = nodeIterator.nextNode();
System.out.println("Node: "+currentNode.getPath());
// I can see that some of the nodes correspond to children (versions) of
//node B and C ..how can I get their version?
}
Thank you.
Each version in the history of the parent will contain a "frozen node" that represents a snapshot of the parent as it existed when the version was created (e.g., when the parent node was checked in). This frozen node contains child nodes that are either snapshots of the child (if the child was not versionable) or a "nt:versionedChild" node (if the child was versionable). This "nt:versionedChild" node contains a single "jcr:childVersionHistory" REFERENCE property that points to the version history of the child.
Section 3.13.10 of the JSR-283 specification contains a pretty good diagram that shows this structure.
Note that the "nt:versionedChild" node does not point to the particular version in the child's version history, which means that you have to determine which version of the child existed at the time the parent was checked in. After all, in this case of a versionable child, the parent and child version histories are independent and the nodes are checked in independently. (The reason might also stem from the fact that the application can change both the parent and child nodes in a single session, and then either check the parent in followed by checking the child in, or checking the child in followed by checking the parent in.)
One way to do this is by looking at the creation date of each version in the child's version history. This isn't ideal, as it will only tell you which child version existed at the time the parent was created. This could be ambiguous, since the comparison of timestamps depends on whether the parent was checked in before or after the versioned child. Within your application, you might have conventions that help you get around these ambiguities.
Perhaps a better option is to use version labels and apply the same label to the parent version and child version. (This is probably easier to do just after checking in the nodes rather than at a later time.) Then once you have a particular version of the parent, obtain its label and use it to find the corresponding version of the child in the child's version history (using VersionHistory.getVersionByLabel(String)).
Question: how can we display tree nodes level by level ?. could you please give me time and space efficient solution .
Example :
A
/ \
B C
/ \ / \
D E F G
void PrintTree(struct tree *root);
Output:
You have to print tree nodes level by level
A
B C
D E F G
If you're feeling brutish, and want to think very simply about the level you are at...
You will need:
Two queues
A slight twist on Jack's approach
So, start with root.
Tack its children onto the first queue.
Step through them, tacking their children onto the second queue as you go.
Switch to the second queue, step through, pushing their children onto the first queue.
Wax on, wax off.
Really it's just a slight expansion of the same idea, the breadth first search or sweep, which is worth thinking about as a pattern, since it applies to a variety of data structures. Almost anything that's a tree or trie, and a few things that aren't, in fact!
To save space and time on SO:
http://thecodecracker.com/c-programming/bfs-and-dfs/
This kind of visit is called Breadth-first or Level Order. You can see additional infos here.
Basically you
first visit the current node
then all the children of that node
then all the children of every children and so on
This should be achieved easily with a FIFO structure:
push the root
until queue is empty
take first element, visit it, and push all its children to the end of the queue
repeat