Found 7346 Articles for C++

Replace every character of string by character whose ASCII value is K times more than it

Way2Class
Updated on 21-Jul-2023 17:56:36

430 Views

In the realm of C++ programming, it is possible to replace every character of a specified string with a symbol whose ASCII value is elevated by a factor of K compared to the original character. This can be accomplished through the implementation of a straightforward algorithmic technique. This piece delves into the syntax, the algorithm, and two distinct methods to address the problem, complete with code illustrations in C++. Syntax To substitute every character in a string with a character whose ASCII value is multiplied by K, the syntax is as follows − string replace(string str, int K); Here, ... Read More

Implement Multi Stack (K stacks) using only one Data Structure

Way2Class
Updated on 21-Jul-2023 17:54:03

1K+ Views

A dynamic multi-stack is a remarkable data structure that possesses the capacity to store elements in numerous stacks, with an ever-changing quantity of stacks. It can be a daunting task to implement K stacks utilizing only one data structure. In this instructional guide, we shall investigate two distinct techniques to execute dynamic multi-stack (K stacks) using C++. The initial technique employs an array to stock the elements, along with two additional arrays to monitor the topmost and following indices of the stacks. The secondary technique employs a vector of nodes to stock the elements, along with a vector to keep ... Read More

Length of Longest Increasing Subsequences (LIS) using Segment Tree

Way2Class
Updated on 21-Jul-2023 17:45:08

281 Views

Segment Tree is a versatile data structure designed for answering range queries and performing updates on arrays in logarithmic time complexity, where each node stores information related to a specific range of elements in the array. In the context of the Longest Increasing Subsequence (LIS) problem, which requires determining the length of the longest subsequence of a given sequence in which the elements are sorted in increasing order, Segment Trees can be utilized to efficiently compute the Length of Longest Increasing Subsequences in an array. This approach significantly reduces the time complexity compared to traditional methods and has ... Read More

Classification of Algorithms with Examples

Way2Class
Updated on 21-Jul-2023 17:39:00

247 Views

Classification of algorithms helps in selecting the most suitable one for a specific task, enabling developers to optimize their code and achieve better performance. In computer science, algorithms are sets of well-defined instructions used to solve problems or perform specific tasks. The efficiency and effectiveness of these algorithms are crucial in determining the overall performance of a program. In this article, we will discuss two common approaches for classifying algorithms, namely, based on their time complexity and based on their design technique. Syntax The syntax of the main function used in the codes for both approaches − int ... Read More

Count K-length subarrays whose average exceeds the median of the given array

Way2Class
Updated on 21-Jul-2023 17:20:50

66 Views

The expression "K-length subarrays" pertains to successive subarrays having precisely K elements. Grasping and working with subarrays is crucial for resolving various issues in fields such as dynamic programming, computational geometry, and data analysis. Another vital concept in array manipulation and statistics is the median. The median of an array represents the middle value when the elements are sorted in ascending order. In the case of an even number of elements, the median is the average of the two central values. The median constitutes a durable measure of central tendency, as it is less vulnerable to extreme values or outliers ... Read More

Queries to find the Minimum Weight from a Subtree of atmost D-distant Nodes from Node X

Way2Class
Updated on 21-Jul-2023 17:16:23

53 Views

When engaged in computer programming, it is sometimes necessary to locate the minimum weight of a subtree that originates from a specific node, with the condition that the subtree must not contain any nodes farther than D units away from the specified node. This problem arises in various fields and applications, including graph theory, tree-based algorithms, and network optimization. The subtree constitutes a subset of a larger tree structure, with the specified node serving as the root of the subtree. The subtree encompasses all the descendants of the root node and their connecting edges. The weight of a node refers ... Read More

Queries to find the Lower Bound of K from Prefix Sum Array with updates using Fenwick Tree

Way2Class
Updated on 21-Jul-2023 17:13:16

99 Views

A foremost series summation array is an assemblage that accumulates the sum of interlacing elements up to an express index. It is a widely utilized tactic in the reconfiguration of assemblages to refine time complexity. Fenwick Tree, also recognized as Binary Indexed Tree (BIT), is a form of database that proficiently modernizes components and computes a preceding series summation in logarithmic time complexity. Within this article, we shall confer on how to disclose the lesser extreme boundary of a given value, referred to as K, from a series summation array with modernizations utilizing Fenwick Tree in C++. Syntax The ... Read More

Queries to check if vertices X and Y are in the same Connected Component of an Undirected Graph

Way2Class
Updated on 21-Jul-2023 17:00:04

169 Views

Graph theory encompasses the study of connected components, which are subgraphs in an undirected graph where every pair of vertices is linked by a path, and no other vertices are connected to it. In this article, we will delve into the utilization of the C/C++ programming language to determine if two vertices, X and Y, belong to the same connected component in an undirected graph. We will elucidate the syntax and rationale of the method before elucidating at least two diverse approaches to tackle this problem. Furthermore, we will provide concrete code examples and their corresponding outcomes for each ... Read More

Queries to find the count of connected Non-Empty Cells in a Matrix with update

Way2Class
Updated on 21-Jul-2023 15:57:07

56 Views

A matrix can be thought of as a collection of cells organized in rows and columns. Each cell can contain a value, which can be either empty or non-empty. In computer programming, matrices are commonly used to represent data in a two-dimensional grid. In this article, we will discuss how to efficiently count the number of connected non-empty cells in a matrix, taking into account possible updates to the matrix. We will explore different approaches to solve this problem and provide real code examples to demonstrate the implementation. Syntax The basic syntax for querying the count of connected non-empty cells ... Read More

Implementing of strtok() function in C++

Way2Class
Updated on 21-Jul-2023 13:48:33

346 Views

The strtok() function is one of the most utilised functions in C++. Using a delimiter as a guide, this function can divide a text into smaller chunks or tokens. It is simple to work with strings in C++ thanks to the strtok() function. The strtok() function will be thoroughly examined in this article, along with its definition, syntax, algorithm, and various implementation strategies. It is crucial to remember that the strtok function has several restrictions and potential downsides. It cannot be used on const or read-only strings, for instance, because it changes the original string in place. Edge situations and ... Read More

Advertisements