Divya Sahni has Published 42 Articles

Print numbers in the range 1 to n having bits in an alternate pattern

Divya Sahni

Divya Sahni

Updated on 28-Sep-2023 14:26:29

57 Views

Alternate bit pattern implies the positioning of 0’s and 1’s in a number at an alternate position i.e. no two 0s or 1’s are together. For example, 10 in binary representation is (1010)2 which has an alternate bit pattern as 0’s and 1’s are separated by each other. Problem Statement ... Read More

Jacobsthal and Jacobsthal-Lucas Numbers

Divya Sahni

Divya Sahni

Updated on 28-Sep-2023 14:19:17

146 Views

Jacobsthal Numbers Lucas sequence 𝑈𝑛(𝑃, 𝑄) where P = 1 and Q = -2 are called Jacobsthal numbers. The recurrence relation for Jacobsthal numbers is, $$\mathrm{𝐽_𝑛 = 0\: 𝑓𝑜𝑟 \: 𝑛 = 0}$$ $$\mathrm{𝐽_𝑛 = 1\: 𝑓𝑜𝑟 \: 𝑛 = 1}$$ $$\mathrm{𝐽_𝑛 = 𝐽_𝑛−1 + 2𝐽_{𝑛−2}\: 𝑓𝑜𝑟 \: 𝑛 > ... Read More

Increment a number by 1 by manipulating the bits

Divya Sahni

Divya Sahni

Updated on 28-Sep-2023 14:03:06

323 Views

Bit manipulation applies logical operations on a bit stream using bitwise operators like AND(&), OR(|), NOT(~), XOR(^), Left Shift() to get a required result. Using bitwise operators is beneficial as we can manipulate individual bits and they are faster than other operators. Problem Statement Given a number. Increment or add ... Read More

Sum of Fourth Powers of first N natural numbers

Divya Sahni

Divya Sahni

Updated on 28-Sep-2023 12:07:35

230 Views

The fourth power of a number x is x raised to the power 4 or x4. Natural numbers are all positive integers excluding zero. Thus, the sum of the fourth powers of the first N natural numbers is − $\mathrm{Sum = 1^4 + 2^4 + 3^4 + 4^4 + … ... Read More

QuickSort using Random Pivoting

Divya Sahni

Divya Sahni

Updated on 04-Sep-2023 09:37:30

1K+ Views

Quick Sort is a Divide and Conquer algorithm. In this algorithm, we elect a pivot element and then partition the array around the pivot element. The two partitions are such that one part contains elements all lower than the pivot element and the other part contains elements all higher than ... Read More

Program to print binomial expansion series

Divya Sahni

Divya Sahni

Updated on 25-Jul-2023 15:08:27

250 Views

Binomial expansion is a mathematical formula used to expand the expressions of the form (a+b)^n, where n is a positive integer and a and b can be any real or complex numbers. The expansion gives the coefficients of the terms in the expansion. A binomial expansion can be represented as ... Read More

Python program to print words from a sentence with highest and lowest ASCII value of characters

Divya Sahni

Divya Sahni

Updated on 25-Jul-2023 13:42:40

168 Views

ASCII (American Standard Code for Information Interchange), is a character encoding system that represents every character as a unique 7-bit binary code i.e. ASCII values are a numerical representation of characters. The ASCII values are 7-bit binary codes that range from 0 to 127. For Example, the ASCII code for ... Read More

Modify array of strings by replacing characters repeating in the same or remaining strings

Divya Sahni

Divya Sahni

Updated on 25-Jul-2023 13:28:25

115 Views

Modifying an array of strings by replacing characters repeating in the same or remaining strings is a common problem in programming. It can be solved using hash tables, sets, arrays etc. The aim is to improve the time and space requirements while providing the same functionality. This problem can be ... Read More

Minimum number of basic logic gates required to realize given Boolean expression`

Divya Sahni

Divya Sahni

Updated on 25-Jul-2023 13:26:02

389 Views

Logic gates are the basic building block of a digital circuit. They take in one or two binary inputs and return a binary output. Since, using the term binary, the output and input can either be 0 or 1 or it can be said as “false” and “true” or “low” ... Read More

Check if it is possible to reach any point on the circumference of a given circle from origin

Divya Sahni

Divya Sahni

Updated on 25-Jul-2023 13:21:11

39 Views

The circumference of a circle can be defined as the outer boundary of the circle. It is the perimeter of a circle. Each point around a circle follows certain properties as follows − Point (x, y) lying inside the circle such that, $\mathrm{x^2 + y^2 < R^2}$ Point (x, ... Read More

Advertisements