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

The Tannenbaum series

+2
−0

A series of 7 single digits, that if added in sequence to create an unbalanced 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) 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
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

General comments (8 comments)