Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by sudhir sharma
Page 51 of 98
Position of rightmost different bit in C++
In this problem, we are given two numbers N and M. Our task is to find the index of the rightmost different bit in the binary representation of the number.Let’s take an example to understand the problem, Input − N = 12 , M = 9Output − 2Explanation − (12)2 = 1100 and (10)2 = 1010.The second bit from right is a different bit.To solve this problem, we will have to find all the different bits of the numbers. To find all different bits we will find xor of M and N. Then we will find the rightmost bit of M^N.This seems ...
Read MorePosition of rightmost common bit in two numbers in C++
In this problem, we are given two numbers M and N. Our task is to print the position (index) of the rightmost common bit of the two numbers.Let’s take an example to understand the problem, Input − N = 4 , M = 7Output − 3Explanation − (4)2 = 100 , (7)2 = 111. The rightmost common bit is at index 3.To solve this problem, we will have to find all the same bits of the numbers. To find all same bits we will find xor of M and N. Then we will find the rightmost bit in the negation ...
Read MorePosition of rightmost bit with first carry in sum of two binary in C++
In this problem, we are given two positive integers N and M. Our task is to print the rightmost bit that generates the first carry bit in the binary addition of the sum of N and M.Let’s take an example to understand the problem, Input − N = 5, M = 14Output − 3Explanation −(5)2 = 0101 , (14)2 = 1110 Sum 0101 + 1110 10011To solve this problem, we will consider some observations from boolean algebra.The sum will generate a carry when both numbers are 1. So, we will find all bits where carry is generated. ...
Read MorePosition of a person diametrically opposite on a circle in C++
In this problem, we are given two integers N and M. there is a circle and N people are standing on it. M denotes the position of a person. Our task is to print the position of the person opposite to M.Let’s take an example to understand the problem, Input − N = 6, M = 3Output − 6Explanation −To solve this problem, there will be two cases, one if the position is greater than half the position (second half), the opposition will be the first half and vise versa.Let’s create a formula for this mathematically, Case 1 − if ...
Read MorePosition after taking N steps to the right and left in an alternate manner in C++
In this problem, we are given three integers N, A and B. there is a person who is standing at coordinate 0 movesA step towards the right and then B step towards left. Then again right. Our task is to print the final position of the element after N moves.Let’s take an example to understand the problem, Input − N = 4, A = 3, B = 1Output −Explanation −1st move -> right 3, +3 2nd move -> left 1, -1 3rd move -> right 3, +3 4th move -> left 1, -1. Position after 4 moves, +3-1+3-1 = 4.To ...
Read MorePopulate Inorder Successor for all nodes in C++
In this problem, we are given a tree. The structure contains a pointer next. Our task is to populate this pointer with the inorder successor of the node.struct node { int value; struct node* left; struct node* right; struct node* next; }All the next pointer are set to NULL and we have to set the pointer to the inorder successor of the node.Inorder traversal − This traverses in the following form, Left node -> root Node -> right node.Inorder successor − the inorder successor is the node that comes after the current node is the inorder ...
Read MorePolybius Square Cipher in C++
In this problem, we are given a string and we have to find its integer encryption using the Polybius Square Cipher.Polybius Square CipherIt is a table that is used for the conversion of letters into numbers. The table for English encryption is a 5X5 table i.e. contains 25 cells for 26 alphabets of an English dictionary. The letters i and j are kept together in a single cell.The following table shows a Polybius square Cipher −123451ABCDE2FGHI, JK3LMNOP4QRSTU5VWXYZThe letter of the tables can be randomized. Also, the size of the table can be changed based on the number of alphabets of ...
Read MorePolicy-based data structures in g++
g++ compiler is a C++ compiler for GNU in Linux.The g++ compiler also adds support for some special data structures that are not in C++ programming language standard library. These are known as policy-based data structures.The policy-based data structures provide the programmer a high-performance, semantic safety and flexibility as compared to the standard data structures of C++ std library.To include these data structures to your program, the following lines should be added, #include using namespace __gnu_pbds;ExampleLet’s see a program to see how these policy-based data structures work.#include #include #include #include using namespace __gnu_pbds; using namespace ...
Read MorePolicemen catch thieves in C++
In this problem, we are given an array of n elements. Each element of the array has either a policeman or a thief, one thief can be caught by one police and we have to find the maximum number of thieves that can be caught by the police if a policeman can catch a thief k units away from him.Let’s take an example to understand the problem, Input −array = {T, P, P, P, T , T, T} K = 2.Output − 3Explanation − here, each policeman will catch a thief, P at index 1 will catch T at index ...
Read MorePoint to next higher value node in a linked list with an arbitrary pointer in C++
In this problem, we are given a linked list with a value, link pointer and an arbitrary pointer. Our task is to make the arbitrary pointer point to point the next large value in the list.Let’s take an example to understand the problem, Here, we can see 8 points to 12, 12 to 41, 41 to 54, 54 to 76 which are successive larger elements of the linked list.To solve this problem, we will use the merge sort algorithm to sort elements and use the sort as a linked list for the arbitrary pointer.For this we will use the merge ...
Read More