Tree Printout with 29 elements

This algorithm is essentially a map function which, given an output line number, determines the array index to be output on that line, and what row to put it in.

The bit highlighted in red is the bit that was set in the last increment (i.e. n AND NOT (n - 1), where n is the current line number). Note how its position relates to which row that line is placed into.

The bits highlighted in black are the bits to the left (more significant) of the red bit, and represent the row index.

The array index is calculated by adding the row base to the row index. The row base is 2^(n-1) - 1, where n is the row number.

In the included implementation of this algorithm, rows are differentiated by tab (\t) characters.

Line (Dec)Line (Bin)Row 1Row 2Row 3Row 4Row 5
1000010: 15
2000100: 7
3000111: 16
4001000: 3
5001012: 17
6001101: 8
7001113: 18
8010000:1
9010014: 19
10010102: 9
11010115: 20
12011001: 4
13011016: 21
14011103: 10
15011117: 22
16100000: 0
17100018: 23
18100104: 11
19100119: 24
20101002: 5
211010110: 25
22101105: 12
231011111: 26
24110001: 2
251100112: 27
26110106: 13
271101113: 28
28111003: 6
2911101
30111107: 14
3111111