Category Archives: Algorithms

Find GCD of two numbers

Given two numbers A and B, the task is to calculate GCD of A and B. Examples: Input : A = 4, B = 6 Output : 2 Input : A = 5, B = 10 Output : 5 GCD (Greatest Common Divisor) of two number is the largest number that divides both of them. A simple solution… Read More »

Find the Nth Fibonacci Number

Given a number N, the task is to find Nth Fibonacci number. The Fibonacci numbers are the numbers in the following integer series. 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ……. In this series, each number is the sum of the two preceding ones starting from 0 and 1. Examples: Input :… Read More »

Find Top-Ranked Student Based on Exam Scores in C++

There are N student from class 12th,each student finished thier exam and exam consist with four subjects like math, computer, physics and chemistory. Result is announced and result list consist with student identity number with their corresponding marks scored in each subject. Our task is to find ranked student among the N student. Example: Suppose there are 5… Read More »

Introduction to Dynamic Programming

Dynamic Programming is an algorithmic approach to solve some complex problems easily and save time and number of comparisons by storing the results of past computations. The basic idea of dynamic programming is to store the results of previous calculation and reuse it in future instead of recalculating them. Consider a simple example of calculating Factorials from 1… Read More »

Grid and alphabets

Amanada, a school kid, is learning English alphabets. Her teacher devised a small game to make the task fun. A grid of ‘m’ rows and ‘n’ columns is filled with English alphabets. She needs to search English words in this grid by moving one step at a time in any of the adjacent grid cells. A grid of… Read More »

What is Backtracking? And why is it used?

Backtracking is an algorithm that searches for possible combinations in order to solve computational problems. It is used for solving problems recursively by building increments and removing solutions that do not satisfy given constraints. This technique finds a solution among all possible solutions. Comparison with Brute-Force Approach: Backtracking is an improvement technique of the Bruteforce technique. These are… Read More »

A brief introduction to a new stable sorting algorithm – Quadsort

1. Overview We’ll discuss Quadsort in this article. It’s a new stable sorting algorithm. We’ll begin from the concept of stable sorting and some sorting algorithms. Then, we’ll discuss the Quadsort algorithm step by step. We’ll discuss an example of Quadsort with flowchart to show in the process. 2. Stable Sorting Algorithms The relative order of the identical… Read More »