Sorting and searching – free C programming tutorial

In this tutorial you will be familiarize with searching and sorting techniques which is available for C programming language.

Searching :

Searching in C language is defined as finding an element in a array i.e.  by searching we will find the position of a element where the entered number by user is stored.

There are two types of searching available in C which are given as below :

  1. Linear search :Linear search is also known as sequential search.
    In linear search, basically we have to keep comparing elements of an array with the number entered by user to search in a given array until the element is found or an array ends.
  2. Binary search :It is also known as half-interval search.
    In binary search, searching starts in the middle of a sorted array( i.e. basically binary searching is applied on sorted array ) and determines which side the value you are looking for is on.

So there are three possibilities in linear search which are given as below:

  1. Best case : Number entered by user found at first position of the array.
  2. Average case : Number entered by user found at middle of the array.
  3. Worst case : Number entered by user does not found in the array.

Sorting :

Sorting is defined as the process of arranging an array in ascending order or descending order or it is defined as rearranging elements of an array.

There are different types of sorting available for C language which are given as following :

  1. Internal sort : When all the sorted data is stored in a memory. For example bubble sort.
  2. External sort : When all the sorted data is stored outside the memory. For example merge sort.

sorting

Internal sorting :

Internal sort is defined as the process of sorting in which all the sorted data is stored in a memory.
For example bubble sort.
Other example of internal sort are insertion sort, selection sort, radix sort, heap sort, quick sort etc.

External sorting:

External sort is defined as the process of sorting in which all the sorted data is stored outside the memory.
For example merge sort.

This is all about the basics of searching and sorting techniques which is available for C programming language.
If you have any query please comment below.

Leave a Comment

Your email address will not be published. Required fields are marked *