DEV Community

Cover image for Day 13/366

Posted on

Day 13/366

πŸš€ Today's Learning:


  • Calculate the Diameter of a Binary Tree
  • Preorder Traversal of Binary Tree

🌟 Dev

  • Events in React

πŸ” Some Key Highlights:


Calculate the Diameter of a Binary Tree - start traversal using DFS β†’ Assume each node as the curving point β†’ diameter using the current node is 1 + max(depth of left subtree, depth of right subtree). Likewise, recursively calculate the current diameter of all the nodes. Maintain a maxDiameter variable which stores the maximum of all diameters.

Image description

Preorder traversal β†’ Β The recursive function begins by processing ie. adding to the array or printing the current node β†’ Recursively traverse the left subtree by invoking the preorder function on the left child of the current node. This step continues the exploration of nodes in a depth first manner β†’ After traversing the entire left subtree, we traverse the right subtree recursively. We once again invoke the preorder function, but this time on the right child of the current node.

Image description


An event is an action that a user or system may trigger, such as pressing a key, a mouse click, etc.

  • React events are named using camelCase, rather than lowercase in HTML.
  • With JSX, you pass a function as the event handler, rather than a string in HTML.

For example β†’ Button onPress={lightItUp}

#100daysofcode #1percentplusplus #coding #dsa

Top comments (0)