Found 7197 Articles for C++

Design a queue data structure to get minimum or maximum in O(1) time

Tapas Kumar Ghosh
Updated on 04-Jun-2025 17:48:39

906 Views

In data structure & algorithm, we have a deque header file that handles the properties of stack and queue. For getting minimum and maximum value from O(1) time complexity, we need constant time. So, deque is one of the possible advantages of using both stack and queue. O(1) Time Complexity The O(1) time complexity is also known as constant time which defines an algorithm for taking the same amount of time instead of using size input. Syntax The basic syntax of deque data structure is as follows: deque name_of_queue; Here, deque : It ... Read More

Check if given words are present in a string

Tapas Kumar Ghosh
Updated on 10-May-2023 14:20:57

962 Views

C++ has a predefined function find() which enables searching from the first element range until the last element. In this article, we are going to understand how we can use this find() function to check if a given word is present in a string or not. Let’s take an example of this. The given string is “John and mark have same color of t-shirt”; For searching the word in a string we will make a variable that is denoted as a search finder. Let’s take two variables and check if the given words are present or not. Var1 = ... Read More

Proof that the Dominant Set of a Graph is NP-Complete

Tapas Kumar Ghosh
Updated on 10-May-2023 14:15:12

580 Views

A Dominant set of a graph is NP-complete is the subset of vertices such that every vertex in the subset or adjacent vertex in the subset. The full form of NP is “Nondeterministic polynomial” which will check the problem in polynomial time and it means that we can check whether the solution is correct or not in polynomial time. The polynomial time has the best complexity to the code like the time complexity of linear search – n, Binary search – logn, Merge sort- n(log)n, etc. The NP-complete graph provides a good solution in a reasonable amount of time. This ... Read More

Find array sum using Bitwise OR after splitting given array in two halves after K circular shift

Tapas Kumar Ghosh
Updated on 10-May-2023 14:06:25

189 Views

In C++ splitting an array mean dividing the array into more than one subarray. The Bitwise OR is used to handle the comparison and calculation between two bits or indexes in C++. In this article, we use k circular shift which means the last index position will be shifted to zero index position i.e, the first array element according to k-th times. Let’s take an example to understand the circular shift into the array. The given array is 1, 2, 3, 4, 5, 6, 7 and has a length of 6. Now we will assign the value 3 to k ... Read More

Check if product of Array elements in given range are M-th root or not

Tapas Kumar Ghosh
Updated on 10-May-2023 13:54:11

198 Views

M-th root is defined as the cube of any number and array ranges mean to count the indexes from first to end. We will take three numbers in the array range as input and see if their product value comes in the form of a cube value then it will be the 'M-th' root of the number. Let’s take an example to understand the product range of an array and calculate the M-th root of the number. Example 1 Given array integer is 9, 8, 3, 1 Now we see the product range of array 9*8*3*1 is 216. Therefore, 216 ... Read More

Check if it is possible to reach the index with value K when start index is given

Tapas Kumar Ghosh
Updated on 10-May-2023 13:32:57

156 Views

C++ has a bitwise operator “||” to check multiple conditions at once and for finding the length of an array we use the size() function. In the given problem statement, we need to reach the K-th value which sets to 0 in the array range, and the starting index is already known. If the given index satisfies to K-th value in the array range then it will print that “We can reach the value k from the given start index”. Let’s take an example of this − Given integer array is 5, 6, 0, 9, 10 having a length of ... Read More

Inversion Count using Policy Based Data Structure

Tapas Kumar Ghosh
Updated on 10-May-2023 12:43:42

200 Views

We will use the g++ header file to compile the code in C++ compiler. g++ is a Linux based header file that is used in C++ to compile the code of policy based data structure. The policy based data structure are such structures used for high performance and flexibility of the code. As these data structures are so resourceful that we can use them for many functions like searching the index of an element, inserting the element into the index position, removing the element from the range of index, etc. Example Let’s take an example of inversion count − Suppose ... Read More

Find strings that end with a given suffix

Tapas Kumar Ghosh
Updated on 10-May-2023 12:24:01

603 Views

C++ has a predefined function substr to return the portion of string and compare function to check the sequence of characters. The suffix means the group of characters added to the end of the word. In this article, we are going to find the strings that end with a given suffix. Let us understand the example of suffix by taking some of the strings − Tutorialspoint − The characters n and t represent the suffix. Tutorix − The characters r, i, and x represent the suffix. Note that, the length of the reverse of some characters in ... Read More

Finding the shortest path between any two nodes using Floyd Warshall Algorithm

Tapas Kumar Ghosh
Updated on 10-May-2023 12:17:36

1K+ Views

C++ has a macro which is defined as a piece of code or desired value and it will use repetitively again and again whenever the user wants. The Floyd Warshall Algorithm is the process of finding the shortest path between all pairs of vertices in a given weighted graph. This algorithm follows the dynamic programming approach to find the minimal weightage graph. Let us understand what is Floyd Warshall Algorithm with the help of diagrams − Take vertex 1 as the source and vertex 4 as the destination and find the shortest path between them. We have seen that ... Read More

Minimum cost of reducing Array by merging any adjacent element repetitively

Tapas Kumar Ghosh
Updated on 10-May-2023 11:47:41

474 Views

In C++ we have a pop() function to remove the element from the beginning. The top() function returns the reference of the first element of the priority_queue whereas the push() function is used to insert an element on it. A priority queue is a part of the data structure that manages elements based on their values. In this article, we will learn the minimum cost of reducing an array by merging any adjacent element repetitively. Let's take an example from this article − We will draw the array of size 4 and add the adjacent element repetitively. Syntax The ... Read More

Advertisements