Definition of Algorithm
Definition of Algorithm
#include <stdio.h>
int main()
{
return 0;
}
Output
Enter the 1st number: 0
Enter the 2nd number: 0
Enter the 3rd number: -1577141152
Pseudocode Examples:
1. Binary search Pseudocode:
Binary search is a searching algorithm that works only for sorted
search space. It repeatedly divides the search space into half by
using the fact that the search space is sorted and checking if the
desired search result will be found in the left or right half.
Example: Given a sorted array Arr[] and a value X, The task is
to find the index at which X is present in Arr[].
Below is the pseudocode for Binary search.
BinarySearch(ARR, X, LOW, HIGH)
repeat till LOW = HIGH
MID = (LOW + HIGH)/2
if (X == ARR[MID])
return MID
else
HIGH = MID – 1
2. Quick sort Pseudocode:
QuickSort is a Divide and Conquer algorithm. It picks an element
as a pivot and partitions the given array around the picked pivot.
Say last element of array is picked as pivot then all elements
smaller than pivot element are shifted on the left side of pivot
and elements greater than pivot are shifted towards the right of
pivot by swapping, the same algorithm is repeatedly followed for
the left and right side of pivot until the whole array is sorted.
Below is the pseudocode for Quick sort
QUICKSORT(Arr[], LOW, HIGH) {
if (LOW < HIGH) {
PIVOT = PARTITION(Arr, LOW, HIGH);
QUICKSORT(ARR, LOW, PIVOT – 1);
QUICKSORT(ARR, PIVOT + 1, HIGH);
}
}
Here, LOW is the starting index and HIGH is the ending index.
A Pseudocode is a step-by-step
A Flowchart is pictorial representation of flow description of an algorithm in code
of an algorithm. like structure using plain English
text.
Conclusion:
In the above discussion, we understood the importance of
pseudocode in understanding an algorithm. Pseudocode is a lot
simpler to construct and debug as compared to an algorithm.