Why arangodb breadth first traversal is not ordered node from left to right?

39 views
Skip to first unread message

Frank Russell

unread,
Mar 19, 2017, 2:12:34 AM3/19/17
to ArangoDB
I have a tree like this


|   |   |   | A |   |   |
|---|---|---|---|---|---|
|   | B |   | C | D | E |
| F | G | H |   |   |   |


edge collection:
[
 
{
   
"_key": "1",
   
"_from": "columns/0",
     
"_to": "columns/1"
 
},
 
{
   
"_key": "2",
   
"_from": "columns/1",
   
"_to": "columns/2"
 
},
 
{
   
"_key": "3",
   
"_from": "columns/1",
     
"_to": "columns/3"
 
},
 
{
   
"_key": "4",
   
"_from": "columns/1",
   
"_to": "columns/4"
 
},
 
{
   
"_key": "5",
   
"_from": "columns/1",
     
"_to": "columns/5"
 
},
 
{
   
"_key": "6",
   
"_from": "columns/2",
   
"_to": "columns/6"
 
},
 
{
   
"_key": "7",
   
"_from": "columns/2",
     
"_to": "columns/7"
 
},
 
{
   
"_key": "8",
   
"_from": "columns/2",
   
"_to": "columns/8"
 
}
]


I query using:
FOR v,e,p IN 1..3 OUTBOUND "columns/0" `bfs` OPTIONS {"bfs": true} RETURN v.title

result:
[ "A",  "D",  "E",  "C",  "B",  "G",  "H",  "F"]

Why not? [ "A",  "B",  "C",  "D",  "E",  "F",  "G",  "H"]

Is it possible to return node from left to right without sort by e._key?


mpv1989

unread,
Mar 24, 2017, 5:22:22 AM3/24/17
to ArangoDB
The order of breadth first within one depth is not guaranteed.

You will always get `A` first and then `B`,`C`,`D`,`E` in any order followed by `F`,`G`,`H` in any order.
The only way to get the node's in your preferred order is by using `sort`.
Reply all
Reply to author
Forward
0 new messages