Found 7197 Articles for C++

A-Buffer Method in C/C++?

Arnab Chakraborty
Updated on 29-Jan-2020 07:07:58

2K+ Views

A-Buffer technique in computer graphics is a simple hidden face detection mechanism used to medium scale virtual memory computers. This technique is also known as anti-aliased or area-averaged or accumulation buffer. This technique extends the algorithm of depth-buffer (or Z Buffer) technique. As the depth buffer technique can only be implemented for opaque object but not for transparent object, the A-buffer technique provides advantage in this scenario. Though the A buffer technique requires more memory, but different surface colors can be correctly composed implementing it. Being a descendent of the Z-buffer algorithm, each position in the buffer can locate or ... Read More

A Number Link Game in C/C++?

Arnab Chakraborty
Updated on 29-Jan-2020 07:04:03

262 Views

The Game − Suppose an n × n array of squares. Out of these, some of the squares are empty, some are solid, and some non-solid squares are set by integers 1, 2, 3, … .Each integer maintains or occupies exactly two different squares on the board. The task of the player is to connect the two occurrences of each integer on the board with the help of a simple path implementing horizontal and vertical movements alone. No two different paths are permitted to intersect one another. No path may include any solid square (solid squares are not permitted to ... 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

2-3 Trees (Search and Insert) in C/C++?

Aman Kumar
Updated on 25-Jul-2025 17:12:28

923 Views

What is 2-3 Trees? A 2-3 tree is a tree data structure, where each internal node has either 2 or 3 children (also, we can say that 2-nodes and 3-nodes, respectively). It is a type of B-tree that ensures efficient search, insertion, and deletion operations with O(logn) time complexity. Properties of 2-3 tree 2-node contains one data element and has two children (or none if it is a leaf). 3-node contains two data elements and has three children (or none if it is a leaf). Data ... Read More

0/1 Knapsack using Branch and Bound in C/C++?

Ravi Ranjan
Updated on 05-May-2025 12:29:17

3K+ Views

In the 0-1 knapsack problem, a set of items is given, each with a weight and a value. We need to determine the number of each item to include in a collection so that the total weight is less than or equal to the given limit and the total value is as large as possible. What is Branch and Bound Algorithm?The branch and bound algorithm breaks the given problem into multiple sub-problems and then uses a bounding function. It eliminates only those solutions that cannot provide optimal solutions. In this article, we will discuss how to solve the 0-1 knapsack problem ... Read More

Convert Binary Number in a Linked List to Integer in C++

Arnab Chakraborty
Updated on 27-Apr-2020 09:16:41

815 Views

Suppose we have one ‘head’ which is a reference node to a singly-linked list. The value of each node present in the linked list is either 0 or 1. This linked list stores the binary representation of a number. We have to return the decimal value of the number present in the linked list. So if the list is like [1, 0, 1, 1, 0, 1]To solve this, we will follow these steps −x := convert the list elements into an arraythen reverse the list xans := 0, and temp := 1for i in range i := 0, to size ... Read More

Shift 2D Grid in C++

Arnab Chakraborty
Updated on 27-Apr-2020 09:14:50

613 Views

Suppose we have one 2D grid of size m x n. We have another variable k. We have to shift the grid k times. The shift operation will be as followsElement at grid G[i, j] moves to G[i, j + 1]Element at grid G[i, n – 1] moves to G[i + 1, 0]Element at grid G[m - 1, n – 1] moves to G[0, 0]So if the grid is like −123456789The output will be −912345678To solve this, we will follow these steps −The shift operation will take the matrix as inputn = number of rows, m := number of columns, ... Read More

Play with Chips in C++

Arnab Chakraborty
Updated on 27-Apr-2020 09:10:14

406 Views

Suppose there are some chips, the i-th chip is at present at position chips[i]. We can perform any of the two following types of operations any many numbers of times as we want (possibly zero) on any chip −Move the i-th chip by 2 units to the left side or to the right side with a cost of 0.Move the i-th chip by 1 unit to the left side or to the right side with a cost of 1.Initially, there can be two or more chips. We have to return the minimum cost needed to move all the chips to ... Read More

Merge Two Binary Trees in C++

Arnab Chakraborty
Updated on 27-Apr-2020 08:59:01

744 Views

Suppose we have two binary trees and consider that when we put one of them to cover the other, some nodes of the two trees are overlapped while the others are overlapping. We have to merge them into a new binary tree. The merge rule is like that if two nodes are overlapping, then sum node values up as the new value of the merged node. Otherwise, the non-empty node will be used as the node of the new tree.So if the trees are −Then the output will be −To solve this, we will follow these steps −The method is ... Read More

Path Sum III in C++

Arnab Chakraborty
Updated on 04-May-2020 06:33:43

269 Views

Suppose we have given a binary tree in which each node holds an integer key. We have to find the paths that sum to a given value. The path should start from root to leaf. We have to find the path where the sum is same.If the tree is like [5, 4, 8, 11, null, 13, 4, 7, 2, null, null, 5, 1], and sum is 22, then it will be −The paths are [[5, 4, 11, 2], [5, 8, 4, 5]].To solve this, we will follow these steps −Use the dfs function to solve this problem, the dfs is ... Read More

Advertisements