Posts

Showing posts from April, 2023

Data Structures(Binary search in Data structures)

Image
Binary Search 👉  Binary search is the search technique which works efficiently on the sorted lists.  👉 Hence, in order to search an element into some list by using binary search technique, we must ensure that the list is sorted. 👉 Binary search follows divide and conquer approach in which, the list is divided into two halves and the item is compared with the middle element of the list.  👉 If the match is found then, the location of middle element is returned otherwise, we search into either of the halves depending upon the result produced through the match. 👉  Binary search is implemented using following steps... Step 1 -  Read the search element from the user. Step 2 -  Find the middle element in the sorted list. Step 3 -  Compare the search element with the middle element in the sorted list. Step 4 -  If both are matched, then display "Given element is found!!!" and terminate the function. Step 5 -  If both are not matched, then check whether the search element is

Data Structures(Linear search in data structures)

Image
Searching: 👉   Searching is the process of finding some particular element in the list.  👉   If the element is  present in the list, then the process is called successful and the process returns the location  of that element, otherwise the search is called unsuccessful. 👉   There are two popular search methods that are widely used in order to search some item  into the list.                🔯    Linear Search                🔯     Binary Search Linear Search 👉   Linear search is the simplest search algorithm and often called sequential search.  👉   In this  type of searching, we simply traverse the list completely and match each element of the list  with the item whose location is to be found.  👉   If the match found then location of the item is  returned otherwise the algorithm return NULL. 👉   Linear search is mostly used to search an unordered list in which the items are not sorted. Technique: The steps used in the implementation of Linear Search are listed as follows - First

Data Structures(Merge Sort in Data Structures)

Image
  Merge Sort: 👉   Merge Sort  is a  divide and conquer-based  sorting algorithm. 👉   In this sorting algorithm the unsorted array keeps on dividing into two halves until the array is either empty or contains only one element, and then the halves are combined/Merged in sorted order producing a sorted array. 👉   It is one of the most  popular and efficient sorting  techniques. Working of Merge sort Algorithm: Let the elements of array are - According to the merge sort, first divide the given array into two equal halves. Merge sort keeps dividing the list into equal parts until it cannot be further divided. As there are eight elements in the given array, so it is divided into two arrays of size 4. Now, again divide these two arrays into halves. As they are of size 4, so divide them into new arrays of size 2. Now, again divide these arrays to get the atomic value that cannot be further divided. Now, combine them in the same manner they were broken. In combining, first compare the elemen