π Today's Learning:
π DSA
- Bubble sort
- Selection Sort
π Dev
- Features of React
- JSX
π Some Key Highlights:
DSA
In bubble sort, we just compare the current element with the next element β if the current element is greater than next element it is swapped β This let the maximum element reach the end of the array. Now the unsorted array left is till the second last element. Same process is repeated for sorting this array and so on. Finally we get the sorted array. There is an outer loop βiβ which runs from n-1 to 0. And an inner loop βjβ that runs from 0 to i-1 (not till i coz we are comparing A[j] and A[j+1]). Avg and worst case T.C. O(n2) | Best case: O(n) (when the array is already sorted)
In selection sort, we check a range of array at each pass. An inner loop finds the minimum element from that range and swaps it from the first element of the range. The range starts from complete array and keeps on decreasing till the complete array is sorted. The outer loop, say i, is running from 0 to n-2 i.e. n-1 times, and for each i, the inner loop j runs from i to n-1. For, i = 0, the inner loop runs n-1 times, for i = 1, the inner loop runs n-2 times, and so on. So, the total steps will be approximately the following: (n-1) + (n-2) + (n-3) + β¦β¦..+ 3 + 2 + 1. The summation is approximately the sum of the first n natural numbers i.e. (n*(n+1))/2. Avg and worst case T.C. O(n2)
DEV
JSX is a syntax extension of JavaScript. It is used with React to describe what the user interface should look like. By using JSX, we can write HTML structures in the same file that contains JavaScript code.
Note:
- Web browsers cannot read JSX directly. This is because they are built to only read regular JS objects and JSX is not a regular JavaScript object
- For a web browser to read a JSX file, the file needs to be transformed into a regular JavaScript object. For this, we use Babel
#100daysofcode #1percentplusplus #coding #dsa
Top comments (0)