Posts

Redux - Saga

Image
Redux is a state management tool that works as a “centralized store,” which means that it is the only place to access the state.Redux is a light “standalone” JavaScript library, which means it can be used with any UI framework, most frequently, it is used with ReactJS. Redux-Thunk Redux Thunk is a middleware that enables you to call action creators that return functions (thunks) that accept the store's dispatch method as an argument and are then used to dispatch the synchronous action after the API or side effects have ended. Redux-Saga Another middleware library that assists us with API calls or side effects is Redux Saga. Redux Saga makes use of ES6's "Generators" feature, which makes it easier to develop asynchronous code. Redux-saga’s action creator returns an Object while Redux-Thunk action creator returns a Function(thunk). Redux-Saga Data Flow How data flow When a user interacts with the application, an action is dispatched Root Reducer/ Reducer  function is c...

Binary Search - Time Complexity

Image
Time Complexity of Binary Search Algorithm Algorithm:       Int BinarySearch(int Array[], int value, int left, int right){                Int mid=(left+right)/2     If(Array[mid]== value){ Return mid; }elif(left>right){ Return -1; }elif(Array[mid] > value){ BinarySearch(Array,left,mid-1); }else{   BinarySearch(Array, mid+1,right); }   End if   } Let N be the Size of the Binary tree   T(N) =  C +  T(N/2)   ------ 1 T(N/2) = C + T (N/4) ------2 Substitute 2 à 1 T(N) = 2C + T(N/4)    -------3 T(N/4) = C + T(N/8)  --------4 Substitute 4 à 3   T(N) = 3C + T(N/8) ------5   pattern   T(N) = iC + T(N/2 i )        where I is an integer     At some point , as N/2 i diminishes , we reach only 1 element,   So     ...

Quick Sort - Time Complexity

Image
 Time Complexity of Quick Sort Algorithm:                            QuickSort(left, right){                                   If(left < right){                                              Pi= partition(left,right)                                                QuickSort(left,pi)                                         ...

Merge Sort - Time Complexity

Image
 Time Complexity of Merge Sort Algorithm:                       MergeSort(left, right){                              If(left < right){                                         Mid=(left+right)/2                                            MergeSort(left,mid)                                          MergeSort(mid+1, right)         ...

Insertion Sort - Time Complexity

Image
 Time Complexity of Insertion Sort Selection Sort is using two for loops to do one iteration. The first loop (Outer loop ) travels through an array starting from index 0, while the inner loop runs from index i+1 to index less than i. The following diagram shows the Number of execution rounds it performs. when i is 0,, j is 1,  the inner for loop runs n-1 time. when i is 1, j is 2, the inner for loop runs n-2 times. Likewise, when i is n, j is n+1,  the inner for loop runs n times. So the total number of Execution rounds can be calculated by adding all Execution times in each i values.  Time Complexity =    n-1 (n-1)                                              2            ...

Selection Sort - Time Complextity

Image
  Time Complexity of Selection Sort  Selection sort  is using two for loops to do one iteration. The first loop (Outer loop ) travels through an array starting from index 1, while the inner loop runs from index 1 to index i-1. The following diagram shows the Number of execution rounds it performs. when i is 1, the inner for loop runs only one time. when i is 2, inner for loop runs 2 times. Likewise when i is   n   the inner for loop runs n times. So the total number of Execution rounds can be calculated by adding all Execution times in each i values.     Time Complexity       =    n (n+1)                                         2                     ...