Arnab Chakraborty has Published 4458 Articles

Absolute difference between the first X and last X Digits of N?

Arnab Chakraborty

Arnab Chakraborty

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

324 Views

Here we will see how to get the differences between first and last X digits of a number N. The number and X are given. To solve this problem, we have to find the length of the number, then cut the last x digits using modulus operator. After that cut ... Read More

Absolute Difference between the Product of Non-Prime numbers and Prime numbers of an Array?

Arnab Chakraborty

Arnab Chakraborty

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

109 Views

Here we will see how we can find the absolute difference between the product of all prime numbers and all non-prime numbers of an array. To solve this problem, we have to check whether a number is prime or not. One possible way for primality testing is by checking a ... Read More

Absolute Difference between the Sum of Non-Prime numbers and Prime numbers of an Array?

Arnab Chakraborty

Arnab Chakraborty

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

114 Views

Here we will see how we can find the absolute difference between the sum of all prime numbers and all non-prime numbers of an array. To solve this problem, we have to check whether a number is prime or not. One possible way for primality testing is by checking a ... Read More

Absolute distinct count in a sorted array?

Arnab Chakraborty

Arnab Chakraborty

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

85 Views

In this section we will see how to count how many of elements whose absolute values are distinct? Suppose in an array there are few elements like {5, 5, 6, -5, 8, 2, -2, 1}, so there are 8 elements. But there are 5 elements {5, 6, 8, 2, 1} ... Read More

C++ Program for Cocktail Sort?

Arnab Chakraborty

Arnab Chakraborty

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

466 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

253 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

328 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

75 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

202 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

796 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

Advertisements