Found 7197 Articles for C++

String Range Queries to count number of distinct character with updates

Tapas Kumar Ghosh
Updated on 10-May-2023 11:34:14

368 Views

A string range query is the range of characters present in the string where a character starts from the index[0] and the last index[] may be specified according to the length of a given string. In this article, we are going to learn how string range queries count the number of distinct characters with their updates. Let’s take an example of counting the number of distinct characters of a string with its update. string = “tutorialpoint” // original string The given string is the length of 12. So the count is 13(counting always starts from 1). If we ... Read More

Number of times an array can be partitioned repetitively into subarrays with equal sum

Tapas Kumar Ghosh
Updated on 10-May-2023 11:28:56

192 Views

In C++ we have a vector header file that can change the size of an array during runtime. In this article, we are going to learn the concept of the number of times an array can be partitioned repetitively into subarrays with equal sum. Let’s take an example to show an array partition with an equal sum. The given array is {1, 2, 3, 4, 2} and we are subdividing the array into two parts − {1, 2, 3}- The total sum of each index of an array is 6. {4, 2}- The total sum of each index of an ... Read More

Sum of minimum element at each depth of a given non cycle graph

Tapas Kumar Ghosh
Updated on 10-May-2023 11:23:05

162 Views

A graph that does not contain any cycles or loops is called a non-cycle graph. A tree is a non-cycle graph in which every node is joined to another unique node. A non-cycle graph is also known as an acyclic graph. Difference between cycle graph and non-cycle graph − Cycle Graph Non-Cycle graph The graph forms a closed loop. The graph doesn’t form a closed loop. The graph doesn’t contain a depth loop The graph contains each depth. Example 1 let’s take an example of a cycle graph − A Cycle ... Read More

Page Faults in LRU

Rudradev Das
Updated on 05-May-2023 11:35:46

2K+ Views

Paging is a memory management process related the operating systems. It stores or retrieve some process data from the secondary data storage into the primary data storage or memory by using the page segement. The paging process happens when the process encounters any fault in a page and we can not use a new free page to satisfy the allocation process here. The LRU process generates the particular need of a replacement algorithm. It decides which page needs to be replace when a process produce a new page. Let us take an example – Input taken for the process − ... Read More

Page Faults in LFU

Rudradev Das
Updated on 05-May-2023 11:29:40

3K+ Views

The Least Frequently Use aka LFU is a concept of page memory management, can also be used as a replacement algorithm. This process take a lead we the particular page needs a replacement when a new page is on the way by the process. LFU is one of the page replacement policy where an user can replace the least frequency of a particular operation page. If the page frequency is same in a process, then it will come first on the replacement list. Here we will take a page sequence of an array of pages denoted as pages[], whose length ... Read More

Lamport's Bakery Algorithm

Diksha Patro
Updated on 03-May-2023 15:49:18

2K+ Views

A synchronization method called Lamport's Bakery method addresses the critical section issue in parallel computing systems. When more than one process needs to utilize a shared resource at once but only one process can do so, this is known as the critical section problem. To avoid conflicts and guarantee the accuracy of the system, the challenge is to make sure that each process uses the resource in a way that is mutually exclusive. Pseudo code for Lamport's Bakery Algorithm Here the Pseudo code for Lamport’s Bakery Algorithm − Initialize an array, called choosing, of size N, where N is ... Read More

Isomorphism in N-ary Trees

Tapas Kumar Ghosh
Updated on 20-Apr-2023 12:42:19

507 Views

Isomorphism is defined as two trees either having identical or mirror structures. In the case of mirror structure, the left node data will always match the right node. For example, we will take a number nearest to the mirror and see what its reverse would be, that is the real concept of isomorphism. In this article, we are going to check whether two different binary trees are isomorphic or not. Let’s take an example of Isomorphism in N-ary Trees − Note that, L represents as left node whereas R represents as Right node Mirror structure of P and Q ... Read More

Check score of given binary string

Tapas Kumar Ghosh
Updated on 20-Apr-2023 12:25:58

303 Views

The sequence of bytes is called a binary string and it holds the binary value. A binary score is normally presented on a range from 0 to 1 where 1 is reserved for the perfect model. In the given binary string, If the element is found to be 1 then it will calculate as the score and increment the count sum. Let’s take an example of a binary score − The given binary string is 1011010. In the above figure, the number 1 is present in the index- 0, 2, 3, and 5. Therefore, the total score is 4 ... Read More

Length of longest substring that do not contain any palindrome

Tapas Kumar Ghosh
Updated on 20-Apr-2023 12:22:04

363 Views

In C++, we have predefined function max() that will be used for finding any longest substring that does contain any palindrome. A palindrome string is a group of characters that remains the same even after reversing. Let’s take an example of a palindrome string to make the longest non-palindrome substring. The string malayalam itself is a palindrome but we need to identify the longest non-palindrome substring. When we change the string malayalam( length=9 ) to alayalam then we get the longest non-palindrome substring length i.e, 8. The string synapse is a non-palindrome string and its length is 7. ... Read More

Check if string can be made lexicographically smaller by reversing any substring

Tapas Kumar Ghosh
Updated on 20-Apr-2023 12:17:45

700 Views

In C++ we have an inbuild reverse() function that will be used for reversing the substring to check whether a string can be made lexicographically smaller or not. Lexicographic ordering is the process by which the character of a word is sorted in a dictionary. Let’s take an example of a string to check lexicographically smaller or not. We will compare the two words to check the lexicographically smaller ones and take two strings namely ‘apple’ and ‘army’. Both these strings of the first letter starting with letter ‘a’. When we move to check the second character of both ... Read More

Advertisements