Found 1862 Articles for Data Structure

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

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

473 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” and “high”. There are 3 basic logic gates − AND Gate AND gate has two or more inputs and one output. It produces a high output if all inputs are high. The truth table for a two-input AND gate is given below − Input 1 Input 2 Output ... Read More

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

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

44 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, y) lying on the circle such that, $\mathrm{x^2 + y^2 = R^2}$ Point (x, y) lying outside the circle such that, $\mathrm{x^2 + y^2 > R^2}$ where R = radius of the circle. Problem Statement Given a string S representing a sequence of moves (L, R, U, D) and ... Read More

Check if a given string is a comment or not

Divya Sahni
Updated on 25-Jul-2023 12:53:09

1K+ Views

In computer programming, comments are text written with the source code but ignored by the compiler or interpreter. They are used to provide readability of code by describing the code and its functionality for someone who is reading the code other than a compiler or interpreter. They are not executed and do not affect the functionality of the overall program, they are just for programmer guidance. Each programming language has a different syntax to represent comments. Here are a few examples − C/C++ − In C or C++, single-lined comments begin with ‘//’ and multi-liner comments are enclosed in ... Read More

Total area of two overlapping rectangles

Divya Sahni
Updated on 25-Jul-2023 12:50:15

715 Views

An overlapping area is an area that is shared by two objects. In the case of rectangles, it is the area of the rectangles that belong to both rectangles. In order to find the total areas of two overlapping rectangles, first er need to add the area of both rectangles respectively but in this total, the overlapping area is counted twice. Thus we need to subtract the overlapping area too. Problem Statement Given the bottom left and top right vertices of two rectangles. Find the total area covered by the two rectangles. Sample Example 1 Input bl_x1 = 0 bl_y1 ... Read More

Sum of Pairwise Products

Divya Sahni
Updated on 25-Jul-2023 12:47:33

688 Views

The pairwise product of a set X = {a, b, c} can be defined as the sum of the product of all possible set pairs. The pairs of the set are, Y = {a * a, a * b, a *c, b * b, b * c, c * c}, where the product is commutative. Thus, the pairwise product of set X is the summation of elements of set Y i.e. aa + ab + ac + bb + bc + cc. In mathematical terms, the sum of possible pair products can be depicted as, $$\mathrm{\displaystyle\sum\limits_{i=1, j=i}^{i\leq n, j\leq n}\:(i, ... Read More

Sum of Minimum and Maximum Elements of all Subarrays of Size K.

Shubham Vora
Updated on 22-Jul-2023 12:47:06

367 Views

In this problem, we need to take the maximum and minimum elements of all sub−array of length K and add them to get the answer. The first solution approach is that traverse through all sub−arrays of size K, find the minimum and maximum element of each sub−array, and add them. The optimized approach to solve the problem is using the deque data structure. We will store the index of the minimum and maximum elements of the subarray in the deque. Problem statement − We have given an array nums[] containing N positive or negative integer values. We have also ... Read More

Reduce the Array to Atmost one Element by the Given Operations

Shubham Vora
Updated on 22-Jul-2023 12:42:30

68 Views

In this problem, we will reduce the array size to 1 or 0 by performing the given operations in each turn. We can sort the array in each turn to get the maximum elements in each iteration. Also, we can use the head data structure to improve the performance of the code. Problem statement − We have given a nums[] array. We need to decrease the array by performing the below operations. Choose two maximum elements of the array. If both elements are the same, remove both elements from the array. If both elements are not the same, remove ... Read More

Rearrange and Update Array Elements as Specified by the given Queries

Shubham Vora
Updated on 22-Jul-2023 12:36:30

138 Views

In this problem, we will perform the given queries on the array elements. The queries contain the circular left rotation, right rotation, and updation of the array element. The logical part of solving the problem is array rotation. The naïve approach to rotating the array in the left direction is to replace each element with the next element and the last element with the first element. We can use the deque data structure to rotate the array efficiently. Problem statement − We have given an arr[] array containing the integer values. Also, we have given a queries[] array containing ... Read More

Heap Sort for decreasing order using min heap

Divya Sahni
Updated on 25-Jul-2023 12:44:09

600 Views

Heap Sort − Heap sort is a comparison-based algorithm that used binary tree data structures to sort a list of numbers in increasing or decreasing order. It heap sorts to create a heap data structure where the root is the smallest element and then removes the root and again sorting gives the second smallest number in the list at the root position. Min Heap − Min heap is a data structure where the parent node is always smaller than the child node, thus root node is the smallest element among all. Problem Statement Given an array of integers. Sort them ... Read More

Print all Prime Levels of a Binary Tree

Shubham Vora
Updated on 22-Jul-2023 12:20:22

68 Views

In this problem, we will print all prime levels of the given binary tree. We will use the level order traversal technique to traverse each binary tree level and check whether all nodes contain the prime integer for the particular level. Problem statement − We have given a binary tree and need to print all prime levels of the binary tree. It is given that if all nodes of any binary tree contain a prime integer, we can say a particular level is a prime level. Sample examples Input  ... Read More

Advertisements