Found 7347 Articles for C++

Construct Pushdown automata for L = {a(2*m)c(4*n)dnbm | m,n = 0} in C++

Sunidhi Bansal
Updated on 07-Jan-2021 06:33:49

441 Views

We are given with a language “L” and the task is to construct a pushdown automata for the given language which explains that the occurrences of character ‘a’ should be doubles the time of occurrence of character ‘b’ and occurrences of character ‘c’ should be quadruples the times of ‘d’ and also occurrences of all the characters should be minimum 1 which can also makes the string NULL and it should be accepted by the automata.What is pushdown Automata?A pushdown automata or pushdown automaton or PDA is a technique to implement a context-free grammar in a similar way we design ... Read More

Construct Pushdown automata for L = {0n1m2m3n | m,n = 0} in C++

Sunidhi Bansal
Updated on 07-Jan-2021 06:32:01

535 Views

We are given with a language “L” and the task is to construct a pushdown automata for the given language which explains that the occurrences of 0’s and 3’s will be equal and occurrences of 1’s and 2’s will be equal and also occurrences of all the numbers should be minimum 1 which can also makes the string NULL and it should be accepted by the automata.What is pushdown Automata?A pushdown automata or pushdown automaton or PDA is a technique to implement a context−free grammar in a similar way we design Deterministic Finite Automaton or DFA for a regular grammar. ... Read More

Construct Pushdown automata for L = {0m1(n+m)2n | m,n = 0} in C++

Sunidhi Bansal
Updated on 07-Jan-2021 05:27:09

432 Views

We are given with a language “L” and the task is to construct a pushdown automata for the given language which explains that the occurrences of 1’s will be the addition of occurrences of 0’s and 2’s and also, occurrence of 0 and 2 will be minimum one which can also makes the string NULL and it should be accepted by the automata.What is pushdown Automata?A pushdown automata or pushdown automaton or PDA is a technique to implement a context−free grammar in a similar way we design Deterministic Finite Automaton or DFA for a regular grammar. A DFA can operate ... Read More

Construct Pushdown automata for L = {0(n+m)1m2n | m, n = 0} in C++

Sunidhi Bansal
Updated on 07-Jan-2021 05:24:22

354 Views

We are given with a language “L” and the task is to construct a pushdown automata for the given language which explains that the occurrences of 0’s will be the addition of occurrences of 1’s and 2’s and also, occurrence of 1 and 2 will be minimum one which can also makes the string NULL and it should be accepted by the automata.What is pushdown Automata?A pushdown automata or pushdown automaton or PDA is a technique to implement a context−free grammar in a similar way we design Deterministic Finite Automaton or DFA for a regular grammar. A DFA can operate ... Read More

Count the nodes of the tree whose weighted string contains a vowel in C++

Sunidhi Bansal
Updated on 05-Jan-2021 14:53:08

132 Views

Given a binary tree with weights of its nodes as strings. The goal is to find the number of nodes that have weights such that the string contains a vowel. If weight is ‘aer’ then it has vowels ‘a’ and ‘e’ so the node will be counted.For ExampleInputThe tree which will be created after inputting the values is given below −OutputCount the nodes of the tree whose weighted string contains a vowel are: 5Explanationwe are given with the tree nodes and the string weights associated with each node. Now we check whether the string of nodes contains vowels or not.NodeWeightvowelsyes/no2aeeyes1bcdNo ... Read More

Count the nodes whose weight is a perfect square in C++

Sunidhi Bansal
Updated on 05-Jan-2021 14:57:18

90 Views

Given a binary tree with weights of its nodes. The goal is to find the number of nodes that have weights such that the number is a perfect square. If weight is 36 then it is 62 so this node will be counted.For ExampleInputThe tree which will be created after inputting the values is given below −OutputCount the nodes whose weight is a perfect square are: 4Explanationwe are given with the tree nodes and the weights associated with each node. Now we check whether the digits of nodes are perfect squares or not.NodeWeightPerfect squareYes/no212111*11yes1819*9yes437Prime numberno3255*5yes810010*10yes9701Not possiblenoInputThe tree which will be ... Read More

Count the nodes in the given tree whose weight is a power of two in C++

Sunidhi Bansal
Updated on 05-Jan-2021 14:58:58

171 Views

Given a binary tree with weights of its nodes. The goal is to find the number of nodes that have weights such that the number is power of two. If weight is 32 then it is 25 so this node will be counted.For ExampleInputThe tree which will be created after inputting the values is given below −OutputCount the nodes in the given tree whose weight is a power of two are: 3Explanationwe are given with the tree node and the weights associated with each node. Now we calculate the power of each and every weight and check whether it can ... Read More

Count the nodes in the given tree whose sum of digits of weight is odd in C++

Sunidhi Bansal
Updated on 05-Jan-2021 13:56:22

179 Views

Given a binary tree with weights of its nodes. The goal is to find the number of nodes that have weights such that the sum of digits in that weights add up to an odd number. If weight is 12 then the digit sum is 3 which is odd so this node will be counted.For ExampleInputThe tree which will be created after inputting the values is given below −OutputCount of nodes in the given tree whose sum of digits of weight is odd are: 2Explanationwe are given with the tree node and the weights associated with each node. Now we ... Read More

Count subtrees that sum up to a given value x in C++

Sunidhi Bansal
Updated on 05-Jan-2021 13:39:31

259 Views

Given a binary tree and a value x as input. The goal is to find all the subtrees of a binary tree that have sum of weights of its nodes equal to x.For ExampleInputx = 14. The tree which will be created after inputting the values is given belowOutputCount of subtrees that sum up to a given value x are: 1Explanationwe are given with a x value as 14. As we can see there is only one leaf node with the values as 14 therefore the count is 1.Inputx = 33. The tree which will be created after inputting the ... Read More

Count subarrays whose product is divisible by k in C++

Sunidhi Bansal
Updated on 05-Jan-2021 13:36:48

251 Views

Given an array arr[] and an integer k as input. The goal is to find the number of subarrays of arr[] such that the product of elements of that subarray is divisible by k.For ExampleInputarr[] = {2, 1, 5, 8} k=4OutputCount of sub-arrays whose product is divisible by k are: 4ExplanationThe subarrays will be: [ 8 ], [ 5, 8 ], [ 1, 5, 8 ], [ 2, 1, 5, 8 ].Inputarr[] = {7, 1, 9, 7} k=9OutputCount of sub−arrays whose product is divisible by k are: 6ExplanationThe subarrays will be: [ 9 ], [ 9, 7 ], [ 1, ... Read More

Advertisements