Found 7197 Articles for C++

Binomial Heap in C++?

Arnab Chakraborty
Updated on 29-Jan-2020 12:10:57

499 Views

Binomial Heap is defined as an extension of Binary Heap that provides faster merge or union operation together with other operations provided by Binary Heap.A Binomial Heap is treated as a collection of Binomial Trees.What is a Binomial Tree?A Binomial Tree of order k can be built by taking two binomial trees of order k-1 and treating one as leftmost child or other.A Binomial Tree of order k has below properties.The number of nodes of Binomial Tree has exactly 2k.The depth of Binomial Tree is k.There are exactly kCi nodes at depth i where i = 0, 1, . . ... Read More

Binary Tree to Binary Search Tree Conversion using STL set C++?

Arnab Chakraborty
Updated on 29-Jan-2020 12:11:48

727 Views

In case of a given Binary Tree, convert it to a Binary Search Tree in such a way that keeps the original structure of Binary Tree intact.Sets of C++ STL will be used by this solution instead of array based solution.ExamplesExample 1Input     11     /  \    3    8 /     \ 9 5Output     9    /   \   5     11  /        \ 3        8Example 2Input      11      /   \     31    16    /        \  21 ... Read More

Binary Number System - Overflow in Arithmetic Addition in C/C++?

Arnab Chakraborty
Updated on 29-Jan-2020 11:43:59

877 Views

2’s Complement Number System is widely implemented in computer architecture.N-bit 2’s Complement number System can be able to represent Number from -2n-1 to 2n-1- 14 Bit can be able to represent numbers from ( -8 to 7 )5 Bit can be able to represent numbers from ( -16 to 15 ) in 2’s Complementary System.Overflow happens with respect to addition when 2 N-bit 2’s Complement Numbers are appended and the answer is too large to fit into that N-bit Group.A computer contains N-Bit Fixed registers. Result of addition of two N-Bit Number will result maximum N+1 Bit number.Carry Flag stores ... Read More

Binary Indexed Tree or Fenwick Tree in C++?

Arnab Chakraborty
Updated on 29-Jan-2020 11:11:23

448 Views

In case of comparing with a flat array of numbers, the Fenwick tree results a much better balance between two operations: element update and prefix sum computation. In case of a flat array of m numbers, we can either store the elements, or the prefix sums. In case of first instance, calculating prefix sums needs linear time; in case of second instance, modifying or updating the array elements needs linear time (in both instances, the other operation can be accomplished in constant time). Fenwick trees permit both operations to be accomplished in O(log m) time. This is obtained by representing ... Read More

Bin Packing Problem (Minimize number of used Bins) in C++?

Arnab Chakraborty
Updated on 29-Jan-2020 11:08:42

4K+ Views

In case of given m elements of different weights and bins each of capacity C, assign each element to a bin so that number of total implemented bins is minimized. Assumption should be that all elements have weights less than bin capacity.ApplicationsPlacing data on multiple disks.Loading of containers like trucks.Packing advertisements in fixed length radio/TV station breaks.Job scheduling.ExampleInput: weight[] = {4, 1, 8, 1, 4, 2} Bin Capacity c = 10 Output: 2 We require at least 2 bins to accommodate all elements First bin consists {4, 4, 2} and second bin {8, 2}Lower BoundWe can always calculate a lower ... Read More

Barabasi Albert Graph (for Scale Free Models) in C/C++?

Arnab Chakraborty
Updated on 29-Jan-2020 11:00:00

297 Views

The Barabási-Albert model is treated as one of several proposed models that produce scale-free networks. It combines two important general concepts: growth and preferential attachment. Both concepts i.e. growth and preferential attachment have wide existence in real networks. The meaning of growth is that the number of nodes in the network increases over time.The meaning of preferential attachment is that the more connected a node is, the more chance it is to receive new links.Higher degree nodes have stronger ability to catch or grab links added to the network. Basically, the preferential attachment can be well understood if we think ... Read More

Balanced expressions such that given positions have opening brackets in C++?

Arnab Chakraborty
Updated on 29-Jan-2020 10:57:50

219 Views

In case of a given integer m and an array of positions ‘position[]’ (1

Arrange consonants and vowels nodes in a linked list in C++?

Nishu Kumari
Updated on 06-Aug-2025 11:10:56

224 Views

A singly linked list is a fundamental data structure that consists of nodes,  where each node contains a data field and a reference to the next node in the linked list. The next of the last node is null, indicating the end of the list. The given task is to rearrange the linked list in such a way that all the vowel nodes precede the consonants while maintaining the order of their arrival. Scenario Input: a -> b-> c -> d-> e-> f-> g-> h-> i Output: a-> e-> i-> b-> c-> d-> f-> g-> h To solve this problem, we ... Read More

Arrange a binary string to get maximum value within a range of indices C/C++?

Arnab Chakraborty
Updated on 29-Jan-2020 08:14:40

255 Views

In case of a given string consisting of only 0’s and 1’s, we are given M non-intersecting ranges A, B( A

Are array members deeply copied in C++?

Aman Kumar
Updated on 24-Jul-2025 15:49:59

1K+ Views

In C++, an array member is simply the individual elements stored within an array. What is Deep Copy? A deep copy creates a new object and allocates separate memory for the dynamically allocated resources; it copies all the data members of the original object into the new object. So that the new object is completely independent of the original. When a class has a pointer to dynamic memory, the default copy constructor and assignment operator will perform a shallow copy, which is a copy of the pointer rather than the data. So, must define our own ... Read More

Advertisements