😀 Hello Leetcoders !!
I hope you all doing good .
Let me give you a quick introduction about myself.
Myself Ishika Rastogi , a 3rd year Student studying Computer Science and Engineering (Data science) as a major . I'm just an average person like other's.
I'm not talented enough, but I work hard & what I know is "Work Hard , Stay Positive and Good Things Will Happen.”I'm not a big coder actually i'm a big learner!!
..........................................................................................................................................................................................................
..........................................................................................................................................................................................................
It's not an language specific article. Trust me, you will learn a lot. HAPPY LEARNING!
So, with that let's start. Hello, my fellow programmer's this post is all about Searching .
If you want to become master, then you have to follow some rules, only after that you can become Master's in Searching
Rules are as follows:
Practice makes a men perfect.
#Introduction Ques::1 What is searching ?
Ans:: Searching in data structure refers to the process of finding the required information from a collection of items . These sets of items can be in
different forms, such as an array, linked list , graph, or tree etc.Second and most firstly question come in mind is Why do we have reqirement of Searching Algorithm?Why do we not search one by one every elements in the list?Okk so don't worry😌 , here we have an ans -
If you search an element one by one in a list or between the set of items then it takes a lot of time to search an item one by one .
We often need to find one particular item of data amongst many hundreds, thousands, millions or more. Without them you would have to look at each item of data – each phone number or business addresses and anything else – individually, to see whether it is what you are looking for. In a large set of data, it will take a long time to do this. Instead, a searching algorithm can be used to help find the item of data you are looking for.
This is why searching algorithms are important.
There are various searching method that can be perform search on a data set.The choice of a particular searching method in a given situation depends on a number of factors , such as
Okk in this whole journey we are learn about two(2) types of searching algorithm-->>
1.Linear search .
2. Binary search .linear search is also called as a Sequential search .
Linear search is a very simple search algorithm. In this type of search, a sequential search is made over all items one by one.
Every item is checked and if a match is found then that particular item is returned, otherwise the search continues till the end of the data collection.
In array we have to first define the size of the Array
Let's say:-
int n; // size of array
int arr[n];
for(int i=0;i<n;i++)
{
cin>>a[i]; // enter the array values
}
Array :- [3,2,18,33,21,5,7]
K=33.
Here , element (K=33) will be find lineraly or called sequentially.
Complexity::
worst case : O(n )
best case : O(1)
Advantages Disadvantages
1. easy to implement 1. inefficient for larged sized list.
2. it does not require the list to be sorted 2. it does not leverage the presence if any pre-existing sort order .Real-life Application's :-
#Binary SearchBinary search follows the 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 the middle element is returned.
Otherwise, we search into either of the halves depending upon the result produced through the match.

Time Complexity :
worst case : O(log2n)
best case : O(1)Advantages Disadvantages
1. requires lesser number of iteration 1. it requires list to be sorted
2. faster than linear search 2. comparison to linear search it seem to be little difficult to implement.Real-life Application's :-
`

now let k=68(the element which would be find)
now array will divide into three parts:
1. left subarray
2. right subarray
3. midnow the comparing will start , if searching element is greater than mid element , pointer will move right side of array and if searching element is less than the mid , pointer will move towards left subarray.
i.e
if (arr[mid] == k) if ans is NO -->>>we have two options either to move towards right or left .

As see in this example , K=68 is greater than mid element =45, so the pointer will move towards right side .

Here, the complexity only based on right side of array.
Lets see the implementation of linear search-

output -

Let's see the implementation of Binary Search -
This implementation is based on iterative method.

output-

Now just look on the Recursive Method.

Output-

Some **basic** to **medium** to **hard** questions for practice Bineary Search.1. Find Target Indices After Sorting Array.
Problem Statement-
You are given a 0-indexed integer array nums and a target element target.A target index is an index i such that nums[i] == target.Return a list of the target indices of nums after sorting nums in non-decreasing order. If there are no target indices, return an empty list. The returned list must be sorted in increasing order. Example- Input: nums = [1,2,5,2,3], target = 2
Output: [1,2].
SOLUTION::

....................................................................................................................................................................................................................................................
Try practicing these question by yourself and if anyone could find most useful method to solve these questions can put there solutions on comment box or
can share any kind of information so that others also take advantage and learn new approaches. Its all means to spread knowledge as much as we can .............................................................................................................................................................................................................................