Monday, 26 June 2023

Searching Algorithms in C

What is searching Algorithms?

Searching is an operation or performance which finds the site or location of a given section or element in a list. The search is said to be victorious or unsuccessful or pointless depending on whether the section or element that is to be searched is begin or found or not. The following are the dissimilar types of searches

1.       Linear Search

2.       Binary Search

 

Algorithms in C, C language, C programming
Searching Algorithms Image-1

1.1   Linear Search

It is also known as successive or sequential search, which is fit or suitable for searching a set of data for a certain or particular value.
It is the easy or simplest procedure or method of searching, and it can be put in or applied to a sorted or an unsorted list.
It work or operates by checking every section or element of a list one at a time in order or sequence until a match is found. Linear search runs in O(N). If the information or data are distributed or give out randomly, on average N/2 balancing or comparisons will be needed.
The best case or instance is that the value is equal to the firs section or element tested, in which case only1 balancing or comparison is needed. The poorest or worst case is that the worth or value is not in the list (or is the last thing or item in the list), in which case N balancing or comparisons are needed.
Suppose or think an array A having section or elements 1 to N is to be searched for a worth or value x: if not found, the result is zero.

1.2   Binary Search

The most effective or fruitful technique that can be applied to sorted data or records is the binary search technique. This technique or ability is faster than the other searching techniques.

1.       The given sorted data or records are divided into two halves.

2.       The key is first compared or measure with the key area or field of the middle record.

3.       If the match or tie is found, the key index or sign is returned.

4.       If it does not match or tie, then required key must be either in the lower or upper half.

5.       If the key is less than the key field or area of the middle data or record, the key is searched in the lower half otherwise it is checked or inspect in the upper half.


Computer stuff kit tricks of Topics 68.