Search code examples
graphtinkerpop

What are Binary Graphs?


I came across this term while going through Apache TinkerPop documentation

When modeling a graph in a computer and applying it to modern data sets and practices, the generic mathematically-oriented, binary graph is extended to support both labels and key/value properties

Googling "Binary Graph" returns definition of a "Binary Tree" which doesn't seem to fit the context here.


Solution

  • Binary Graph is a graph data representation of a Binary Tree. Take the below Graph data (https://gremlify.com/scb244l635i) where each node can have left or right children.

    g.addV('node').as('1').property(single, 'data', 22).
      addV('node').as('2').property(single, 'data', 16).
      addV('root').as('3').property(single, 'data', 9).
      addV('node').as('4').property(single, 'data', 5).
      addV('node').as('5').property(single, 'data', 2).
      addV('node').as('6').property(single, 'data', 11).
      addV('node').as('7').property(single, 'data', 15).
      addV('node').as('8').property(single, 'data', 10).
      addV('node').as('9').property(single, 'data', 1).
      addV('node').as('10').property(single, 'data', 8).
      addE('left').from('1').to('2').
      addE('left').from('3').to('4').
      addE('right').from('3').to('6').
      addE('left').from('4').to('5').
      addE('right').from('4').to('10').
      addE('left').from('5').to('9').
      addE('left').from('6').to('8').
      addE('right').from('6').to('7').
      addE('right').from('7').to('1')
    

    enter image description here

    Conditions:

    1. Each node can have only one parent node.
    2. Each node can have at most 2 children (left and right) nodes.