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

Find the Largest Prime Factor of a Number in C

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 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

Find Product of Unique Prime Factors of a Number in C/C++

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

644 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

Count Set Bits in an Integer using C/C++

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

Count Inversions in an Array Using Merge Sort in C/C++

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

304 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

HTML DOM Figure Object

AmitDiwan
Updated on 19-Aug-2019 07:40:08

147 Views

The HTML DOM Figure object is used for reperesenting the HTML element. We can dynamically create and access a figure element using the figure object.SyntaxFollowing is the syntax for creating a Figure object −var p = document.createElement("FIGURE");ExampleFollowing is how you can create Figure object −    function createFigure(){       var fig = document.createElement("FIGURE");       fig.setAttribute("id", "Figure1");       document.body.appendChild(fig);       var i = document.createElement("IMG");       i.setAttribute("src", "https://www.tutorialspoint.com/servlets/images/servletsmini-logo.jpg");       i.setAttribute("width", "250");       i.setAttribute("height", "200");       i.setAttribute("alt", "Eiffel Tower");       fig.appendChild(i);   ... Read More

Check Divisibility by 3 Using Array Digits in C/C++

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

417 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

C++ Program for the Triangular Matchstick Number

sudhir sharma
Updated on 19-Aug-2019 07:33:21

228 Views

A triangle that is made by using matchsticks arrange to make an equilateral triangle, this is called the triangular matchstick number. Triangular matchstick number is the number of matchsticks required to make the matchstick triangle.In this problem, we have the number is the floor of a matchstick pyramid, X. and our task is to write a program to print the total minimum number of matchstick required to form a pyramid of matchsticks of x floors.Let's look at an example that will make the concept more clear, Input: 7 Output: 84ExplanationThis is an extension of triangular numbers. For integer X, the ... Read More

C++ Program for Odd-Even Sort (Brick Sort)

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

510 Views

The odd-even sword also known as the brick sort is a similar sorting technique, like bubble sort. This sorting technique is subdivided into 2 phases odd phase and even phase, Both these phases simultaneously at every iteration until all the elements get sorted.The Odd phase of this programming technique works as a bubble sort but only on the elements that have an odd index.Similarly, the even phase works only on the elements that have an even index.For making this concept more clear let's take an example :Input: a[]={3, 5, 7, 6, 1, 4, 2} Output: 1 2 3 4 5 ... Read More

Advertisements