Day 13/366

🚀 Today’s Learning:

🌟 DSA

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

🌟 Dev

  • Events in React

🔍 Some Key Highlights:

DSA

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

DEV

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


Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
Windows vps plans – currently replenishing.