Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Sandbox

Post History

66%
+2 −0
Sandbox The Tannenbaum series

posted 4y ago by Lundin‭

Article code-golf
#1: Initial revision by user avatar Lundin‭ · 2020-12-16T12:17:37Z (about 4 years ago)
The Tannenbaum series
A series of 7 single digits, that if added in sequence to create an unbalanced [binary search tree](https://en.wikipedia.org/wiki/Binary_search_tree), is considered a _Tannenbaum series_, in case:

- the left branch of the root has depth 3 and consists of ever-increasing numbers, and 
- the right branch of the root has depth 3 and consists of ever-decreasing numbers, and
- it contains no duplicate digits.

Example: 4123765

          4
       /     \              
      /       \              
     /         \ 
    1           7
     \         /
      2       6
       \     /
        3   5

Such a Tannenbaum series can be drawn using _Tannenbaum search tree_ notation:

```
        4
       / \
      /   \
     /     \
    1_     _7
     /     \
    /       \
   /         \
  2_         _6
   /         \
  /           \
 /             \
3_______________5
```

This tree can be said to have [O(Tannenbaum log _n_)](https://www.german-way.com/history-and-culture/german-language/german-christmas-carols/o-tannenbaum/) search efficiency. 

---

The task:

Write a program that takes a 7 digit sequence as input and determines if the 7 digits form a Tannenbaum series, then draws a valid Tannenbaum tree as proof. In case the series is invalid, the program gives no output.

The input can be assumed to be correct and containing no duplicates. The implementation can choose if to take the input either as integer or as a string. This is code golf, shortest source code per language wins.

Valid examples:  

    4123765
    5234876

Invalid examples:

    1234567
    4321765
    4123567