Write The Shortest Program to Calculate Height of a Binary TreeTips for golfing in CFree a Binary TreePrint a Binary TreeEnumerate all binary trees with n nodesFind a binary tree's deepest nodeConvert binary search tree into ordered linked listPrint a non-clashing binary search treeTree traversingCompute the height of a radix treeRooting for Trees With the Right NodesBinary tree rotations

Is an "are" omitted in this sentence

HackerRank Implement Queue using two stacks Solution

How were x-ray diffraction patterns deciphered before computers?

Lower bound for the number of lattice points on high dimensional spheres

What does Argus Filch specifically do?

Why do my fried eggs start browning very fast?

Why did the United States not resort to nuclear weapons in Vietnam?

What is the reason behind water not falling from a bucket at the top of loop?

Being told my "network" isn't PCI compliant. I don't even have a server! Do I have to comply?

Skipping same old introductions

Export economy of Mars

Unlocked Package Dependencies

In MTG, was there ever a five-color deck that worked well?

(7 of 11: Fillomino) What is Pyramid Cult's Favorite Shape?

Does a bard know when a character uses their Bardic Inspiration?

Does WSL2 runs Linux in a virtual machine or alongside windows Kernel?

How does Rust's 128-bit integer `i128` work on a 64-bit system?

Partial Fractions: Why does this shortcut method work?

Can an unintentional murderer leave Ir Miklat for Shalosh Regalim?

Can there be multiple energy eigenstates corresponding to the same eigenvalue of a Hamiltonian (Pauli-X)?

Phase portrait of a system of differential equations

Why are sugars in whole fruits not digested the same way sugars in juice are?

Can I say "Gesundheit" if someone is coughing?

Is there any difference between "result in" and "end up with"?



Write The Shortest Program to Calculate Height of a Binary Tree


Tips for golfing in CFree a Binary TreePrint a Binary TreeEnumerate all binary trees with n nodesFind a binary tree's deepest nodeConvert binary search tree into ordered linked listPrint a non-clashing binary search treeTree traversingCompute the height of a radix treeRooting for Trees With the Right NodesBinary tree rotations






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








4












$begingroup$


The height of a binary tree is the distance from the root node to the node child that is farthest from the root.



Below is an example:



 2 <-- root: Height 1
/
7 5 <-- Height 2
/
2 6 9 <-- Height 3
/ /
5 11 4 <-- Height 4


Height of binary tree: 4



Definition of a Binary Tree



A tree is an object that contains a signed integer value and either two other trees or pointers to them.



The structure of the binary tree struct looks something like the following:



typedef struct tree

struct tree * l;

struct tree * r;

int v;

tree;


The challenge:



Input



The root of a binary tree



Output



The number that represents the height of a binary tree



Assuming you are given the root of a binary tree as input, write the shortest program that calculates the height of a binary tree and returns the height. The program with least amount of bytes (accounting whitespaces) wins.










share|improve this question









New contributor



T. Salim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$









  • 2




    $begingroup$
    What do languages without pointers take?
    $endgroup$
    – Jonathan Allan
    8 hours ago






  • 3




    $begingroup$
    ...but then my tree object could just have a property, say h. Might be better to define a specific structure made just of lists for the purpose of this challenge.
    $endgroup$
    – Jonathan Allan
    8 hours ago






  • 4




    $begingroup$
    @T.Salim In the future, please consider posting in the sandbox first.
    $endgroup$
    – wizzwizz4
    7 hours ago






  • 1




    $begingroup$
    So, is a valid representation a list of length 3 [root_value, left_node, right_node] where each of left_node and right_node are also binary trees acceptable? It'll be trivial in many languages, but might be fun in some others.
    $endgroup$
    – Jonathan Allan
    7 hours ago






  • 2




    $begingroup$
    Can you edit the question to include what constitutes a valid binary structure? Perhaps a definition like a tree is an object that contains a value and either two other trees or pointers to them. A definition that is inclusive of languages without objects would also be nice too.
    $endgroup$
    – Jo King
    3 hours ago


















4












$begingroup$


The height of a binary tree is the distance from the root node to the node child that is farthest from the root.



Below is an example:



 2 <-- root: Height 1
/
7 5 <-- Height 2
/
2 6 9 <-- Height 3
/ /
5 11 4 <-- Height 4


Height of binary tree: 4



Definition of a Binary Tree



A tree is an object that contains a signed integer value and either two other trees or pointers to them.



The structure of the binary tree struct looks something like the following:



typedef struct tree

struct tree * l;

struct tree * r;

int v;

tree;


The challenge:



Input



The root of a binary tree



Output



The number that represents the height of a binary tree



Assuming you are given the root of a binary tree as input, write the shortest program that calculates the height of a binary tree and returns the height. The program with least amount of bytes (accounting whitespaces) wins.










share|improve this question









New contributor



T. Salim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$









  • 2




    $begingroup$
    What do languages without pointers take?
    $endgroup$
    – Jonathan Allan
    8 hours ago






  • 3




    $begingroup$
    ...but then my tree object could just have a property, say h. Might be better to define a specific structure made just of lists for the purpose of this challenge.
    $endgroup$
    – Jonathan Allan
    8 hours ago






  • 4




    $begingroup$
    @T.Salim In the future, please consider posting in the sandbox first.
    $endgroup$
    – wizzwizz4
    7 hours ago






  • 1




    $begingroup$
    So, is a valid representation a list of length 3 [root_value, left_node, right_node] where each of left_node and right_node are also binary trees acceptable? It'll be trivial in many languages, but might be fun in some others.
    $endgroup$
    – Jonathan Allan
    7 hours ago






  • 2




    $begingroup$
    Can you edit the question to include what constitutes a valid binary structure? Perhaps a definition like a tree is an object that contains a value and either two other trees or pointers to them. A definition that is inclusive of languages without objects would also be nice too.
    $endgroup$
    – Jo King
    3 hours ago














4












4








4


1



$begingroup$


The height of a binary tree is the distance from the root node to the node child that is farthest from the root.



Below is an example:



 2 <-- root: Height 1
/
7 5 <-- Height 2
/
2 6 9 <-- Height 3
/ /
5 11 4 <-- Height 4


Height of binary tree: 4



Definition of a Binary Tree



A tree is an object that contains a signed integer value and either two other trees or pointers to them.



The structure of the binary tree struct looks something like the following:



typedef struct tree

struct tree * l;

struct tree * r;

int v;

tree;


The challenge:



Input



The root of a binary tree



Output



The number that represents the height of a binary tree



Assuming you are given the root of a binary tree as input, write the shortest program that calculates the height of a binary tree and returns the height. The program with least amount of bytes (accounting whitespaces) wins.










share|improve this question









New contributor



T. Salim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$




The height of a binary tree is the distance from the root node to the node child that is farthest from the root.



Below is an example:



 2 <-- root: Height 1
/
7 5 <-- Height 2
/
2 6 9 <-- Height 3
/ /
5 11 4 <-- Height 4


Height of binary tree: 4



Definition of a Binary Tree



A tree is an object that contains a signed integer value and either two other trees or pointers to them.



The structure of the binary tree struct looks something like the following:



typedef struct tree

struct tree * l;

struct tree * r;

int v;

tree;


The challenge:



Input



The root of a binary tree



Output



The number that represents the height of a binary tree



Assuming you are given the root of a binary tree as input, write the shortest program that calculates the height of a binary tree and returns the height. The program with least amount of bytes (accounting whitespaces) wins.







