Posts

Showing posts with the label DSU

Search a data using binary search

Image
This post content:- Algorithm Flowchart C code Output Pdf notes Algorithm:- Step 1:- start. Step 2:- declare a sorted array. Step 3:- declare the size of the given array. Step 4:- declare the variable to find the number in the given array. Step 5:- make a function for binary search algorithm. int binarysearch(int arr[],int size,int element) {     int low=0;     int high=size -1;          while(low<=high)     {         int mid = (low + high)/2;         if (arr[mid]==element)         {             return mid;         }         if (arr[mid]< element)         {             low = mid+1;         }         if (arr[mid]> element)         {             high = mid-1; ...

Search a Data Using Linear Search

Image
This post content:- Algorithm Flowchart C code Output Pdf notes Algorithm :- Step 1:- start. Step 2:- declare an array. Step 3:- declare variable and assign size of array to it. (int size = sizeof(arr)/sizeof(int);) Step 4:- give the value to find in the array. Step 5:- make the function for linear search     for(int i= 0;i<=size;i++)     {         if(arr[i]==element)         {           return i;         }     }      return -1; }(End of function) Step 6:- assign output to the variable result. Step 7:- print result. Step 8:- end. Flowchart:- C code:- Output:- Try it yourself:- online c compiler Download pdf notes