# Category Archives: Algorithms

Bubble Sort Algorithm is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in the wrong order. This algorithm… Read More
Given a singly linked list, sort it using bubble sort. Input : 10->30->20->5 Output : 5->10->20->30 Input : 20->4->3 Output : 3->4->20 C // C… Read More
Given two numbers, write a C program to swap the given numbers. Example: Input: x = 10, y = 20;Output: x = 20, y =… Read More
Selection sort is a simple and efficient sorting algorithm that works by repeatedly selecting the smallest (or largest) element from the unsorted portion of the… Read More
Given two variables, x, and y, swap two variables without using a third variable.  Method 1 (Using Arithmetic Operators)  The idea is to get… Read More
Given an array of integers, find the sum of its elements. Examples: Input : arr[] = {1, 2, 3}Output : 6Explanation: 1 + 2 +… Read More
We basically ignore half of the elements just after one comparison. Compare x with the middle element. If x matches with middle element, we return… Read More
Binary Search is defined as a searching algorithm used in a sorted array by repeatedly dividing the search interval in half. The idea of binary… Read More
We strongly recommend to read following post on suffix trees as a pre-requisite for this post.Pattern Searching | Set 8 (Suffix Tree Introduction)A suffix array… Read More
Similar to the Merge Sort algorithm, the Quick Sort algorithm is a Divide and Conquer algorithm. It initially selects an element as a pivot element… Read More
Like Merge Sort, QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot.… Read More
QuickSort is a sorting algorithm based on the Divide and Conquer algorithm that picks an element as a pivot and partitions the given array around… Read More
Just unlikely merge Sort, QuickSort is a divide and conquer algorithm. It picks an element as a pivot and partitions the given array around the… Read More
The problem is to count all the possible paths from the top left to the bottom right of a M X N matrix with the… Read More
Given an integer array and a positive integer k, count all distinct pairs with differences equal to k.  Examples:  Input: arr[] = {1, 5, 3,… Read More