Server Side Programming Articles - Page 2204 of 2650

C++ Program for QuickSort?

Ravi Ranjan
Updated on 12-May-2025 16:52:36

2K+ Views

Quick sort algorithm is also known as partition exchange sort and is based on partitioning of an array of data into smaller sub-arrays. A large array is partitioned into two arrays such that the left sub-array holds values smaller than the pivot element and the right sub-array holds values greater than the pivot value. Quicksort partitions an array and then calls itself recursively twice to sort the two resulting sub-arrays: left and right sub-arrays. Quick sort falls uses the divide and conquer approach of problem-solving methodology. This algorithm is ... Read More

C++ Program for Pigeonhole Sort?

sudhir sharma
Updated on 19-Aug-2019 07:58:11

619 Views

Pigeonhole Sort is an example of the non-comparison sorting technique. It is used where the number of items and the range of possible key values is approximately the same.To perform this sort, we need to make some holes. The number of holes needed is decided by the range of numbers. In each hole, items are inserted. Finally deleted from the hole and stored into an array for sorted order.Pigeonhole sorting, also known as count sort, is a sorting algorithm that is suitable for sorting lists of elements where the number of elements (n) and the number of possible key values ... Read More

C Program for Find the largest prime factor of a number?

sudhir sharma
Updated on 19-Aug-2019 07:55:07

5K+ Views

Prime Factor− In number theory, the prime factors of a positive integer are the prime numbers that divide that integer exactly. The process of finding these numbers is called integer factorization, or prime factorization.Example− Prime factors of 288 are: 288 = 2 x 2 x 2 x 2 x 2 x 3 x 3Input: n = 124 Output: 31 is the largest prime factor!ExplanationYou will find all the prime factors of a number and find the largest of them. The prime factors 124 = 2 x 2 x 31. and 31 is the largest of them.Example#include int main() { ... Read More

Advantages of vector over the array in C++?

sudhir sharma
Updated on 19-Aug-2019 07:53:16

3K+ Views

Vector is a template class and is C++ only construct whereas arrays are built-in language construct and present in both C and C++.Vector are implemented as dynamic arrays with list interface whereas arrays can be implemented as statically or dynamically with primitive data type interface.Differences between a Vector and an ArrayA vector is a dynamic array, whose size can be increased, whereas THE array size can not be changed.Reserve space can be given for vector, whereas for arrays you cannot give reserved space.A vector is a class whereas an array is a datatype.Vectors can store any type of objects, whereas ... Read More

C/C++ Program to Find the reminder of array multiplication divided by n?

sudhir sharma
Updated on 19-Aug-2019 12:58:56

192 Views

Array multiplication we will find the product of all elements of the given array. and then according to the problem, we will divide the product with the number n. let's take an example −Input: arr[] = { 12, 35, 69, 74, 165, 54};       N = 47 Output: 14ExplanationThe array is like {12, 35, 69, 74, 165, 54} so the multiplication will be (12 * 35 * 69 * 74 * 165 * 54) = 19107673200. Now if we want to get the remainder after dividing this by 47 it will be 14.First multiple all the number then ... Read More

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

sudhir sharma
Updated on 19-Aug-2019 07:45:29

646 Views

The unique prime factors is a factor of the number that is a prime number too. In this problem, we have to find the product of all unique prime factors of a number. A prime number is a number that has only two factors, the number and one.Here we will try to find the best way to calculate the product of unique prime factors of a number. let's take an example to make the problem more clear.There is a number say n = 1092, we have to get the product of unique prime factors of this. The prime factors of ... Read More

C/C++ Program to the Count set bits in an integer?

sudhir sharma
Updated on 19-Aug-2019 07:43:40

255 Views

Counting set bits means counting 1’S of the given integer. For this, we have multiple solutions that can be applied. For this case, we have a binary number( binary representation of an integer), for which we have to count the number of 1’s off the string.To count the number of 1’s, we will take the string, traverse each element and count all the 1’s of the string. For example, if we input 17 the output will be 2 because the binary of 17 is 10001 that contains two 1's.Input: Enter a positive integer: 6 Output: 2ExplanationThe binary representation of 6 ... Read More

C/C++ Program to Count number of binary strings without consecutive 1’s?

sudhir sharma
Updated on 04-Aug-2025 18:35:51

365 Views

In this article, we will learn how to count all distinct binary strings of length n such that no two 1's appear consecutively. We'll explore this problem using both recursive and dynamic programming approaches in C and C++. What is a Binary String? A binary string is a sequence of characters that contains only '0' and '1'. It represents information in base-2 format. For example, "0101" is a binary string of length 4. We are given a positive integer n, and our task is to count all possible distinct binary strings of length n that do not contain ... Read More

C/C++ Program to the Count Inversions in an array using Merge Sort?

sudhir sharma
Updated on 19-Aug-2019 07:40:46

305 Views

The Count of inversions that take place to Sort the given array is known as inversion count. the inversion problem is a classical problem that can be solved using the merge sort Algorithm. in this problem v we will count all elements more than it to its left and add the count to output. ThisLogic is done inside merge function of merge sort.For understanding the topic better let us take an example. Let us consider two sub-arrays involved in merge process -  Input: arr[] = { 1, 9, 6, 4, 5} Output: Inversion count is 5ExplanationInversion count of an arrayGiven an ... Read More

C/C++ Program to check whether it is possible to make the divisible by 3 number using all digits in an array?

sudhir sharma
Updated on 19-Aug-2019 07:35:15

418 Views

To check whether a number is divisible by 3, we add all the digits of the number and then calculate that the sum is divisible by 3 or not. In this problem, there is an array of integers arr[], and we have to check if a number formed with these number is divisible by 3. If the number formed is divisible then print ‘yes’ else print ‘no’Input: arr[] = {45, 51, 90} Output: YesExplanationconstruct a number which is divisible by 3, for example, 945510.So the answer will be Yes Find the remainder of the sum when divided by 3 true ... Read More

Advertisements