Group Abstract Group Abstract

Message Boards Message Boards

0
|
303 Views
|
4 Replies
|
4 Total Likes
View groups...
Share
Share this post:

How to generate a "triangular" graph for arbitrary given depth?

Posted 13 days ago

I am looking for a way to generate a "triangular" graph of the following shape for arbitrary given depth, with vertices at positions similar to the numbers in Pascal's triangle, and vertical edges only:

Graph[{1 -> 2, 1 -> 3, 2 -> 4, 2 -> 5, 3 -> 5, 3 -> 6, 4 -> 7, 4 -> 8,
   5 -> 8, 5 -> 9, 6 -> 9, 6 -> 10}, VertexLabels -> Automatic]

enter image description here

I was unsuccessful in using any of the parametric graphs available in Mathematica.

Thank you for any hints you might provide.

4 Replies
Posted 11 days ago

Another way:

With[
 {d = 5},
 Graph[
  Flatten[
   BlockMap[Inner[Rule, #[[1]], Partition[#[[2]], 2, 1], List] &, 
    TakeList[Range[d (d + 1)/2], Range[d]], 2, 1]],
  VertexLabels -> Automatic]]
POSTED BY: Eric Rimbey

Thank you, Eric. Your post contained commands (TakeList, Rule, BlockMap) that were new for me. I used your suggestion to construct a SparseArray whose AdjacencyMatrix is the requested graph.



				
					

Michael, thank you for the elegant solution that you had provided to my question. It took me some time to digest, but I have learned a lot about postfix notation and pure function use.

Matthias

One way:

Block[{n = 6}, (* n >= 1 *)
  Flatten@Table[
    {Thread[DirectedEdge[
       k (k - 1)/2 // Range[1 + #, # + k] &,
       k (k + 1)/2 // Range[1 + #, # + k] &]
      ],
     Thread[DirectedEdge[
       k (k - 1)/2 // Range[1 + #, # + k] &,
       k (k + 1)/2 // Range[2 + #, # + k + 1] &]
      ]}, {k, n - 1}]
  ] // Graph[#, VertexLabels -> Automatic] &
POSTED BY: Michael Rogers
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard