Im doing a research about binary trees and there is a question I couldn't find the answer to.
Can a root in a binary tree have zero children? Like if we had a tree containing only one node (the root) can we call it a binary tree?
In computer science, a binary tree is a tree data structure in which each node has at most two children, which are referred to as the left child and the right child.
With this concept:
Because in case 2, the tree have two null childs.
Related
https://raw.githubusercontent.com/saurabhkumar1903/neo4j/master/alterFile/sampletestoutput1.csv
here's the link to an image showning my expected output:[https://i.imgur.com/x6CYdfU.jpg] I've drawn it on paper just to show the expected output.
[I have a csv file containing a list of nodes where each line denotes a relationship of node at line[0] with every other list of nodes line2,line2,line[3].....line[4500] in that line]
eg.
1,3,4,5,7,8
2,4,5,11
4,10,11,15
here node at
line[0] i.e. "1" has a directed relationship with
nodes at line[2] i.e "3" as a friend,
nodes at line[4], i,e."4" as a friend,
nodes at line[6], i,e."5" as a friend,
what i am trying to do is I want to show a graph in neo4j dipicting the suggested friend relationship among each nodes.
what I cannot figure out is how to iterate the whole csv file as well as capture the relationship among each nodes on each line of csv file.
If you want to ensure there is a HAS_FRIEND relationship between a person whose id comes first (in line) and the people whose ids come afterwards (in the same line), something like this should work:
LOAD CSV FROM 'file:///friends.csv' AS line
MERGE (p:Person {id: TOINT(line[0])})
FOREACH(id IN line[1..] |
MERGE(f:Person {id: TOINT(id)})
MERGE (p)-[:HAS_FRIEND]-(f))
This query presumes that you only want a single HAS_FRIEND relationship between any 2 nodes. Therefore, the MERGE for the relationship does not specify a direction. That way, if there is already such a relationship in either direction, no new relationship is created.
Also, the TOINT function is used to convert the id values to integers (since LOAD CSV automatically treats all values as strings). If you don't need that conversion, then you can remove the function calls.
XML tree data
<EMPLOYEEDATAROOT>
<id></id>
<EMPLOYEE>
<EmployeeId></EmployeeId>
<user_id></user_id>
<Basic_information>
<fname></fname>
<lname></lname>
...
...
</Basic_information>
</EMPLOYEE>
is flattened and stored in a table like this.
Type of SPACE means the node has no children.
Type of 'A' means the node has children.
And Hier represents hierarchy.
Now, I need to respond to an incoming HTTP get request with a nested JSON structure of this data. To create JSON, i need a structure.
I started using RTTI. But, since each work area is different - one work area can just be a node, another can just have one level of children, the next one can have grandchildren etc. RTTI is not entirely possible - or I don't know how to use it.
Any ideas here would be helpful.
You do not need to generate a data structure. Use a JSON writer to render the output that you create using object-oriented rendering. This example shows how to create a document dynamically and render it as XML; it should be trivial to adapt the sample program to use a JSON writer.
I have an object model with a parent -> children relation:
class diagram
The relation is a composition, a parent can have multiple children, a child has always one parent and cannot live without its parent. To persist this data, we serialize it into JSON and use a NoSQL document database (MongoDB) to store it:
{
"id": 123456,
"Attr1": "I'm a parent",
"children": [
{
"Attr1": "I'm a child"
},
{
"Attr1": "I'm another child"
}
]
}
Now we are trying to map this model to an OData EDM. We map the parent objects as an entity type. Because the children cannot live on their own but are rather part of the parent we did not want them as entity type but more like a complex type.
When using OData 2, I am having a hard time, because OData 2 seems to not know about collections of primitive or complex types. As soon as you need to map a "to many" relation, it seems necessary to define the "many"-side of the relation as an entity type in its own right. But when defining the children in my model as an entity type, OData2 requires to be able to address these children on service root level.
So the canonical URL of the following object
httX://host/serviceroot/Parent(1)/Child(2)
really is something like this:
httX://host/serviceroot/Child(1,2)
See documentation of OData2:
"For OData services conformant with the addressing conventions in this section, the canonical form of an absolute URI identifying a single Entry is formed by adding a single path segment to the service root URI. The path segment is made up of the name of the Collection associated with the Entry followed by the key predicate identifying the Entry within the Collection. For example the URIs httX://services.odata.org/OData/OData.svc/Categories(1)/Products(1) and httX://services.odata.org/OData/OData.svc/Products(1) represent the same Entry, but the canonical URI for the Entry is httX://services.odata.org/OData/OData.svc/Products(1)."
http://www.odata.org/documentation/odata-version-2-0/uri-conventions/
For me, OData 2 seems to fit for relational databases, where when objects are connected with a "to many" relation, they are mapped to different tables and every object therefor has its own primary key. In this case, it is easy to address a child object on service root level (httX://host/serviceroot/Child(48346954) (where 48346954 is the DB primary key)) because you can fetch that object directly with SQL means.
However, OData2 seems not to fit for document databases which can store nested object graps as documents (e.g. JSON). Child objects do not need to be independent documents but are rather nested in the parent document. When mapping this to OData and then address a concrete child, you would need to first find the document in which this child is embedded and from there traverse the object graph to the child. A direct fetch of an embedded child is not possible.
What do you think, am I right when stating that OData 2 does not really fit a document oriented database?
When using OData 4, things change a bit, because OData 4 knows about collections of complex types. So may be I can model my children as complex types. Then I have the "to many" relation of parent to its children as a property of the parent with type "complex collection". Would this be the recommendet way to model dependent and nested child objects?
Is OData 4 better suited to map documents from a document oriented database to a REST interface? Has anyone tried it? Or are there more pitfalls I currently do not see and that make OData 4 not a good choice in my case?
I probably don't understand the JSON format enough but here goes. I have a graph whose values are based on a database that keeps a node id, which node is following that node and which node is followed by that node. The graph requires a JSON format as follows:
nodes: ["1","2","3","4","5","6","7","8","9","10",],edges: [["1","7"],["2","3"],["1","4"],["7","1"],["4","3"],["5","3"],["4","8"],["9","1"],["3","2"],["5","2"],["9","4"],["5","80"],["8","4"]}
where the nodes are drawn as a node and the edges are the id of the source node and the target node so they can be connected up with a line.
However I would also like to be able to manipulate the characteristics of the node using javascript, based on other fields in a record. For example I have a field called size and I would eventually like to change the node colour based on that (each node has one size value).
The problem I have is how to carry the information of eg size in the same JSON as nodes and edges. The graph requires nodes and edges to be rendered. Obviously if I'm going to carry the size field as well it would need to be associated with the node rather than as another array. Is there a way of doing this in JSON?
Well, you just have to handle your data as "objects"... Then you give them properties (like ID and SIZE) and you get them with . in js.
For example, you should declare your "array" like an array of objects, like this :
var nodes = [{id:"1",size:"big"},{id:"2",size:"small"},{id:"3",size:"huge"},{id:"4",size:"tiny"},{id:"5",size:"normal"}];
Then handle it with :
console.log(nodes[n].id);
console.log(nodes[n].size);
Have a look at this fiddle (and look at console) :
http://jsfiddle.net/0vkg3tt9/3/
Hope it helps
Is there a VB.NET equivalent to java.util.TreeSet?
The closest you'll find is the SortedSet(T) class.
Strangely, the .NET FCL does not include tree-bases data structures/collections. You can implement your own though. See here for a C# example (easy enough to convert to VB.NET)
The C5 Library is a well-regarded project that:
... provides the
following data structures, described
by C# classes: array list, doubly
linked list, hash-indexed array list,
hash-indexed linked list, hash set,
hash bag (multiset), sorted array,
wrapped array, tree set, tree bag
(multiset), stack, double-ended queue,
circular queue, priority queue
(interval heap), hash dictionary, and
tree dictionary.
C5 is also C#-based but it does come as a DLL so you wouldn't even have to worry about the language. Just reference it in your solution and off you go.
There's nothing built-in, but you could use the TreeSet<T> implementation from the C5 library. This sounds as though it's roughly equivalent, although I haven't used it myself.