code-golf binary-tree






share|improve this question









New contributor



T. Salim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.










share|improve this question









New contributor



T. Salim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








share|improve this question




share|improve this question








edited 3 hours ago







T. Salim













New contributor



T. Salim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.








asked 8 hours ago









T. SalimT. Salim

476 bronze badges




476 bronze badges




New contributor



T. Salim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




New contributor




T. Salim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • 2




    $begingroup$
    What do languages without pointers take?
    $endgroup$
    – Jonathan Allan
    8 hours ago






  • 3




    $begingroup$
    ...but then my tree object could just have a property, say h. Might be better to define a specific structure made just of lists for the purpose of this challenge.
    $endgroup$
    – Jonathan Allan
    8 hours ago






  • 4




    $begingroup$
    @T.Salim In the future, please consider posting in the sandbox first.
    $endgroup$
    – wizzwizz4
    7 hours ago






  • 1




    $begingroup$
    So, is a valid representation a list of length 3 [root_value, left_node, right_node] where each of left_node and right_node are also binary trees acceptable? It'll be trivial in many languages, but might be fun in some others.
    $endgroup$
    – Jonathan Allan
    7 hours ago






  • 2




    $begingroup$
    Can you edit the question to include what constitutes a valid binary structure? Perhaps a definition like a tree is an object that contains a value and either two other trees or pointers to them. A definition that is inclusive of languages without objects would also be nice too.
    $endgroup$
    – Jo King
    3 hours ago













  • 2




    $begingroup$
    What do languages without pointers take?
    $endgroup$
    – Jonathan Allan
    8 hours ago






  • 3




    $begingroup$
    ...but then my tree object could just have a property, say h. Might be better to define a specific structure made just of lists for the purpose of this challenge.
    $endgroup$
    – Jonathan Allan
    8 hours ago






  • 4




    $begingroup$
    @T.Salim In the future, please consider posting in the sandbox first.
    $endgroup$
    – wizzwizz4
    7 hours ago






  • 1




    $begingroup$
    So, is a valid representation a list of length 3 [root_value, left_node, right_node] where each of left_node and right_node are also binary trees acceptable? It'll be trivial in many languages, but might be fun in some others.
    $endgroup$
    – Jonathan Allan
    7 hours ago






  • 2




    $begingroup$
    Can you edit the question to include what constitutes a valid binary structure? Perhaps a definition like a tree is an object that contains a value and either two other trees or pointers to them. A definition that is inclusive of languages without objects would also be nice too.
    $endgroup$
    – Jo King
    3 hours ago








2




2




$begingroup$
What do languages without pointers take?
$endgroup$
– Jonathan Allan
8 hours ago




$begingroup$
What do languages without pointers take?
$endgroup$
– Jonathan Allan
8 hours ago




3




3




$begingroup$
...but then my tree object could just have a property, say h. Might be better to define a specific structure made just of lists for the purpose of this challenge.
$endgroup$
– Jonathan Allan
8 hours ago




$begingroup$
...but then my tree object could just have a property, say h. Might be better to define a specific structure made just of lists for the purpose of this challenge.
$endgroup$
– Jonathan Allan
8 hours ago




4




4




$begingroup$
@T.Salim In the future, please consider posting in the sandbox first.
$endgroup$
– wizzwizz4
7 hours ago




$begingroup$
@T.Salim In the future, please consider posting in the sandbox first.
$endgroup$
– wizzwizz4
7 hours ago




1




1




$begingroup$
So, is a valid representation a list of length 3 [root_value, left_node, right_node] where each of left_node and right_node are also binary trees acceptable? It'll be trivial in many languages, but might be fun in some others.
$endgroup$
– Jonathan Allan
7 hours ago




$begingroup$
So, is a valid representation a list of length 3 [root_value, left_node, right_node] where each of left_node and right_node are also binary trees acceptable? It'll be trivial in many languages, but might be fun in some others.
$endgroup$
– Jonathan Allan
7 hours ago




2




2




$begingroup$
Can you edit the question to include what constitutes a valid binary structure? Perhaps a definition like a tree is an object that contains a value and either two other trees or pointers to them. A definition that is inclusive of languages without objects would also be nice too.
$endgroup$
– Jo King
3 hours ago





$begingroup$
Can you edit the question to include what constitutes a valid binary structure? Perhaps a definition like a tree is an object that contains a value and either two other trees or pointers to them. A definition that is inclusive of languages without objects would also be nice too.
$endgroup$
– Jo King
3 hours ago











9 Answers
9






active

oldest

votes


















4












$begingroup$


Jelly, 3 bytes



ŒḊ’


A monadic Link accepting a list representing the tree: [root_value, left_tree, right_tree], where each of left_tree and right_tree are similar structures (empty if need be), which yields the height.



Try it online!



How?



Pretty trivial in Jelly:



ŒḊ’ - Link: list, as described above
ŒḊ - depth
’ - decremented (since leaves are `[value, [], []]`)





share|improve this answer











$endgroup$














  • $begingroup$
    Jonathon Allen, that is an interesting language you are using. As a newcomer, may you provide a link or a website referral that tutors people how to use Jelly?
    $endgroup$
    – T. Salim
    7 hours ago






  • 1




    $begingroup$
    Click the link in the header - it's a golfing Language developed by Dennis, one of the site's moderators.
    $endgroup$
    – Jonathan Allan
    7 hours ago







  • 2




    $begingroup$
    I wonder how controversial it would be to represent a leaf as x instead of [x, [], []]...
    $endgroup$
    – Erik the Outgolfer
    7 hours ago










  • $begingroup$
    @EriktheOutgolfer To keep with the "pointer" and "struct" nature of the question I think every node should be of the same form.
    $endgroup$
    – Jonathan Allan
    7 hours ago



















3












$begingroup$


Python 2,  35  33 bytes



Thanks to Arnauld for noicing an oversight and saving 4.





f=lambda a:a>[]and-~max(map(f,a))


A recursive function accepting a list representing the tree: [root_value, left_tree, right_tree], where each of left_tree and right_tree are similar structures (empty if need be), which returns the height.



Try it online!



Note that [] will return False, but in Python False==0.






share|improve this answer











