Check if all bits of a number are set in Python

Yaswanth Varma
Updated on 30-Jul-2025 15:14:27

440 Views

In computers, data is stored in the binary form, which uses the two digits 0 and 1. Each digit in this format is known as a bit. In this article, we are going to check if all bits of a number are set in Python. A bit is said to be set if the binary representation of every bit is 1. Let's look at some scenarios to understand this better: Scenario 1 Input: 3 Binary: 111 Output: True Explanation: All bits are 1. Scenario 2 Input: 6 Binary: 110 Output: False Explanation: Not all bits are 1. ... Read More

What does the operation c=a+++b mean in C/C++?

Aman Kumar
Updated on 30-Jul-2025 15:03:20

2K+ Views

In C/C++, the expression c = a++ + b indicates that the current value of a is added to b, and the result is assigned to c. After this assignment, a is incremented by 1 (post-increment), which means the increment of a happens after its value is used in the expression. Well, let a and b initialize with 2 and 5, respectively. This expression can be taken as two different types. c = (a++) + b c = a + (++b) The above two expressions contain both post and pre-increment ... Read More

Angle between two Planes in 3D in C Program?

Aman Kumar
Updated on 30-Jul-2025 14:13:45

170 Views

In 3D geometry, planes are flat surfaces extending infinitely in space. When two planes intersect, they form a line, and the angle between them becomes an important geometric measure. In this article, we will learn how to calculate the angle between two planes in 3D space using a C program. The diagram below illustrates two planes intersecting in 3D space. These planes can be represented by the following equations: Equation P1: a1 * x + b1 * y + c1 * z + d1 = 0 P2: a2 * x + b2 * y + c2 * ... Read More

Print level order traversal line by line in C++ Programming.

Aman Kumar
Updated on 30-Jul-2025 13:09:16

400 Views

Level Order Traversal, also known as Breadth-First Search (BFS), is a method of traversing a tree where nodes are visited level by level, starting from the root node and moving left to right within each level. In this article, our task is to print the nodes of a binary tree in level order, with each level displayed on a separate line. For example, if the binary tree (consider the below image) is traversed in level order. The output will look like this: 1 2 3 4 5 Printing Level Order Traversal Line by Line The following are the ... Read More

Add n binary strings in C++?

Nishu Kumari
Updated on 29-Jul-2025 18:52:05

284 Views

We are given n binary strings, and we need to add them together and return the result (as a binary string). A binary string is a string that consists only of the characters '0' and '1', which represent binary digits. We will add them bit by bit using binary addition rules. Addition of Binary Numbers Here's how binary addition with binary numbers works: 1 + 0 = 1 0 + 1 = 1 0 + 0 = 0 1 + 1 ... Read More

Get Size of Java LinkedHashSet

Aishwarya Naglot
Updated on 29-Jul-2025 18:49:52

393 Views

LinkedHashSet is a collection in Java that maintains the insertion order of elements. It is part of the Java Collections Framework and extends the HashSet class. It stores unique elements and allows null values, but only one null element. It is similar to HashSet; the main difference is that a LinkedHashSet maintains a linked list holding of the entries of the current object, allowing it to maintain the order of elements. Let's learn how to get the size of a LinkedHashSet in Java. The following are some example scenarios: Scenario 1 Input : set = {1, 2, 3, 4, ... Read More

Get an element from a Stack in Java without removing it

Aishwarya Naglot
Updated on 29-Jul-2025 18:46:42

3K+ Views

The Stack is a data structure that is used to store elements in a Last In First Out (LIFO) manner. In Java, a stack is represented by the java.util.Stack class. It provides methods to create and manipulate a stack. Get an Element of a Stack without Removing it The pop() method of the Stack class removes the element at the top of the stack and returns it. But there is no direct way to access an element without removing it. However, we can see/view the top element of a Stack in Java using the peek() method. This method returns the ... Read More

Find the largest three elements in an array in C++

Akansha Kumari
Updated on 29-Jul-2025 17:55:31

10K+ Views

An array is a group of similar data elements stored at contiguous memory locations. It is one of the fundamental data structures in programming and used to store and manage multiple values of the same type. Here, we are given an array arr[] containing N unsorted elements, and our task is to find the three largest elements from this array. To understand the problem better. let's see the following example scenarios: Scenario 1 Input: arr[] = {7, 3, 9, 12, 1} Output: 12, 9, 7 Scenario 2 Input: arr[] = {15, 22, 6, 3, 11, 8} Output: 22, 15, ... Read More

3-way Merge Sort in C++

Aman Kumar
Updated on 29-Jul-2025 16:22:31

2K+ Views

Merge sort is a popular sorting algorithm that follows the divide-and-conquer strategy. It works by recursively dividing the input array into two halves, sorting each half, and then merging them. With a time complexity of O(n log n). 3-Way Merge Sort An optimized variation of merge sort is the 3-way merge sort, where the array is divided into three equal parts instead of two. This reduces the number of recursive calls and improves performance in certain scenarios. 3-Way Merge Sort algorithm Following are the steps (algorithm) to implement the 3-way merge sort: Divide the array ... Read More

Can a constructor be made final in Java?

Aishwarya Naglot
Updated on 29-Jul-2025 16:21:25

7K+ Views

A constructor is a special method in Java that is used to initialize objects. It gets called when an instance of a class is created. The constructor has the same name as the class and does not have a return type. The question is whether a constructor can be declared or made final in Java? The answer is no. Let's understand why. Why can't we declare a Java Constructor "final"? In Java, the final keyword is used to restrict modification of the members of a class (methods and variables). For example, a final method of a class cannot be overridden ... Read More

Advertisements