Algorithms

·

2 min read

what is Algorithm?

  • " Algorithm is a finite set of rules and regulation to solve a problem. "
  Characteristics of Algorithm:

  - Unambiguous
  -  Feasible
  - Well-Defined Inputs and Outputs
  - Finiteness
  - Effectiveness

Screenshot (98).png

Searching Algorithm:

Some of the important searching algorithms are:

  • Binary Search

image.png

  Binary Search is a searching algorithm used in a sorted array by repeatedly dividing the search interval in half.

  Begin with the mid element of the whole array as a search key.

  If the value of the search key is equal to the item then return an index of the search key.
Or if the value of the search key is less than the item in the middle of the interval,     narrow the interval to the lower half.

  Otherwise, narrow it to the upper half.
  Repeatedly check from the second point until the value is found or the interval is empty.

I learnt binary search algorithm from Geeks for Geeks and Kunal Kushwaha's YouTube channel(youtube.com/watch?v=f6UU7V3szVw&list=PL..)

  • Linear Search

image.png

In linear Search, it is a sequential search algorithm.
Linear search iterating from 0 to n-1
if target value found in comparison then it return the value Otherwise it will not return 

Sorting Algorithm:

  Some of the important Sorting Algorithms

        - Bubble Sort
        - Selection Sort
        - Insertion Sort     
  • Bubble Sort

image.png

Bubble sort is a simple sorting algorithm.

Bubble sort repeatedly swapping the adjacent elements if they are not in their correct         
place

This sorting algorithm is not suitable for large data.

Selection Sort

image.png

 selection sort algorithm sorts an array by repeatedly finding the minimum element from the unsorted part and putting it at the beginning. 
The algorithm maintains two subarrays in a given array.
  The subarray which already sorted. 
  The remaining subarray was unsorted.
  In every iteration of the selection sort, the minimum element from the unsorted subarray is picked and moved to the sorted subarray. 

insertion sort

image.png

Insertion sort is a simple sorting algorithm
This algorithm is one of the simplest algorithm with simple implementation
Basically, Insertion sort is efficient for small data values
Insertion sort is adaptive in nature, i.e. it is appropriate for data sets which are already     partially sorted.