Construct Tree from Inorder and Preorder Traversals in C++

Sunidhi Bansal
Updated on 03-Aug-2020 09:58:45

929 Views

We are given the Inorder and Preorder traversals of a binary tree. The goal is to construct a tree from given traversals.Inorder traversal − In this type of tree traversal, a left subtree is visited first, followed by the node and right subtree in the end.Inorder (tree root)Traverse left subtree of node pointed by root, call inorder ( root→left )Visit the rootTraverse right subtree of node pointed by root, call inorder ( root→right )Preorder traversal − In this type of tree traversal, the node visited first, followed by the left subtree and right subtree in the end.Preorder (tree root)Visit the ... Read More

Continuous Tree in C++

Sunidhi Bansal
Updated on 03-Aug-2020 09:53:38

206 Views

A Continuous Tree is defined as a tree with any path from root node to leaf node has value or weight of nodes such that the absolute difference between the parent node and all of its direct children nodes is always 1.If we pick any node on the path from root to leaf, then|weight of node-weight of left child node|=|weight of left child node-weight of node| = 1, this holds true for right child as well|weight of node-weight of right child node|=|weight lof right child node-weight of node| = 1DiagramLet us understand with examples.The tree below is continuous as absolute ... Read More

Count Derangements in C++

Sunidhi Bansal
Updated on 03-Aug-2020 09:51:27

664 Views

Derangement is permutation of N numbers such that no number appears at original position. For example one possible derangement of { 1, 2, 3 } is { 2, 1, 3 }. No element in this is at its original position. The goal here is to count the possible derangements for N numbers.We will do this using a recursive solution. For following no. of elements −N=0, no derangement, return 1N=1, only one number, return 0N=2, only one swap of position possible, { 1, 2 } → { 2, 1 }, return 1N=3, 2 possible permutations eg, { 1, 2, 3 } ... Read More

Content Management Systems: An Overview

Sunidhi Bansal
Updated on 03-Aug-2020 09:48:38

3K+ Views

If we go by the term Content Management System word to word, then it basically means a system of managing the content. It is defined as a collaborative platform with different features and functionalities that allow the creating, designing, publishing and maintaining web content easily and effectivelWhat is a Content Management System (CMS)?A Content Management System is a software application used to create and design the web content online. It allows the users to manage the digital content easily by providing access to features like database handling, smart reporting, archiving, designing and animation features etc. These are generally used in ... Read More

Maximum Length of Balanced String After Swapping and Removal of Characters in C++

Sunidhi Bansal
Updated on 03-Aug-2020 09:44:43

126 Views

We are given a string containing (, ), {, }, [, ] characters only. The goal is to find the maximum length of such string so that it becomes balanced by swapping adjacent characters or removing a character. We will do this by comparing adjacent characters, if they are opposite of each other then they can be swapped. ( }{, )(, ][ can be swapped, while {{, )), [[, }}, )), ]] cannot be swapped ).Also if a character has no matching pair, then it can be removed also. ( “{{}][“, here first { can be removed and balanced string ... Read More

Maximum Litres of Water That Can Be Bought with N Rupees in C++

Sunidhi Bansal
Updated on 03-Aug-2020 09:43:21

633 Views

We are given N rupees. The goal is to buy maximum water possible with the money where the rates of water bottles are as follows −Plastic Bottles: A Rupees for 1 litreGlass Bottles: B Rupees for 1 litreGlass Bottles: B Rupees for 1 litreNow the original cost of glass bottles becomes B-E rupees. After returning.If the cost of plastic bottles is still less than B-E, then only buy plastic bottles. Else buy N-E/B-E glass bottles and spend rest on plastic bottles.InputN = 6, A = 5, B = 4, E = 3;OutputMaximum litres of water: 3Explanation − B-E=1, 1A n/a= ... Read More

Maximum in an Array that Can Make Another Array Sorted in C++

Sunidhi Bansal
Updated on 03-Aug-2020 09:42:18

139 Views

We are given an array of numbers say Arr1[] and another array Arr2[] of same or different length. The Arr1[] has elements sorted in ascending order, such that a single element is unsorted. We must find the element from the second array Arr2[] such that it can replace the wrongly placed element of Arr1[] and make it sorted. Also, the element chosen from Arr2[] should be maximum if there are multiple options available.InputArr1[]= { 1,3,5,7,2,11 }, Arr2[]= { 4,8,7,10,9 }OutputMaximum element that can make Arr1 sorted: 10Explanation − Numbers in Arr2[] that can make Arr1[] sorted − 8,9,10 as they all are >=7 and =12 and

Construct Turing Machine for L = a^n b^m a^{n+m} n, m >= 1 in C++

Sunidhi Bansal
Updated on 03-Aug-2020 09:31:58

2K+ Views

Turing Machine − A Turing machine is a device used to accept words of a language generated by type 0 grammars. A Turing Machine (TM) is a mathematical model which consists of an infinite length tape divided into cells on which input is given. It consists of a head which reads the input tape. A state register stores the state of the Turing machine. After reading an input symbol, it is replaced with another symbol, its internal state is changed, and it moves from one cell to the right or left. If the TM reaches the final state, the input ... Read More

Count Magic Squares in a Grid in C++

Sunidhi Bansal
Updated on 03-Aug-2020 09:29:29

331 Views

We are given with a matrix of numbers. The goal is to find the number of Magic squares present inside the given matrix.A Magic Square, if taken as a matrix, is a 3X3 matrix which contains the elements ranging from 1 to 9 just like a grid in Sudoku. Properties are −All numbers occur exactly once.Sum of all 9 cells in the matrix is 45.Sum of each row of 3 is 15.Sum of each column of 3 is 15.Sum of diagonals of 3 is 5.To get such sums, 5 is always in the middle of both diagonals.Inputint arr[][]= { { ... Read More

Skip Selected Test from Execution in Pytest

Debomita Bhattacharjee
Updated on 29-Jul-2020 12:47:51

505 Views

We can skip a selected test from execution in pytest. Pytest is a test framework in python. To install pytest, we need to use the command pip install pytest. After installation, we can verify if python has been installed by the command pytest –version. The version of pytest shall be known.Pytest can be used for creating and executing test cases. It can be used in wide range testing API, UI, database and so on. The test file of pytest has a naming convention that it starts with test_ or ends with _test keyword and every line of code should be ... Read More

Advertisements