
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7197 Articles for C++

2K+ Views
Good problem-solving in computer science heavily relies on efficient algorithms like the Greedy-Best First Search (GBFS). GBFS has already established credibility as an optimal solution method for pathfinding or optimization issues. Therefore, we're discussing GBFS thoroughly in this article while exploring its implementation approach using C++. Syntax void greedyBestFirstSearch(Graph graph, Node startNode, Node goalNode); Algorithm The Greedy Best-First Search algorithm aims to find the path from a given start node to a goal node in a graph. Here are the general steps of the algorithm − Initialize an empty priority queue. Enqueue the start node into the priority ... Read More

105 Views
Efficiency and accuracy are often essential when solving complex problems in programming. One particular challenge involves appropriately identifying whether the maximum sum of N dice visible faces equals or surpasses X. In this piece, we evaluate various methods of tackling this difficulty in C++ coding, complete with syntax explanations and step-by-step algorithms. Furthermore, we will provide two real, full executable code examples based on the approaches mentioned. By the end, you will have a clear understanding of how to check if the maximum sum of visible faces of N dice is at least X in C++. Syntax Before diving into ... Read More

832 Views
In graph theory, finding the minimum spanning tree (MST) of a connected weighted graph is a common problem. The MST is a subset of the graph's edges that connects all the vertices while minimizing the total edge weight. One efficient algorithm to solve this problem is Boruvka's algorithm. Syntax struct Edge { int src, dest, weight; }; // Define the structure to represent a subset for union-find struct Subset { int parent, rank; }; Algorithm Now, let's outline the steps involved in Boruvka's algorithm for finding the minimum spanning tree − ... Read More

1K+ Views
A directed graph is a graph where the edges specify a direction from one vertex to another. In this article, we will learn how to find a path between two vertices in a directed graph and implement C++ code to achieve this. To determine if there is a path between two vertices, there are two common algorithms we can use: BFS Algorithm to Find Path Between Two Vertices DFS Algorithm to Find Path Between Two Vertices First of all, let's understand what does it meant by having a ... Read More

2K+ Views
Disjoint set information structure, too known as the Union-Find algorithm, could be an essential concept in computer science that gives an effective way to solve issues related to apportioning and network. It is especially valuable in solving issues including sets of components and determining their connections. In this article, we are going to investigate the language structure, algorithm, and two distinctive approaches to executing the disjoint set information structure in C++. We will also provide fully executable code examples to illustrate these approaches. Syntax Before diving into the algorithm, let's familiarize ourselves with the syntax used in the following code ... Read More

168 Views
A palindromic string is a string that is equal to its reverse string. We are given a string that contains ‘0’, ‘1’, and ‘2’ and an array Q of length N and each index of the given array indicates a range in the form of pairs. We have to find the minimum number of characters that are needed to replace in the given range such that none of the palindromic substrings remains in that range. Sample Example Input1: string s: “01001020002”, int Q = {{0, 4}, {2, 5}, {5, 10}}; Output: 1 1 3 Explanation For the range ... Read More

217 Views
Two binary strings str1 and str2 of the same length are given and we have to maximize a given function value by choosing the substrings from the given strings of equal length. The given function is such that − fun(str1, str2) = (len(substring))/(2^xor(sub1, sub2)). Here, len(substring) is the length of the first substring while xor(sub1, sub2) is the xor of the given substrings as they are binary strings so it is possible. Sample Examples Input1: string str1 = 10110 & string str2 = 11101 Output: 3 Explanation We can choose a lot of different sets of strings ... Read More

787 Views
A string str is given and we can swap only adjacent characters to make the string reverse. We have to find the number of minimum moves required to make the string reverse just by swapping the adjacent characters. We will implement two approaches to find the required solution with the explanation and the implementation of the code. Sample Examples Input1: string str1 = “shkej” Output: 10 Explanation First, we will take the last character to the first position which will take 4 swappings, and then the string will be “jshke”. Then we will move ‘e’ to the second ... Read More

373 Views
Prefixes are the substring from the given string that starts from the zeroth index and can go up to length 1 to the size of the string. Similarly, the suffix is the substring of any length 1 to the size of the string and ends at the last index. We will be given two strings and have to create the first string by using any number of prefixes and suffixes of the second string in any way. If it is not possible to create the given string from the given methods then we will return -1. Sample Examples Input 1: ... Read More

2K+ Views
Encryption is the technique to change the data by using some techniques or certain steps so it changes to another information or the previous information cannot be gathered from it directly. For encryption, we have to follow certain steps that are fixed for a particular type of encryption. In this problem, we will be given a string and we have to encrypt it by following the given steps − First, we have to get all the substring that contains the same characters and replace that substring with a single character followed by the length of the substring. Now, change ... Read More