 
 Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Server Side Programming Articles - Page 2126 of 2650
 
 
			
			174 Views
In this tutorial, we will be discussing a program to print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are coprime.In this, we will be given an integer N, we have to print N integers less than 109 such that no two consecutive numbers are coprime but a pair of 3 consecutive integers must be coprime.For example, let us say we have the integer 4. Then the numbers that follow both of the above-provided conditions are6 15 35 14Example#include using namespace std; #define limit 1000000000 #define MAX_PRIME 2000000 #define MAX 1000000 #define I_MAX ... Read More
 
 
			
			4K+ Views
Here we will see how to display all distinct subsets of a given set. So if the set is {1, 2, 3}, then the subsets will be {}, {1}, {2}, {3}, {1, 2}, {2, 3}, {1, 3}, {1, 2, 3}. The set of all subsets is called power set. The power set has 2n elements.We will loop through 0 to 2n (excluding), in each iteration we will check whether the ith bit in the current counter is set, then print ith element.Example#include #include using namespace std; void showPowerSet(char *set, int set_length) { unsigned int size = pow(2, set_length); for(int counter = 0; counter < size; counter++) { cout
 
 
			
			245 Views
In this tutorial, we will be discussing a program to print all the nodes that appear in the top view of a given binary tree.For a particular binary tree, a node appears in its top view if it is the very first node at its horizontal distance. Horizontal distance for the left node of a node x is x-1 and for the right node of node x is x+1.To solve this, we will do the level order traversal so that we get the topmost node for a particular level before the other nodes present at that level. Further, we will ... Read More
 
 
			
			463 Views
Suppose we have a set of integers. Find distinct sum, that can be formed from the subset of the given sets and print them in an ascending order. The sum of array elements is small. Consider the array elements are like [1, 2, 3]. Output will be 0, 1, 2, 3, 4, 5, 6. The distinct subsets are {}, {1}, {2}, {3}, {1, 2}, {2, 3}, {1, 3}, {1, 2, 3}, the sum values are 0, 1, 2, 3, 3, 5, 4, 6.To solve this, we will use the dynamic programming approach. When the sum of given element is small, ... Read More
 
 
			
			174 Views
In this tutorial, we will be discussing a program to print nodes between the two given level numbers of a binary tree.In this, we will be given a low level and a high level for a particular binary tree and we have to print all the elements between the given levels.To solve this we can use queue-based level traversal. While moving through inorder traversal we can have a marking node at the end of each level. Then we can go to each level and print its nodes if the marking node exists between the given levels.Example#include #include using ... Read More
 
 
			
			500 Views
Suppose we have a positive number n. We have to find all combinations of positive numbers, that adds up to that number. Here we want only combinations, not the permutations. For the value n = 4, there will be [1, 1, 1, 1], [1, 1, 2], [2, 2], [1, 3], [4]We will solve this using recursion. We have an array to store combinations, and we will fill that array using recursive approach. Each combination will be stored in increasing order of elements.Example#include using namespace std; void getCombination(int arr[], int index, int num, int decrement) { if (decrement < 0) return; if (decrement == 0){ for (int i = 0; i < index; i++) cout
 
 
			
			308 Views
Problem statementGiven two positive integer N and X. The task is to express N as a sum of powers of X (X0 + X1 +…..+ Xn) such that the number of powers of X should be minimum.Print the minimum number of power of N used to make the sum equal to N.If N = 15 and X = 3 then we need 3 powers of ‘3’ as follows −15 = (32 + 31 + 31)AlgorithmUse below formula to calculate final result −1. If x = 1, then answer will be n only (n = 1 + 1 +…. n times)s ... Read More
 
 
			
			592 Views
Problem statementWe are given N points in a Cartesian plane. Our task is to find the minimum number of points that should be removed in order to get the remaining points on one side of any axis.If given input is {(10, 5), (-2, -5), (13, 8), (-14, 7)} then if we remove (-2, -5) then all remaining points are above X-axis.Hence answer is 1.Algorithm1. Finds the number of points on all sides of the X-axis and Y-axis 2. Return minimum from both of themExample#include #include #define SIZE(arr) (sizeof(arr) / sizeof(arr[0])) using namespace std; struct point{ int x, ... Read More
 
 
			
			329 Views
Problem statementGiven arrival and departure times of all trains that reach a railway station, the task is to find the minimum number of platforms required for the railway station so that no train waits.We are given two arrays that represent arrival and departure times of trains that stop.For below input, we need at least 3 platforms −TrainArrival timeDeparture timeTrain-109:0009:15Train-209:3511:45Train-309:4011:05Train-411:0012:00Train-514:3018:15Train-618:0019:00Algorithm1. Sort arrival and departure time arrays in ascending order 2. Trace the number of trains at any time keeping track of trains that haves arrived, but not departedExample#include #include #define SIZE(arr) (sizeof(arr) / sizeof(arr[0])) using namespace std; int getPlatformCount(int ... Read More
 
 
			
			219 Views
Problem statementGiven a number N, we have to find the minimum number of palindromes required to express N as a sum of themIf N = 15 then 2 palindromes are required i.e. 8 and 7.Algorithm1. Generate all the palindromes up to N in a sorted fashion 2. Find the size of the smallest subset such that its sum is NExample#include #include #include #include using namespace std; vector table; int createPalindrome(int input, bool isOdd){ int n = input; int palindrome = input; if (isOdd) n /= 10; while (n > ... Read More