Found 1862 Articles for Data Structure

Divide two integers without using multiplication, division and mod operator

Rinish Patidar
Updated on 14-Mar-2023 14:24:05

4K+ Views

In this problem, we simply need to divide two integers without using multiplication, division and mod operator. Though we can use addition or multiplication or bit manipulation. The problem statement states that we will be given two integers x and y. Without using multiplication, division or mod operator, we need to determine the quotient after dividing x by y. Example INPUT: x=15 , y=5 OUTPUT: 3 INPUT: x=10 , y=4 OUTPUT: 2 INPUT: x=-20 , y=3 OUTPUT: -6 Approach Approach-1(using simple mathematics) In this approach, we will use a simple mathematics algorithm. Below is the step-by-step illustration of the ... Read More

Centered Dodecagonal Number

Rinish Patidar
Updated on 14-Mar-2023 14:07:38

152 Views

A figurative number that depicts a dodecagon is called a dodecagonal number. The Centered Dodecagonal number is represented by a dot in the centre and other dots encircling it in the successive dodecagonal (i.e. a 12-sided polygon) layers. Centered Dodecagonal number can be better explained with the below figure. For n=1, only a single dot will be there in the centre. So the output will be 1. For n=2, a single dot in the centre followed by a dodecagon encircling it. Thus, the total number of dots will be 13. So the next centred dodecagonal number ... Read More

Case-specific sorting of strings

Mallika Gupta
Updated on 15-Mar-2023 10:21:25

276 Views

Strings are the storage elements for storing different kinds of letters and symbols. It is indicative of a stream of characters in C++. Strings are denoted in double quotes or single quotes. The given input string can be comprised of both uppercase and lowercase characters. The problem statement is to change the case of the characters of the string, in such a way that the letter which was originally written in lowercase is converted into uppercase and vice versa. Some of the examples illustrating the problem statement are as follows − Sample Examples Example 1 : "AbCd" Output : bAdC ... Read More

Perfect Power (1, 4, 8, 9, 16, 25, 27, …)

Eva Sharma
Updated on 10-Mar-2023 12:35:48

781 Views

A Perfect Power is a Natural Number that is the product of equal natural factors. It can also be defined as an integer that can be expressed as a square power or a higher power of another integer greater than one. For example, 4 can be expressed as the product of 2*2. 27 can be expressed as the product of 3*3*3. Hence, 4 and 27 are perfect powers. Problem Statement Given a number n, find the count of perfect numbers which are less than or equal to n. Example 1 Input = 14 Output = 3 Explanation 1 ... Read More

Legendre’s Conjecture: Concept, Algorithm, Implementation in C++

Eva Sharma
Updated on 10-Mar-2023 12:31:11

188 Views

The Legendre’s Conjecture states that at least one prime number always exists between two consecutive natural numbers' squares. Mathematically, there is always a prime number p between any two numbers n2 and (n+1)2. n is a natural number. A conjecture means a conclusion that doesn't has mathematical proof. Hence, Legendre's Conjecture is just a statement with no mathematical proof. Problem Statement For a number n, print the number of primes in the range of n2 to (n+1)2 from 1 to n. Examples Input: 4 Output: For i = 1: Total primes in the range 1 and 4 = 2 ... Read More

Form a Number Using Corner Digits of Powers

Eva Sharma
Updated on 10-Mar-2023 12:17:23

84 Views

What are Corner digits? The corner digits of a number refer to the rightmost and the leftmost digits. For example, the corner digits of 1234 are 1 and 4. The corner digits of a single-digit number will be the number twice. For example, the corner digits of 2 will be 2 and 2. Problem Statement For given two numbers, n, and x, form a number using the corner digits of all the powers of n from 1 and x, i.e., n1, n2....nx. Examples Input: n = 2, x = 4 Output: 22448816 Explanation 21 = 2. Corner digits = ... Read More

Decimal Equivalent of Gray Code and Its Inverse

Eva Sharma
Updated on 10-Mar-2023 12:08:16

985 Views

Gray code or reflected binary code is a form of a binary representation of numbers in which two consecutive numbers only differ by one bit. For example, the gray code of 1 is 001, while the gray code of 2 is 011. Gray code is usually used in error correction because it prevents some data errors that can happen in the usual binary representations while state changes. Gray code is also helpful in k-maps, communication, etc., because of its unique property. Prerequisite Study decimal, binary and gray code notations before reading further. Problem Statement 1 Given a decimal number n, ... Read More

Cube Free Numbers smaller than n

Eva Sharma
Updated on 10-Mar-2023 12:01:22

195 Views

Cube-free numbers are those numbers that have no cubic divisors. A cubic divisor refers to an integer that is a cube and divides the number with zero remainders. For example, 8 is a cubic divisor of 16 since 8 is a cube of 2 (2*2*2 = 8), and 8 divides 16 with the remainder of zero. Thus, 8 and 16 both are not cube-free numbers. Problem Statement Find all the cube-free numbers less than a given number, n. Example Let's understand the problem with an example. Let n = 15, Thus, we have to find all the numbers less than ... Read More

Square pyramidal number (Sum of Squares)

Eva Sharma
Updated on 10-Mar-2023 11:58:22

211 Views

A Square Pyramidal Number means the Sum of the Square of Natural Numbers. Natural Numbers include all the numbers from 1 to infinity. For example, the first 4 Square pyramidal numbers are 1, 5, 14, 30. For better perception, consider the fact: If we take spheres of numbers equal to the square pyramidal numbers, starting from one, and stack them in descending order, they create a pyramid. Problem Statement Given a number Sum. If Sum is the sum of the squares of first “n” natural numbers, return n, otherwise return false. Example 1 Input = 30 Output = 4 ... Read More

What is an in-memory Queue in Data Structures?

Sonal Meenu Singh
Updated on 22-Feb-2023 16:01:18

1K+ Views

Introduction In this tutorial, we will learn about the in-memory queue in the data structure. A queue is a general data structure that inserts and removes elements with some pattern. It uses the First In First Out approach for its processing. An array and linked lists are used to implement a queue. In-Memory Queue A queue can be visualized as a continuous memory (using an array queue) for storing data types. It is stored in secondary memory. In-memory Queue is different from a simple queue only in terms of its storage area. It is stored in the RAM of your ... Read More

Advertisements