Found 1862 Articles for Data Structure

How to Turn on a Particular Bit in a Number?

Rinish Patidar
Updated on 21-Aug-2023 18:04:56

139 Views

The problem statement says that we need to turn on a particular bit in a number. To put it simply, all we have to do is swap out a certain bit in a number for 1. Provide the same outcome if it has already been 1. You can represent an integer using binary numbers, which come in the forms of 0 and 1 where every digit represents a power of 2. Let's represent 5 in the binary numbers. The binary form of 5 will be 101 i.e.$\mathrm{2^{2} + 2^{0}= 5.}$ In this problem, a number N will ... Read More

Corollaries of Binomial Theorem

Rinish Patidar
Updated on 21-Aug-2023 21:07:46

169 Views

The Binomial Theorem describes how to expand an expression raised to any finite power. A binomial theorem is a powerful expansion tool that has applications in algebra, probability, and other fields. Assume we have an expression $\mathrm{(x\:+\:y)^n}$and we need to expand the expression, we can do this using the generalised equation of binomial theorem. The binomial theorem defines a binomial expression for two different terms. The general equation of binomial theorem is: $$\mathrm{(a+b)^{n}=^n{C_{r=0}}a^{n-r}b^{0}\:+\:^n{C_{r=1}}a^{n-1}b^{1\:}+\:........\:+\:^n{C_{r=n-1}}a^{1}b^{n-1}+^n{C_{r=n}}a^{0}b^{n}}$$ $$\mathrm{=n_{\sum_{r=0}}^n{C_{r}}a^{n-r}b^{r}}$$ Where we can get the value of $\mathrm{^n{C_{r}}}$ using the formula, $$\mathrm{^n{C_{r}}=\frac{n!}{(n-r)!r!}}$$[0! is always equals to 1] NOTE There ... Read More

Check if three Straight Lines are Concurrent or Not

Rinish Patidar
Updated on 21-Aug-2023 17:53:02

175 Views

The problem includes checking if the three given straight lines are concurrent or not. If all three lines in a plane pass through the same point, they are said to be concurrent. They must intersect with each other exactly at one point to be concurrent. The three concurrent lines are depicted in the above illustration. According to the above illustration, the point of intersection of any two lines should be located on the third line to be concurrent. The point of concurrence is the intersection of these lines.As everyone is aware, a straight line can be written as ... Read More

Program to construct a DFA to check if a given integer is unsigned or not

Shubham Vora
Updated on 18-Aug-2023 18:13:39

150 Views

In this problem, we need to check whether the given number is an unsigned integer using the DFA. We need to construct the DFA using the 2D array to solve the problem. Problem statement – We have given string str of length N. By constructing the DFA, we need to check whether the str represents the unsigned integer. In the output, print ‘unsinged integer’ or ‘Not an unsinged integer’ according to whether the number is unsinged or not. Sample examples Input– str = "1729" Output– “Unsigned integer.” Explanation– As the number doesn’t contain any sign, it is an ... Read More

Python Program to check if two sentences can be made the same by rearranging the words

Shubham Vora
Updated on 18-Aug-2023 18:11:12

106 Views

In this problem, we need to check whether we can make two strings equal by rearranging the words of the string. We will learn three different approaches to solving the problem. In the first approach, we will use a dictionary. In the second approach, we will use the sort() method, and in the third approach, we will use the counter() constructor, which is used to count the hashable objects in the python. Problem statement – We have given a str1 and str2 containing sentences. We need to check whether we can make both strings equal by rearranging the words of ... Read More

Sort an array of strings by replacements with their GCD with elements from another array

Shubham Vora
Updated on 18-Aug-2023 17:39:34

52 Views

In this problem, we have given two arrays of strings. We need to replace array1’s values to sort array1. To replace the values of array1, we can take the GCD of the current string of array1 with any string of array2. The GCD of the string is very similar to the GCD of the number. To solve the problem, we can find a GCD string lexicographically larger than the GCD of the string at the ith index in array1 and the jth index in array2. Problem statement – We have given array1 and array2 containing the strings, and the length ... Read More

Modify characters of a string by adding integer values of same-indexed characters from another given string

Shubham Vora
Updated on 18-Aug-2023 17:38:30

104 Views

In this problem, we need to modify the given string by adding the value of the digit from the num string to the ASCII value of str’s character. To solve the problem, we can convert the digit character to the actual digit and add it to the ASCII value of the character. If the ASCII value becomes greater than 122, we start again from 97. Problem statement – We have given two strings of the same length equal to N. The first string, named str, contains the lowercase alphabetical characters, and the second string, named num, contains digits only. ... Read More

Modify array by removing characters from their Hexadecimal representations which are present in a given string

Shubham Vora
Updated on 18-Aug-2023 15:15:38

47 Views

We have given an array of positive integers and need to modify each element of the array by removing the characters given the ‘hex’ string from the hexadecimal representation of the current element. To solve the problem, we can convert the current number to a hexadecimal number. After that, we can remove the characters from the hexadecimal string, which are common in ‘hex’ and the current hexadecimal string. After modifying the hexadecimal string, we can convert it back to decimal. Problem statement – We have given an array containing positive integers, and the array's length is N. Also, we ... Read More

Modify a Binary String by flipping characters such that any pair of indices consisting of 1s are neither co-prime nor divisible by each other

Shubham Vora
Updated on 18-Aug-2023 15:14:22

90 Views

In this problem, we have given a binary string of length 4*N, and we need to flip zeros of the binary string so that any pair of indices containing ‘1’ should not be co-prime or divisible by each other. Here, we can solve the problem by observation. The string contains 4*N characters. We can flip the N characters from the last, which are at the even index. Problem statement – We have given an integer N and a binary string of the length 4*N containing all zeros initially. We need to flip ‘0’ to ‘1’ in such a way so ... Read More

Reverse alternate k characters in a string

Sonal Meenu Singh
Updated on 18-Aug-2023 16:53:38

180 Views

Introduction In this tutorial, we implement examples using C++ programming logic to reverse the alternate k characters in an input string. We define the value of k to reverse the characters in a given string. K is the number of characters to be reversed. The value of k can be anything. If the value of k is more than the total number of characters in the string we do not reverse any of the string characters. Demonstration 1 String = “tutorialspoint” K = 4 Output otutrialiopsnt In the above demonstration, we consider a string “tutorialspoint” to ... Read More

Advertisements