🚀 Today's Learning:
🌟 DSA
- Minimum in a rotated sorted array
Search in a rotated sorted array
🌟 Dev
- Lifecycle of a component in React
🔍 Some Key Highlights:
DSA
To find the minimum value in a rotated sorted array, you start by comparing the middle element with the first and last elements to determine which half of the array is sorted. Then, you recursively search in the unsorted half until you find the minimum element. This process continues until you've narrowed down the search to a single element, which is the minimum value.
In searching a rotated sorted array, you apply a similar approach to binary search, but with adjustments for the rotation. You compare the middle element with the target value and adjust the search based on whether the target could be in the left or right half of the array, considering the rotation. This process is repeated recursively until you find the target element or determine that it's not present in the array.
DEV
In React, the lifecycle of a component refers to the series of events that occur from its creation to its removal from the DOM. It begins with the component being initialized and mounted onto the DOM, where it can then be updated and interacted with by users. During the mounting phase, the component goes through various stages such as constructor initialization, rendering, and componentDidMount, where you can perform side effects like fetching data or setting up subscriptions. Once mounted, the component can be updated based on changes in state or props, triggering rerendering and lifecycle methods like componentDidUpdate. Finally, when the component is removed from the DOM, it goes through the componentWillUnmount phase, allowing you to clean up any resources or subscriptions to prevent memory leaks. This lifecycle pattern helps manage the behavior and appearance of components throughout their existence in a React application.
#100daysofcode #1percentplusplus
Top comments (0)