Found 7347 Articles for C++

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

467 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

150 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

343 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

734 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

813 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

6K+ 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

145 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

89 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

Minimum Sum Path In 3-D Array in C++

Sunidhi Bansal
Updated on 22-Oct-2021 08:35:04

91 Views

We are given a cube which can be formed using a 3-D array as cube[length][breadth][height]. The task is to calculate the minimum sum path which will be achieved by traversing the cube and hence print the result.Let us see various input output scenarios for this -In − int cube[length][breadth][height] = { { {2, 4, 1}, {3, 4, 5}, {9, 8, 7}}, { {5, 3, 2}, {7, 6, 5}, {8, 7, 6}}, { {3, 2, 1}, {4, 3, 2}, {5, 4, 3}}}Out  − Minimum Sum Path In 3-D Array are: 15Explanation − we are given a cube having length, breadth and height. Now, we ... Read More

Midy’s theorem in C++

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

161 Views

We are given integer values as a_num that will store the numerator and p_den that will store the denominator which should be a prime number. The task is to check whether the operations performed on a_num after dividing with p_den proves the midy’s theorem or not.Steps to prove Midy’s theorem are-Input numerator as a_num and denominator as p_den which should always be a prime value.Divide the numbers. Check for the repeating decimal values.Store the decimal values until they are not repeating.Check whether the digits are even, if yes, then break them into halvesAdd both the numbers. If the output is ... Read More

Advertisements