C++ Articles - Page 175 of 719

C++ program to rearrange all elements of array which are multiples of x in increasing order

Sunidhi Bansal
Updated on 02-Nov-2021 06:07:45

440 Views

We are given an integer type array as ‘int arr[]’ and an integer type variable as ‘x’. The task is to rearrange all the elements of an array in such a manner that they will be divisible by a given integer value ‘x’ and the arrangement should be in an increasing order.Let us see various input output scenarios for this −Input − int arr[] = {4, 24, 3, 5, 7, 22, 12, 10}, int x = 2Output − Rearrangement of all elements of array which are multiples of x 2 in decreasing order is: 4 10 3 5 7 12 22 24Explanation −we ... Read More

Recursive sum of digit in n^x, where n and x are very large in C++

Sunidhi Bansal
Updated on 02-Nov-2021 06:04:24

191 Views

We are given positive integer variables as ‘num’ and ‘x’. The task is to recursively calculate the num ^ x then add the digits of a resultant number till the single digit isn’t achieved and the resultant single digit will be the output.Let us see various input output scenarios for this −Input − int num = 2345, int x = 3Output − Recursive sum of digit in n^x, where n and x are very large are: 8Explanation − we are given positive integer values as num and x with the values as 2345 and power as 3. Firstly, calculate 2345 ^ 3 i.e. ... Read More

Recursive program to print all numbers less than N which consist of digits 1 or 3 only in C++

Sunidhi Bansal
Updated on 02-Nov-2021 05:53:00

585 Views

We are given an integer variable as N storing the positive integer type value. The task is to recursively print all the numbers less than given value N having digit 1, 3 or the combination of both.Let us see various input output scenarios for this −Input − int num = 40Output − Recursive program to print all numbers less than N which consist of digits 1 or 3 only are: 33 31 13 11 3 1Explanation − we are given a positive integer value as 40 stored in a variable num. Now, we will recursively find out all the numbers containing digits 1, ... Read More

Rearrange array such that arr[i] >= arr[j] if i is even and arr[i]<=arr[j] if i is odd and j < i in C++

Sunidhi Bansal
Updated on 02-Nov-2021 05:42:33

236 Views

We are given an integer array containing odd and even integer values. The task is to rearrange an array in such a manner that arr[i] should be greater than or equals to arr[j] based on the condition that value at index arr[i] should be even and if value at arr[i] is odd then arr[i] should be less than equals to arr[j].Let us see various input output scenarios for this −Input − int arr[] = {5, 9, 10, 12, 32, 35, 67, 89}Output − Array after rearranging elements are: 12 32 10 35 9 67 5 89Explanation − we are given an array with ... Read More

Memory representation of Binomial Heap in C++

Sunidhi Bansal
Updated on 22-Oct-2021 09:43:54

525 Views

What is a Binomial Tree?Binomial tree is an ordered tree data structure, let's say, B0 consists of a single node whereas a binomial tree represented as Bk consists of two binomial trees i.e. Bk-1 which are linked together. The root of one binomial tree is the leftmost child of the root of the other binomial tree. Binomial tree is mostly used for fundamental and technical analysing of assets or the stocks.The nodes of a binomial tree represent the intrinsic value of an asset. It helps investors or buyers of the markets to analyze the right time and value for investment.What ... Read More

Min-Max Range Queries in Array in C++

Sunidhi Bansal
Updated on 22-Oct-2021 09:42:24

1K+ Views

Given an array Arr[] containing N elements. The goal is to find the minimum and maximum value from indexes of query.According to the query we are given starting index and ending indexes.For ExampleIn − Arr[] = { 1, 2, 3, 4, 5 } QStart = 1 QEnd = 4Out −Minimum Value : 2Maximum Value : 5Explanation −In the above queries the starting index is 1 and ending index is 4. Between these two indexes, minimum value in Arr is 2 and maximum value is 5In − Arr[] = { 10, 12, 3, 2, 5, 18 } QStart = 2 QEnd = 5Out −Minimum Value : ... Read More

New feature of C++17

Sunidhi Bansal
Updated on 22-Oct-2021 09:07:35

1K+ Views

The C++ Standards committee is always focusing on shipping new features every three years. The two main parts of the specification are the core functionality of the programming language and the Standard Template Library (STL). The new features are introduced to make the code cleaner, easier and compact. Following is the list of features that are introduced-:1. Fold ExpressionsFold expressions are used to write shorter codes for a variable number of arguments that can be passed to a function or can be returned from the function. It enables the use of any number of variables as arguments and in return ... Read More

2-3 Trees - Data Structures and Algorithms in C++

Sunidhi Bansal
Updated on 22-Oct-2021 08:56:52

8K+ Views

A 2-3 Tree is a type of tree in data structures in which every node of the tree is either a 2 nodeor 3 nodes. It is a special type of B-Tree with order 3.A 2 node in the tree is one which has one data part and two child nodes.A 3 node in the tree is one which has two data parts and three child nodes.Fig:- A 2-3 treeProperties of a 2-3 Tree:-Every internal node is either a 2 node or a 3 node.A node containing one data part can be a 2 node with exactly 2 children or ... Read More

Maximize the number of subarrays with XOR as zero in C++

Sunidhi Bansal
Updated on 22-Oct-2021 08:54:16

228 Views

We are given an array Arr[] containing integer values. The goal is to find the maximum number of subarrays with XOR as 0. The bits of any subarray can be swapped any number of times.Note:- 1

Maximize the summation of numbers in a maximum of K moves in range [L, R] in C++

Sunidhi Bansal
Updated on 22-Oct-2021 08:45:52

150 Views

We are given an array Arr[] containing integers and 2D array Q containing queries. Each query contains 3 values that are lpos, rpos and K. One can move from index i to next index i+1 in a single step or remain in that index. One can move from lpos to rpos in a maximum of K steps only. Add all numbers at each step including the leftmost number. The goal is to maximize the sum in maximum K moves. If no movement is possible from lpos to rpos in K steps then print “No”. Let us understand more.Let us see ... Read More

Advertisements