🚀 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.
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.
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.