$endgroup$














  • $begingroup$
    The same person is allowed to give two different answers to the same question?
    $endgroup$
    – T. Salim
    7 hours ago






  • 2




    $begingroup$
    Yeah, of course, golf is a competition at a language level. Even a second entry in the same language is sometimes acceptable, if the approach is very different.
    $endgroup$
    – Jonathan Allan
    7 hours ago










  • $begingroup$
    @Arnauld Guess so (I'd assumed non-integers might be present for some reason)
    $endgroup$
    – Jonathan Allan
    6 hours ago



















2












$begingroup$

JavaScript (ES6),  35  33 bytes



Input structure: [[left_node], [right_node], value]





f=([a,b])=>a?1+f(f(a)>f(b)?a:b):0


Try it online!



Commented



f = // f is a recursive function taking
([a, b]) => // a node of the tree split into
// a[] = left child, b[] = right child (the value is ignored)
a ? // if a[] is defined:
1 + // increment the final result for this branch
f( // and add:
f(a) > f(b) ? a : b // f(a) if f(a) > f(b) or f(b) otherwise
) //
: // else:
0 // stop recursion and return 0





share|improve this answer











$endgroup$














  • $begingroup$
    Looks like you can save a byte with a&&-~.
    $endgroup$
    – Shaggy
    2 hours ago










  • $begingroup$
    @Shaggy That would lead to comparisons with undefined.
    $endgroup$
    – Arnauld
    2 hours ago



















1












$begingroup$

Haskell, 33 bytes



h L=0 
h(N l r _)=1+max(h l)(h r)


Using the custom tree type data T = L | N T T Int, which is the Haskell equivalent of the C struct given in the challenge.



Try it online!






share|improve this answer









$endgroup$






















    1












    $begingroup$


    Perl 6, 30 bytes





    +$_&&1+max map &?BLOCK,.[^2]


    Try it online!



    Input is a 3-element list (l, r, v).






    share|improve this answer









    $endgroup$














    • $begingroup$
      The &?BLOCK trick is interesting but it's a couple of bytes shorter to assign the block to $!
      $endgroup$
      – Jo King
      3 hours ago










    • $begingroup$
      @JoKing I don't know. Storing the challenge solution in a volatile global like $! or $/ feels like cheating to me.
      $endgroup$
      – nwellnhof
      3 hours ago


















    1












    $begingroup$

    C, 43 bytes



    h(T*r)r=r?1+(int)fmax(h(r->l),h(r->r)):0;


    Structure of binary tree is the following:



    typedef struct tree

    struct tree * l;

    struct tree * r;

    int v;

    tree;





    share|improve this answer










    New contributor



    T. Salim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





    $endgroup$










    • 1




      $begingroup$
      55 bytes Try it online! Some C-specific golfing tricks are here!
      $endgroup$
      – ErikF
      5 hours ago






    • 1




      $begingroup$
      @ErikF Or 45 bytes
      $endgroup$
      – Arnauld
      4 hours ago










    • $begingroup$
      Thanks ErikF and Arnauld. I should try out the ternary operator more often instead of if-else-if chains.
      $endgroup$
      – T. Salim
      4 hours ago






    • 2




      $begingroup$
      43 bytes
      $endgroup$
      – nwellnhof
      4 hours ago






    • 2




      $begingroup$
      If your submission relies on flags, can you please add them to the header of your submission?
      $endgroup$
      – Jo King
      3 hours ago


















    0












    $begingroup$

    Scheme, 72 Bytes



    (define(f h)(if(null? h)0(+ 1(max(f(car(cdr h)))(f(car(cdr(cdr h))))))))


    More Readable Version:



    (define (f h)
    (if (null? h)
    0
    (+ 1
    (max
    (f (car (cdr h)))
    (f (car (cdr (cdr h))))
    )
    )
    )
    )


    Using lists of the form (data, left, right) to represent a tree. E.g.



     1
    /
    2 3
    /
    4 5

    is represented as: (1 (2 (4 () ()) (5 () ())) (3 () ())

    (1
    (2
    (4 () ())
    ``` (5 () ())
    (3 () ())
    )


    Try it Online!






    share|improve this answer











    $endgroup$






















      0












      $begingroup$


      Charcoal, 29 bytes



      ⊞θ⁰⊞υθFυ«≔⊕⊟ιθFΦι∧κλ⊞υ⊞Oκθ»Iθ


      Try it online! Link is to verbose version of code. Temporarily modifies the tree during processing. Explanation:



      ⊞θ⁰


      Push zero to the root node.



      ⊞υθ


      Push the root node to the list of all nodes.



      Fυ«


      Perform a breadth-first search of the tree.



      ≔⊕⊟ιθ


      Get the depth of this node.



      FΦι∧κλ


      Loop over any child nodes.



      ⊞υ⊞Oκθ


      Tell the child node its parent's depth and push it to the list of all nodes.



      »Iθ


      Once all the nodes have been traversed print the depth of the last node. Since the traversal was breadth-first, this will be the height of the tree.






      share|improve this answer









      $endgroup$






















        0












        $begingroup$


        Japt, 9 bytes



        Ω¡ÒßXÃrw


        Try it






        share|improve this answer









        $endgroup$

















          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "200"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          T. Salim is a new contributor. Be nice, and check out our Code of Conduct.









          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f189220%2fwrite-the-shortest-program-to-calculate-height-of-a-binary-tree%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          9 Answers
          9






          active

          oldest

          votes








          9 Answers
          9






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          4












          $begingroup$


          Jelly, 3 bytes



          ŒḊ’


          A monadic Link accepting a list representing the tree: [root_value, left_tree, right_tree], where each of left_tree and right_tree are similar structures (empty if need be), which yields the height.



          Try it online!



          How?



          Pretty trivial in Jelly:



          ŒḊ’ - Link: list, as described above
          ŒḊ - depth
          ’ - decremented (since leaves are `[value, [], []]`)





          share|improve this answer











          $endgroup$














          • $begingroup$
            Jonathon Allen, that is an interesting language you are using. As a newcomer, may you provide a link or a website referral that tutors people how to use Jelly?
            $endgroup$
            – T. Salim
            7 hours ago






          • 1




            $begingroup$
            Click the link in the header - it's a golfing Language developed by Dennis, one of the site's moderators.
            $endgroup$
            – Jonathan Allan
            7 hours ago







          • 2




            $begingroup$
            I wonder how controversial it would be to represent a leaf as x instead of [x, [], []]...
            $endgroup$
            – Erik the Outgolfer
            7 hours ago










          • $begingroup$
            @EriktheOutgolfer To keep with the "pointer" and "struct" nature of the question I think every node should be of the same form.
            $endgroup$
            – Jonathan Allan
            7 hours ago
















          4












          $begingroup$


          Jelly, 3 bytes



          ŒḊ’


          A monadic Link accepting a list representing the tree: [root_value, left_tree, right_tree], where each of left_tree and right_tree are similar structures (empty if need be), which yields the height.



          Try it online!



          How?



          Pretty trivial in Jelly:



          ŒḊ’ - Link: list, as described above
          ŒḊ - depth
          ’ - decremented (since leaves are `[value, [], []]`)





          share|improve this answer











          $endgroup$














          • $begingroup$
            Jonathon Allen, that is an interesting language you are using. As a newcomer, may you provide a link or a website referral that tutors people how to use Jelly?
            $endgroup$
            – T. Salim
            7 hours ago






          • 1




            $begingroup$
            Click the link in the header - it's a golfing Language developed by Dennis, one of the site's moderators.
            $endgroup$
            – Jonathan Allan
            7 hours ago







          • 2




            $begingroup$
            I wonder how controversial it would be to represent a leaf as x instead of [x, [], []]...
            $endgroup$
            – Erik the Outgolfer
            7 hours ago










          • $begingroup$
            @EriktheOutgolfer To keep with the "pointer" and "struct" nature of the question I think every node should be of the same form.
            $endgroup$
            – Jonathan Allan
            7 hours ago














          4












          4








          4





          $begingroup$


          Jelly, 3 bytes



          ŒḊ’


          A monadic Link accepting a list representing the tree: [root_value, left_tree, right_tree], where each of left_tree and right_tree are similar structures (empty if need be), which yields the height.



          Try it online!



          How?



          Pretty trivial in Jelly:



          ŒḊ’ - Link: list, as described above
          ŒḊ - depth
          ’ - decremented (since leaves are `[value, [], []]`)





          share|improve this answer











          $endgroup$




          Jelly, 3 bytes



          ŒḊ’


          A monadic Link accepting a list representing the tree: [root_value, left_tree, right_tree], where each of left_tree and right_tree are similar structures (empty if need be), which yields the height.



          Try it online!



          How?



          Pretty trivial in Jelly:



          ŒḊ’ - Link: list, as described above
          ŒḊ - depth
          ’ - decremented (since leaves are `[value, [], []]`)






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 7 hours ago

























          answered 7 hours ago









          Jonathan AllanJonathan Allan

          58.2k5 gold badges43 silver badges183 bronze badges




          58.2k5 gold badges43 silver badges183 bronze badges














          • $begingroup$
            Jonathon Allen, that is an interesting language you are using. As a newcomer, may you provide a link or a website referral that tutors people how to use Jelly?
            $endgroup$
            – T. Salim
            7 hours ago






          • 1




            $begingroup$
            Click the link in the header - it's a golfing Language developed by Dennis, one of the site's moderators.
            $endgroup$
            – Jonathan Allan
            7 hours ago







          • 2




            $begingroup$
            I wonder how controversial it would be to represent a leaf as x instead of [x, [], []]...
            $endgroup$
            – Erik the Outgolfer
            7 hours ago










          • $begingroup$
            @EriktheOutgolfer To keep with the "pointer" and "struct" nature of the question I think every node should be of the same form.
            $endgroup$
            – Jonathan Allan
            7 hours ago

















          • $begingroup$
            Jonathon Allen, that is an interesting language you are using. As a newcomer, may you provide a link or a website referral that tutors people how to use Jelly?
            $endgroup$
            – T. Salim
            7 hours ago






          • 1




            $begingroup$
            Click the link in the header - it's a golfing Language developed by Dennis, one of the site's moderators.
            $endgroup$
            – Jonathan Allan
            7 hours ago







          • 2




            $begingroup$
            I wonder how controversial it would be to represent a leaf as x instead of [x, [], []]...
            $endgroup$
            – Erik the Outgolfer
            7 hours ago










          • $begingroup$
            @EriktheOutgolfer To keep with the "pointer" and "struct" nature of the question I think every node should be of the same form.
            $endgroup$
            – Jonathan Allan
            7 hours ago
















          $begingroup$
          Jonathon Allen, that is an interesting language you are using. As a newcomer, may you provide a link or a website referral that tutors people how to use Jelly?
          $endgroup$
          – T. Salim
          7 hours ago




          $begingroup$
          Jonathon Allen, that is an interesting language you are using. As a newcomer, may you provide a link or a website referral that tutors people how to use Jelly?
          $endgroup$
          – T. Salim
          7 hours ago




          1




          1




          $begingroup$
          Click the link in the header - it's a golfing Language developed by Dennis, one of the site's moderators.
          $endgroup$
          – Jonathan Allan
          7 hours ago





          $begingroup$
          Click the link in the header - it's a golfing Language developed by Dennis, one of the site's moderators.
          $endgroup$
          – Jonathan Allan
          7 hours ago





          2




          2




          $begingroup$
          I wonder how controversial it would be to represent a leaf as x instead of [x, [], []]...
          $endgroup$
          – Erik the Outgolfer
          7 hours ago




          $begingroup$
          I wonder how controversial it would be to represent a leaf as x instead of [x, [], []]...
          $endgroup$
          – Erik the Outgolfer
          7 hours ago












          $begingroup$
          @EriktheOutgolfer To keep with the "pointer" and "struct" nature of the question I think every node should be of the same form.
          $endgroup$
          – Jonathan Allan
          7 hours ago





          $begingroup$
          @EriktheOutgolfer To keep with the "pointer" and "struct" nature of the question I think every node should be of the same form.
          $endgroup$
          – Jonathan Allan
          7 hours ago














          3












          $begingroup$


          Python 2,  35  33 bytes



          Thanks to Arnauld for noicing an oversight and saving 4.





          f=lambda a:a>[]and-~max(map(f,a))


          A recursive function accepting a list representing the tree: [root_value, left_tree, right_tree], where each of left_tree and right_tree are similar structures (empty if need be), which returns the height.



          Try it online!



          Note that [] will return False, but in Python False==0.






          share|improve this answer











          $endgroup$














          • $begingroup$
            The same person is allowed to give two different answers to the same question?
            $endgroup$
            – T. Salim
            7 hours ago






          • 2




            $begingroup$
            Yeah, of course, golf is a competition at a language level. Even a second entry in the same language is sometimes acceptable, if the approach is very different.
            $endgroup$
            – Jonathan Allan
            7 hours ago










          • $begingroup$
            @Arnauld Guess so (I'd assumed non-integers might be present for some reason)
            $endgroup$
            – Jonathan Allan
            6 hours ago
















          3












          $begingroup$


          Python 2,  35  33 bytes



          Thanks to Arnauld for noicing an oversight and saving 4.





          f=lambda a:a>[]and-~max(map(f,a))


          A recursive function accepting a list representing the tree: [root_value, left_tree, right_tree], where each of left_tree and right_tree are similar structures (empty if need be), which returns the height.



          Try it online!



          Note that [] will return False, but in Python False==0.






          share|improve this answer











          $endgroup$














          • $begingroup$
            The same person is allowed to give two different answers to the same question?
            $endgroup$
            – T. Salim
            7 hours ago






          • 2




            $begingroup$
            Yeah, of course, golf is a competition at a language level. Even a second entry in the same language is sometimes acceptable, if the approach is very different.
            $endgroup$
            – Jonathan Allan
            7 hours ago










          • $begingroup$
            @Arnauld Guess so (I'd assumed non-integers might be present for some reason)
            $endgroup$
            – Jonathan Allan
            6 hours ago














          3












          3








          3





          $begingroup$


          Python 2,  35  33 bytes



          Thanks to Arnauld for noicing an oversight and saving 4.





          f=lambda a:a>[]and-~max(map(f,a))


          A recursive function accepting a list representing the tree: [root_value, left_tree, right_tree], where each of left_tree and right_tree are similar structures (empty if need be), which returns the height.



          Try it online!



          Note that [] will return False, but in Python False==0.






          share|improve this answer











          $endgroup$




          Python 2,  35  33 bytes



          Thanks to Arnauld for noicing an oversight and saving 4.





          f=lambda a:a>[]and-~max(map(f,a))


          A recursive function accepting a list representing the tree: [root_value, left_tree, right_tree], where each of left_tree and right_tree are similar structures (empty if need be), which returns the height.



          Try it online!



          Note that [] will return False, but in Python False==0.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 6 hours ago

























          answered 7 hours ago









          Jonathan AllanJonathan Allan

          58.2k5 gold badges43 silver badges183 bronze badges




          58.2k5 gold badges43 silver badges183 bronze badges














          • $begingroup$
            The same person is allowed to give two different answers to the same question?
            $endgroup$
            – T. Salim
            7 hours ago






          • 2




            $begingroup$
            Yeah, of course, golf is a competition at a language level. Even a second entry in the same language is sometimes acceptable, if the approach is very different.
            $endgroup$
            – Jonathan Allan
            7 hours ago










          • $begingroup$
            @Arnauld Guess so (I'd assumed non-integers might be present for some reason)
            $endgroup$
            – Jonathan Allan
            6 hours ago

















          • $begingroup$
            The same person is allowed to give two different answers to the same question?
            $endgroup$
            – T. Salim
            7 hours ago






          • 2




            $begingroup$
            Yeah, of course, golf is a competition at a language level. Even a second entry in the same language is sometimes acceptable, if the approach is very different.
            $endgroup$
            – Jonathan Allan
            7 hours ago










          • $begingroup$
            @Arnauld Guess so (I'd assumed non-integers might be present for some reason)
            $endgroup$
            – Jonathan Allan
            6 hours ago
















          $begingroup$
          The same person is allowed to give two different answers to the same question?
          $endgroup$
          – T. Salim
          7 hours ago




          $begingroup$
          The same person is allowed to give two different answers to the same question?
          $endgroup$
          – T. Salim
          7 hours ago




          2




          2




          $begingroup$
          Yeah, of course, golf is a competition at a language level. Even a second entry in the same language is sometimes acceptable, if the approach is very different.
          $endgroup$
          – Jonathan Allan
          7 hours ago




          $begingroup$
          Yeah, of course, golf is a competition at a language level. Even a second entry in the same language is sometimes acceptable, if the approach is very different.
          $endgroup$
          – Jonathan Allan
          7 hours ago












          $begingroup$
          @Arnauld Guess so (I'd assumed non-integers might be present for some reason)
          $endgroup$
          – Jonathan Allan
          6 hours ago





          $begingroup$
          @Arnauld Guess so (I'd assumed non-integers might be present for some reason)
          $endgroup$
          – Jonathan Allan
          6 hours ago












          2












          $begingroup$

          JavaScript (ES6),  35  33 bytes



          Input structure: [[left_node], [right_node], value]





          f=([a,b])=>a?1+f(f(a)>f(b)?a:b):0


          Try it online!



          Commented



          f = // f is a recursive function taking
          ([a, b]) => // a node of the tree split into
          // a[] = left child, b[] = right child (the value is ignored)
          a ? // if a[] is defined:
          1 + // increment the final result for this branch
          f( // and add:
          f(a) > f(b) ? a : b // f(a) if f(a) > f(b) or f(b) otherwise
          ) //
          : // else:
          0 // stop recursion and return 0





          share|improve this answer











          $endgroup$














          • $begingroup$
            Looks like you can save a byte with a&&-~.
            $endgroup$
            – Shaggy
            2 hours ago










          • $begingroup$
            @Shaggy That would lead to comparisons with undefined.
            $endgroup$
            – Arnauld
            2 hours ago
















          2












          $begingroup$

          JavaScript (ES6),  35  33 bytes



          Input structure: [[left_node], [right_node], value]





          f=([a,b])=>a?1+f(f(a)>f(b)?a:b):0


          Try it online!



          Commented



          f = // f is a recursive function taking
          ([a, b]) => // a node of the tree split into
          // a[] = left child, b[] = right child (the value is ignored)
          a ? // if a[] is defined:
          1 + // increment the final result for this branch
          f( // and add:
          f(a) > f(b) ? a : b // f(a) if f(a) > f(b) or f(b) otherwise
          ) //
          : // else:
          0 // stop recursion and return 0





          share|improve this answer











          $endgroup$














          • $begingroup$
            Looks like you can save a byte with a&&-~.
            $endgroup$
            – Shaggy
            2 hours ago










          • $begingroup$
            @Shaggy That would lead to comparisons with undefined.
            $endgroup$
            – Arnauld
            2 hours ago














          2












          2








          2





          $begingroup$

          JavaScript (ES6),  35  33 bytes



          Input structure: [[left_node], [right_node], value]





          f=([a,b])=>a?1+f(f(a)>f(b)?a:b):0


          Try it online!



          Commented



          f = // f is a recursive function taking
          ([a, b]) => // a node of the tree split into
          // a[] = left child, b[] = right child (the value is ignored)
          a ? // if a[] is defined:
          1 + // increment the final result for this branch
          f( // and add:
          f(a) > f(b) ? a : b // f(a) if f(a) > f(b) or f(b) otherwise
          ) //
          : // else:
          0 // stop recursion and return 0





          share|improve this answer











          $endgroup$



          JavaScript (ES6),  35  33 bytes



          Input structure: [[left_node], [right_node], value]





          f=([a,b])=>a?1+f(f(a)>f(b)?a:b):0


          Try it online!



          Commented



          f = // f is a recursive function taking
          ([a, b]) => // a node of the tree split into
          // a[] = left child, b[] = right child (the value is ignored)
          a ? // if a[] is defined:
          1 + // increment the final result for this branch
          f( // and add:
          f(a) > f(b) ? a : b // f(a) if f(a) > f(b) or f(b) otherwise
          ) //
          : // else:
          0 // stop recursion and return 0






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 6 hours ago

























          answered 7 hours ago









          ArnauldArnauld

          89.2k7 gold badges103 silver badges365 bronze badges




          89.2k7 gold badges103 silver badges365 bronze badges














          • $begingroup$
            Looks like you can save a byte with a&&-~.
            $endgroup$
            – Shaggy
            2 hours ago










          • $begingroup$
            @Shaggy That would lead to comparisons with undefined.
            $endgroup$
            – Arnauld
            2 hours ago

















          • $begingroup$
            Looks like you can save a byte with a&&-~.
            $endgroup$
            – Shaggy
            2 hours ago










          • $begingroup$
            @Shaggy That would lead to comparisons with undefined.
            $endgroup$
            – Arnauld
            2 hours ago
















          $begingroup$
          Looks like you can save a byte with a&&-~.
          $endgroup$
          – Shaggy
          2 hours ago




          $begingroup$
          Looks like you can save a byte with a&&-~.
          $endgroup$
          – Shaggy
          2 hours ago












          $begingroup$
          @Shaggy That would lead to comparisons with undefined.
          $endgroup$
          – Arnauld
          2 hours ago





          $begingroup$
          @Shaggy That would lead to comparisons with undefined.
          $endgroup$
          – Arnauld
          2 hours ago












          1












          $begingroup$

          Haskell, 33 bytes



          h L=0 
          h(N l r _)=1+max(h l)(h r)


          Using the custom tree type data T = L | N T T Int, which is the Haskell equivalent of the C struct given in the challenge.



          Try it online!






          share|improve this answer









          $endgroup$



















            1












            $begingroup$

            Haskell, 33 bytes



            h L=0 
            h(N l r _)=1+max(h l)(h r)


            Using the custom tree type data T = L | N T T Int, which is the Haskell equivalent of the C struct given in the challenge.



            Try it online!






            share|improve this answer









            $endgroup$

















              1












              1








              1





              $begingroup$

              Haskell, 33 bytes



              h L=0 
              h(N l r _)=1+max(h l)(h r)


              Using the custom tree type data T = L | N T T Int, which is the Haskell equivalent of the C struct given in the challenge.



              Try it online!






              share|improve this answer









              $endgroup$



              Haskell, 33 bytes



              h L=0 
              h(N l r _)=1+max(h l)(h r)


              Using the custom tree type data T = L | N T T Int, which is the Haskell equivalent of the C struct given in the challenge.



              Try it online!







              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered 5 hours ago









              niminimi

              33.7k3 gold badges27 silver badges91 bronze badges




              33.7k3 gold badges27 silver badges91 bronze badges
























                  1












                  $begingroup$


                  Perl 6, 30 bytes





                  +$_&&1+max map &?BLOCK,.[^2]


                  Try it online!



                  Input is a 3-element list (l, r, v).






                  share|improve this answer









                  $endgroup$














                  • $begingroup$
                    The &?BLOCK trick is interesting but it's a couple of bytes shorter to assign the block to $!
                    $endgroup$
                    – Jo King
                    3 hours ago










                  • $begingroup$
                    @JoKing I don't know. Storing the challenge solution in a volatile global like $! or $/ feels like cheating to me.
                    $endgroup$
                    – nwellnhof
                    3 hours ago















                  1












                  $begingroup$


                  Perl 6, 30 bytes





                  +$_&&1+max map &?BLOCK,.[^2]


                  Try it online!



                  Input is a 3-element list (l, r, v).






                  share|improve this answer









                  $endgroup$














                  • $begingroup$
                    The &?BLOCK trick is interesting but it's a couple of bytes shorter to assign the block to $!
                    $endgroup$
                    – Jo King
                    3 hours ago










                  • $begingroup$
                    @JoKing I don't know. Storing the challenge solution in a volatile global like $! or $/ feels like cheating to me.
                    $endgroup$
                    – nwellnhof
                    3 hours ago













                  1












                  1








                  1





                  $begingroup$


                  Perl 6, 30 bytes





                  +$_&&1+max map &?BLOCK,.[^2]


                  Try it online!



                  Input is a 3-element list (l, r, v).






                  share|improve this answer









                  $endgroup$




                  Perl 6, 30 bytes





                  +$_&&1+max map &?BLOCK,.[^2]


                  Try it online!



                  Input is a 3-element list (l, r, v).







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 4 hours ago









                  nwellnhofnwellnhof

                  7,8901 gold badge12 silver badges29 bronze badges




                  7,8901 gold badge12 silver badges29 bronze badges














                  • $begingroup$
                    The &?BLOCK trick is interesting but it's a couple of bytes shorter to assign the block to $!
                    $endgroup$
                    – Jo King
                    3 hours ago










                  • $begingroup$
                    @JoKing I don't know. Storing the challenge solution in a volatile global like $! or $/ feels like cheating to me.
                    $endgroup$
                    – nwellnhof
                    3 hours ago
















                  • $begingroup$
                    The &?BLOCK trick is interesting but it's a couple of bytes shorter to assign the block to $!
                    $endgroup$
                    – Jo King
                    3 hours ago










                  • $begingroup$
                    @JoKing I don't know. Storing the challenge solution in a volatile global like $! or $/ feels like cheating to me.
                    $endgroup$
                    – nwellnhof
                    3 hours ago















                  $begingroup$
                  The &?BLOCK trick is interesting but it's a couple of bytes shorter to assign the block to $!
                  $endgroup$
                  – Jo King
                  3 hours ago




                  $begingroup$
                  The &?BLOCK trick is interesting but it's a couple of bytes shorter to assign the block to $!
                  $endgroup$
                  – Jo King
                  3 hours ago












                  $begingroup$
                  @JoKing I don't know. Storing the challenge solution in a volatile global like $! or $/ feels like cheating to me.
                  $endgroup$
                  – nwellnhof
                  3 hours ago




                  $begingroup$
                  @JoKing I don't know. Storing the challenge solution in a volatile global like $! or $/ feels like cheating to me.
                  $endgroup$
                  – nwellnhof
                  3 hours ago











                  1












                  $begingroup$

                  C, 43 bytes



                  h(T*r)r=r?1+(int)fmax(h(r->l),h(r->r)):0;


                  Structure of binary tree is the following:



                  typedef struct tree

                  struct tree * l;

                  struct tree * r;

                  int v;

                  tree;





                  share|improve this answer










                  New contributor



                  T. Salim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  $endgroup$










                  • 1




                    $begingroup$
                    55 bytes Try it online! Some C-specific golfing tricks are here!
                    $endgroup$
                    – ErikF
                    5 hours ago






                  • 1




                    $begingroup$
                    @ErikF Or 45 bytes
                    $endgroup$
                    – Arnauld
                    4 hours ago










                  • $begingroup$
                    Thanks ErikF and Arnauld. I should try out the ternary operator more often instead of if-else-if chains.
                    $endgroup$
                    – T. Salim
                    4 hours ago






                  • 2




                    $begingroup$
                    43 bytes
                    $endgroup$
                    – nwellnhof
                    4 hours ago






                  • 2




                    $begingroup$
                    If your submission relies on flags, can you please add them to the header of your submission?
                    $endgroup$
                    – Jo King
                    3 hours ago















                  1












                  $begingroup$

                  C, 43 bytes



                  h(T*r)r=r?1+(int)fmax(h(r->l),h(r->r)):0;


                  Structure of binary tree is the following:



                  typedef struct tree

                  struct tree * l;

                  struct tree * r;

                  int v;

                  tree;





                  share|improve this answer










                  New contributor



                  T. Salim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  $endgroup$










                  • 1




                    $begingroup$
                    55 bytes Try it online! Some C-specific golfing tricks are here!
                    $endgroup$
                    – ErikF
                    5 hours ago






                  • 1




                    $begingroup$
                    @ErikF Or 45 bytes
                    $endgroup$
                    – Arnauld
                    4 hours ago










                  • $begingroup$
                    Thanks ErikF and Arnauld. I should try out the ternary operator more often instead of if-else-if chains.
                    $endgroup$
                    – T. Salim
                    4 hours ago






                  • 2




                    $begingroup$
                    43 bytes
                    $endgroup$
                    – nwellnhof
                    4 hours ago






                  • 2




                    $begingroup$
                    If your submission relies on flags, can you please add them to the header of your submission?
                    $endgroup$
                    – Jo King
                    3 hours ago













                  1












                  1








                  1





                  $begingroup$

                  C, 43 bytes



                  h(T*r)r=r?1+(int)fmax(h(r->l),h(r->r)):0;


                  Structure of binary tree is the following:



                  typedef struct tree

                  struct tree * l;

                  struct tree * r;

                  int v;

                  tree;





                  share|improve this answer










                  New contributor



                  T. Salim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  $endgroup$



                  C, 43 bytes



                  h(T*r)r=r?1+(int)fmax(h(r->l),h(r->r)):0;


                  Structure of binary tree is the following:



                  typedef struct tree

                  struct tree * l;

                  struct tree * r;

                  int v;

                  tree;






                  share|improve this answer










                  New contributor



                  T. Salim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.








                  share|improve this answer



                  share|improve this answer








                  edited 4 hours ago





















                  New contributor



                  T. Salim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.








                  answered 7 hours ago









                  T. SalimT. Salim

                  476 bronze badges




                  476 bronze badges




                  New contributor



                  T. Salim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.




                  New contributor




                  T. Salim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.












                  • 1




                    $begingroup$
                    55 bytes Try it online! Some C-specific golfing tricks are here!
                    $endgroup$
                    – ErikF
                    5 hours ago






                  • 1




                    $begingroup$
                    @ErikF Or 45 bytes
                    $endgroup$
                    – Arnauld
                    4 hours ago










                  • $begingroup$
                    Thanks ErikF and Arnauld. I should try out the ternary operator more often instead of if-else-if chains.
                    $endgroup$
                    – T. Salim
                    4 hours ago






                  • 2




                    $begingroup$
                    43 bytes
                    $endgroup$
                    – nwellnhof
                    4 hours ago






                  • 2




                    $begingroup$
                    If your submission relies on flags, can you please add them to the header of your submission?
                    $endgroup$
                    – Jo King
                    3 hours ago












                  • 1




                    $begingroup$
                    55 bytes Try it online! Some C-specific golfing tricks are here!
                    $endgroup$
                    – ErikF
                    5 hours ago






                  • 1




                    $begingroup$
                    @ErikF Or 45 bytes
                    $endgroup$
                    – Arnauld
                    4 hours ago










                  • $begingroup$
                    Thanks ErikF and Arnauld. I should try out the ternary operator more often instead of if-else-if chains.
                    $endgroup$
                    – T. Salim
                    4 hours ago






                  • 2




                    $begingroup$
                    43 bytes
                    $endgroup$
                    – nwellnhof
                    4 hours ago






                  • 2




                    $begingroup$
                    If your submission relies on flags, can you please add them to the header of your submission?
                    $endgroup$
                    – Jo King
                    3 hours ago







                  1




                  1




                  $begingroup$
                  55 bytes Try it online! Some C-specific golfing tricks are here!
                  $endgroup$
                  – ErikF
                  5 hours ago




                  $begingroup$
                  55 bytes Try it online! Some C-specific golfing tricks are here!
                  $endgroup$
                  – ErikF
                  5 hours ago




                  1




                  1




                  $begingroup$
                  @ErikF Or 45 bytes
                  $endgroup$
                  – Arnauld
                  4 hours ago




                  $begingroup$
                  @ErikF Or 45 bytes
                  $endgroup$
                  – Arnauld
                  4 hours ago












                  $begingroup$
                  Thanks ErikF and Arnauld. I should try out the ternary operator more often instead of if-else-if chains.
                  $endgroup$
                  – T. Salim
                  4 hours ago




                  $begingroup$
                  Thanks ErikF and Arnauld. I should try out the ternary operator more often instead of if-else-if chains.
                  $endgroup$
                  – T. Salim
                  4 hours ago




                  2




                  2




                  $begingroup$
                  43 bytes
                  $endgroup$
                  – nwellnhof
                  4 hours ago




                  $begingroup$
                  43 bytes
                  $endgroup$
                  – nwellnhof
                  4 hours ago




                  2




                  2




                  $begingroup$
                  If your submission relies on flags, can you please add them to the header of your submission?
                  $endgroup$
                  – Jo King
                  3 hours ago




                  $begingroup$
                  If your submission relies on flags, can you please add them to the header of your submission?
                  $endgroup$
                  – Jo King
                  3 hours ago











                  0












                  $begingroup$

                  Scheme, 72 Bytes



                  (define(f h)(if(null? h)0(+ 1(max(f(car(cdr h)))(f(car(cdr(cdr h))))))))


                  More Readable Version:



                  (define (f h)
                  (if (null? h)
                  0
                  (+ 1
                  (max
                  (f (car (cdr h)))
                  (f (car (cdr (cdr h))))
                  )
                  )
                  )
                  )


                  Using lists of the form (data, left, right) to represent a tree. E.g.



                   1
                  /
                  2 3
                  /
                  4 5

                  is represented as: (1 (2 (4 () ()) (5 () ())) (3 () ())

                  (1
                  (2
                  (4 () ())
                  ``` (5 () ())
                  (3 () ())
                  )


                  Try it Online!






                  share|improve this answer











                  $endgroup$



















                    0












                    $begingroup$

                    Scheme, 72 Bytes



                    (define(f h)(if(null? h)0(+ 1(max(f(car(cdr h)))(f(car(cdr(cdr h))))))))


                    More Readable Version:



                    (define (f h)
                    (if (null? h)
                    0
                    (+ 1
                    (max
                    (f (car (cdr h)))
                    (f (car (cdr (cdr h))))
                    )
                    )
                    )
                    )


                    Using lists of the form (data, left, right) to represent a tree. E.g.



                     1
                    /
                    2 3
                    /
                    4 5

                    is represented as: (1 (2 (4 () ()) (5 () ())) (3 () ())

                    (1
                    (2
                    (4 () ())
                    ``` (5 () ())
                    (3 () ())
                    )


                    Try it Online!






                    share|improve this answer











                    $endgroup$

















                      0












                      0








                      0





                      $begingroup$

                      Scheme, 72 Bytes



                      (define(f h)(if(null? h)0(+ 1(max(f(car(cdr h)))(f(car(cdr(cdr h))))))))


                      More Readable Version:



                      (define (f h)
                      (if (null? h)
                      0
                      (+ 1
                      (max
                      (f (car (cdr h)))
                      (f (car (cdr (cdr h))))
                      )
                      )
                      )
                      )


                      Using lists of the form (data, left, right) to represent a tree. E.g.



                       1
                      /
                      2 3
                      /
                      4 5

                      is represented as: (1 (2 (4 () ()) (5 () ())) (3 () ())

                      (1
                      (2
                      (4 () ())
                      ``` (5 () ())
                      (3 () ())
                      )


                      Try it Online!






                      share|improve this answer











                      $endgroup$



                      Scheme, 72 Bytes



                      (define(f h)(if(null? h)0(+ 1(max(f(car(cdr h)))(f(car(cdr(cdr h))))))))


                      More Readable Version:



                      (define (f h)
                      (if (null? h)
                      0
                      (+ 1
                      (max
                      (f (car (cdr h)))
                      (f (car (cdr (cdr h))))
                      )
                      )
                      )
                      )


                      Using lists of the form (data, left, right) to represent a tree. E.g.



                       1
                      /
                      2 3
                      /
                      4 5

                      is represented as: (1 (2 (4 () ()) (5 () ())) (3 () ())

                      (1
                      (2
                      (4 () ())
                      ``` (5 () ())
                      (3 () ())
                      )


                      Try it Online!







                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited 4 hours ago

























                      answered 4 hours ago









                      Zachary CottonZachary Cotton

                      4992 silver badges5 bronze badges




                      4992 silver badges5 bronze badges
























                          0












                          $begingroup$


                          Charcoal, 29 bytes



                          ⊞θ⁰⊞υθFυ«≔⊕⊟ιθFΦι∧κλ⊞υ⊞Oκθ»Iθ


                          Try it online! Link is to verbose version of code. Temporarily modifies the tree during processing. Explanation:



                          ⊞θ⁰


                          Push zero to the root node.



                          ⊞υθ


                          Push the root node to the list of all nodes.



                          Fυ«


                          Perform a breadth-first search of the tree.



                          ≔⊕⊟ιθ


                          Get the depth of this node.



                          FΦι∧κλ


                          Loop over any child nodes.



                          ⊞υ⊞Oκθ


                          Tell the child node its parent's depth and push it to the list of all nodes.



                          »Iθ


                          Once all the nodes have been traversed print the depth of the last node. Since the traversal was breadth-first, this will be the height of the tree.






                          share|improve this answer









                          $endgroup$



















                            0












                            $begingroup$


                            Charcoal, 29 bytes



                            ⊞θ⁰⊞υθFυ«≔⊕⊟ιθFΦι∧κλ⊞υ⊞Oκθ»Iθ


                            Try it online! Link is to verbose version of code. Temporarily modifies the tree during processing. Explanation:



                            ⊞θ⁰


                            Push zero to the root node.



                            ⊞υθ


                            Push the root node to the list of all nodes.



                            Fυ«


                            Perform a breadth-first search of the tree.



                            ≔⊕⊟ιθ


                            Get the depth of this node.



                            FΦι∧κλ


                            Loop over any child nodes.



                            ⊞υ⊞Oκθ


                            Tell the child node its parent's depth and push it to the list of all nodes.



                            »Iθ


                            Once all the nodes have been traversed print the depth of the last node. Since the traversal was breadth-first, this will be the height of the tree.






                            share|improve this answer









                            $endgroup$

















                              0












                              0








                              0





                              $begingroup$


                              Charcoal, 29 bytes



                              ⊞θ⁰⊞υθFυ«≔⊕⊟ιθFΦι∧κλ⊞υ⊞Oκθ»Iθ


                              Try it online! Link is to verbose version of code. Temporarily modifies the tree during processing. Explanation:



                              ⊞θ⁰


                              Push zero to the root node.



                              ⊞υθ


                              Push the root node to the list of all nodes.



                              Fυ«


                              Perform a breadth-first search of the tree.



                              ≔⊕⊟ιθ


                              Get the depth of this node.



                              FΦι∧κλ


                              Loop over any child nodes.



                              ⊞υ⊞Oκθ


                              Tell the child node its parent's depth and push it to the list of all nodes.



                              »Iθ


                              Once all the nodes have been traversed print the depth of the last node. Since the traversal was breadth-first, this will be the height of the tree.






                              share|improve this answer









                              $endgroup$




                              Charcoal, 29 bytes



                              ⊞θ⁰⊞υθFυ«≔⊕⊟ιθFΦι∧κλ⊞υ⊞Oκθ»Iθ


                              Try it online! Link is to verbose version of code. Temporarily modifies the tree during processing. Explanation:



                              ⊞θ⁰


                              Push zero to the root node.



                              ⊞υθ


                              Push the root node to the list of all nodes.



                              Fυ«


                              Perform a breadth-first search of the tree.



                              ≔⊕⊟ιθ


                              Get the depth of this node.



                              FΦι∧κλ


                              Loop over any child nodes.



                              ⊞υ⊞Oκθ


                              Tell the child node its parent's depth and push it to the list of all nodes.



                              »Iθ


                              Once all the nodes have been traversed print the depth of the last node. Since the traversal was breadth-first, this will be the height of the tree.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered 3 hours ago









                              NeilNeil

                              86.7k8 gold badges46 silver badges183 bronze badges




                              86.7k8 gold badges46 silver badges183 bronze badges
























                                  0












                                  $begingroup$


                                  Japt, 9 bytes



                                  Ω¡ÒßXÃrw


                                  Try it






                                  share|improve this answer









                                  $endgroup$



















                                    0












                                    $begingroup$


                                    Japt, 9 bytes



                                    Ω¡ÒßXÃrw


                                    Try it






                                    share|improve this answer









                                    $endgroup$

















                                      0












                                      0








                                      0





                                      $begingroup$


                                      Japt, 9 bytes



                                      Ω¡ÒßXÃrw


                                      Try it






                                      share|improve this answer









                                      $endgroup$




                                      Japt, 9 bytes



                                      Ω¡ÒßXÃrw


                                      Try it







                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered 3 hours ago









                                      ShaggyShaggy

                                      20.7k3 gold badges20 silver badges69 bronze badges




                                      20.7k3 gold badges20 silver badges69 bronze badges























                                          T. Salim is a new contributor. Be nice, and check out our Code of Conduct.









                                          draft saved

                                          draft discarded


















                                          T. Salim is a new contributor. Be nice, and check out our Code of Conduct.












                                          T. Salim is a new contributor. Be nice, and check out our Code of Conduct.











                                          T. Salim is a new contributor. Be nice, and check out our Code of Conduct.














                                          If this is an answer to a challenge…



                                          • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                          • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                            Explanations of your answer make it more interesting to read and are very much encouraged.


                                          • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.


                                          More generally…



                                          • …Please make sure to answer the question and provide sufficient detail.


                                          • …Avoid asking for help, clarification or responding to other answers (use comments instead).




                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f189220%2fwrite-the-shortest-program-to-calculate-height-of-a-binary-tree%23new-answer', 'question_page');

                                          );

                                          Post as a guest















                                          Required, but never shown





















































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown

































                                          Required, but never shown














                                          Required, but never shown












                                          Required, but never shown







                                          Required, but never shown







                                          Popular posts from this blog

                                          Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                                          Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                                          Tom Holland Mục lục Đầu đời và giáo dục | Sự nghiệp | Cuộc sống cá nhân | Phim tham gia | Giải thưởng và đề cử | Chú thích | Liên kết ngoài | Trình đơn chuyển hướngProfile“Person Details for Thomas Stanley Holland, "England and Wales Birth Registration Index, 1837-2008" — FamilySearch.org”"Meet Tom Holland... the 16-year-old star of The Impossible""Schoolboy actor Tom Holland finds himself in Oscar contention for role in tsunami drama"“Naomi Watts on the Prince William and Harry's reaction to her film about the late Princess Diana”lưu trữ"Holland and Pflueger Are West End's Two New 'Billy Elliots'""I'm so envious of my son, the movie star! British writer Dominic Holland's spent 20 years trying to crack Hollywood - but he's been beaten to it by a very unlikely rival"“Richard and Margaret Povey of Jersey, Channel Islands, UK: Information about Thomas Stanley Holland”"Tom Holland to play Billy Elliot""New Billy Elliot leaving the garage"Billy Elliot the Musical - Tom Holland - Billy"A Tale of four Billys: Tom Holland""The Feel Good Factor""Thames Christian College schoolboys join Myleene Klass for The Feelgood Factor""Government launches £600,000 arts bursaries pilot""BILLY's Chapman, Holland, Gardner & Jackson-Keen Visit Prime Minister""Elton John 'blown away' by Billy Elliot fifth birthday" (video with John's interview and fragments of Holland's performance)"First News interviews Arrietty's Tom Holland"“33rd Critics' Circle Film Awards winners”“National Board of Review Current Awards”Bản gốc"Ron Howard Whaling Tale 'In The Heart Of The Sea' Casts Tom Holland"“'Spider-Man' Finds Tom Holland to Star as New Web-Slinger”lưu trữ“Captain America: Civil War (2016)”“Film Review: ‘Captain America: Civil War’”lưu trữ“‘Captain America: Civil War’ review: Choose your own avenger”lưu trữ“The Lost City of Z reviews”“Sony Pictures and Marvel Studios Find Their 'Spider-Man' Star and Director”“‘Mary Magdalene’, ‘Current War’ & ‘Wind River’ Get 2017 Release Dates From Weinstein”“Lionsgate Unleashing Daisy Ridley & Tom Holland Starrer ‘Chaos Walking’ In Cannes”“PTA's 'Master' Leads Chicago Film Critics Nominations, UPDATED: Houston and Indiana Critics Nominations”“Nominaciones Goya 2013 Telecinco Cinema – ENG”“Jameson Empire Film Awards: Martin Freeman wins best actor for performance in The Hobbit”“34th Annual Young Artist Awards”Bản gốc“Teen Choice Awards 2016—Captain America: Civil War Leads Second Wave of Nominations”“BAFTA Film Award Nominations: ‘La La Land’ Leads Race”“Saturn Awards Nominations 2017: 'Rogue One,' 'Walking Dead' Lead”Tom HollandTom HollandTom HollandTom Hollandmedia.gettyimages.comWorldCat Identities300279794no20130442900000 0004 0355 42791085670554170004732cb16706349t(data)XX5557367