Arnab Chakraborty has Published 4293 Articles

C++ Program for Cocktail Sort?

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Jul-2019 22:30:26

638 Views

The Cocktail sort is another variation of bubble sort. In the bubble sort technique, it always searches from left to right, and finds the largest element at the end, in the second phase it finds the second largest element at the second last position. This sorting technique traverses in both ... Read More

C++ Program for Comb Sort?

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Jul-2019 22:30:26

353 Views

The basic idea of comb sort and the bubble sort is same. In other words, comb sort is an improvement on the bubble sort. In the bubble sorting technique, the items are compared with the next item in each phase. But for the comb sort, the items are sorted in ... Read More

C++ Program for Gnome Sort?

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Jul-2019 22:30:26

496 Views

Here we will see how the gnome sort works. This is another sorting algorithm. In this approach if the list is already sorted it will take O(n) time. So best case time complexity is O(n). But average case and worst case complexity is O(n^2). Now let us see the algorithm ... Read More

C++ Program for Largest K digit number divisible by X?

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Jul-2019 22:30:26

144 Views

In this problem we will try to find largest K-digit number, that will be divisible by X. To do this task we will take the largest K digit number by this formula ((10^k) – 1). Then check whether the number is divisible by X or not, if not, we will ... Read More

C++ Program for Range sum queries without updates?

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Jul-2019 22:30:26

325 Views

Here we will see how to get the sum of elements from index i to index j in an array. This is basically the range query. The task is easy by just running one loop from index i to j, and calculate the sum. But we have to care about ... Read More

C++ Program for Recursive Bubble Sort?

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Jul-2019 22:30:26

1K+ Views

In this section we will see another approach of famous bubble sort technique. We have used bubble sort in iterative manner. But here we will see recursive approach of the bubble sort. The recursive bubble sort algorithm is look like this.AlgorithmbubbleRec(arr, n)begin    if n = 1, return    for ... Read More

C++ Program to find sum of even factors of a number?

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Jul-2019 22:30:26

393 Views

In this section we will see how we can get the sum of all even prime factors of a number in an efficient way. There is a number say n = 480, we have to get all factor of this. The prime factors of 480 are 2, 2, 2, 2, ... Read More

C++ Program to Split the array and add the first part to the end?

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Jul-2019 22:30:26

521 Views

Here we will see how to split an array, and add the first part after splitting at the end position. Suppose the array contents are {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. We want to cut this intro two parts. The first part is from index 0 ... Read More

C/C++ Program for Finding the vertex, focus and directrix of a parabola?

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Jul-2019 22:30:26

173 Views

Here we will see how to find the vertex, focus directrix of a parabola using C or C++ program. To get these parameters we need the general equation of a parabola. The general formula is −𝑦 = 𝑎𝑥2 + 𝑏𝑥 + 𝑐The values of a, b and c are given.The formula ... Read More

C/C++ Program to find Product of unique prime factors of a number?

Arnab Chakraborty

Arnab Chakraborty

Updated on 30-Jul-2019 22:30:26

665 Views

In this section we will see how we can get the product of unique prime factor of a number in an efficient way. There is a number say n = 1092, we have to get product of unique prime factors of this. The prime factors of 1092 are 2, 2, ... Read More

Advertisements