Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Sunidhi Bansal
Page 68 of 81
Maximum length cycle that can be formed by joining two nodes of a binary tree in C++
We are given a binary tree. The goal is to find the maximum length cycle in the given tree. We will do this by finding the maximum height of the left subtree and right subtree from the root node and will join these maximum length paths to get the longest cycle.For the above tree the maximum length cycle is 1-2-3-4-7-6 or 1-6-7-4-3-2-1. The length is 6.Input − treeOutput − Maximum length cycle is − 5Explanation − The max height of left subtree is 3 and of right subtree is 1. Cycle length becomes 3+1+1=5. Cycle is 1-2-3-4-6 or 1-6-4-3-2Input − ...
Read MoreConstruct Tree from given Inorder and Preorder traversals in C++
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 MoreContinuous Tree in C++
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 MoreContent Management Systems An Overview
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 MoreConstruct Turing machine for L = {an bm a(n+m) - n,m≥1} in C++
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 MoreMaximum array sum that can be obtained after exactly k changes in C++
We are given with an array of positive and negative integers and a number K. The task is to find the maximum sum of the array after K changes in it’s elements. The single change operation here multiplies the single element by -1.Approach used will be to convert every negative number to positive. If there are N negative numbers then, for this we will sort the array −If NK then change the sign of K negative numbers and add the array. Sum will be maximum.InputArr[]= { 0, -2, 6, 4, 8, 2, -3 } K=4OutputMaximum array sum is : 25Explanation ...
Read MoreSets of pairs in C++
Set in C++ is an associative container and contains unique elements. All the elements once added to a specific cannot be modified. One can only remove and add elements in order to change them.Pair is defined under header and is used to couple together two pair values. The pair can have values of different or same type. The class has member functions first() and second() to individually access the values in a pair.The order of pair elements is fixed (first, second). We can use pair to combine two heterogeneous values of different types.To access any element we use variable_name.first ...
Read MoreCount columns to be deleted to make each row sorted in C++
The abnormal behavior of C++ programs often leads to program crash. You may have encountered problems like Segmentation fault, Aborted, Floating point exception etc. Following are sample programs that may help you to understand the reasons for a C++ program crash.ExceptionsExceptions in C++ are responses of a program when it encounters an abnormal condition. The program crashes due to such exceptions if they are not handled properly using try-catch blocks. Following program crashes due to divide by zero exception −Example#include int main(){ int num1=10; int num2=0; int quotient=num1/num2; printf(" Quotient is: %d", quotient); return ...
Read MoreC++ Program for Deadlock free condition in Operating Systems
Given with the P number of processes in the memory and N number of needed resources by them to complete their execution and the task is to find the minimum number of resources R which should be allotted to the processes such that deadlock will never occur.What is a DeadlockDeadlock is situation in an operating system where multiple processes residing in the memory doesn’t able to perform their execution because the resources which are needed for program execution is being hold by another resource who is waiting for some other resource for completion.Let’s say there are two processes P1 and ...
Read MoreC program for Binomial Coefficients table
Given with a positive integer value let’s say ‘val’ and the task is to print the value of binomial coefficient B(n, k) where, n and k be any value between 0 to val and hence display the result.What is Binomial CoefficientBinomial coefficient (n, k) is the order of choosing ‘k’ results from the given ‘n’ possibilities. The value of binomial coefficient of positive n and k is given by$$C_k^n=\frac{n!}{(n-k)!k!}$$where, n >= kExampleInput-: B(9, 2) Output-:$$B_2^9=\frac{9!}{(9-2)!2!}$$ $$\frac{9\times 8\times 7\times 6\times 5\times 4\times 3\times 2\times 1}{6\times 5\times 4\times 3\times 2\times 1)\times 2\times 1}=\frac{362, 880}{1440}=252$$What is Binomial Coefficient TableThe Binomial Coefficient Table is formed ...
Read More