ConceptWith respect of a given Binary Tree, the task is to determine the size of maximum complete sub-tree in the given Binary Tree.Complete Binary Tree – A Binary tree is treated as Complete Binary Tree if all levels are completely filled without possibly the last level and the last level has all keys as left as possible.It has been noted that all Perfect Binary Trees are Complete Binary tree but reverse in NOT true. It has been seen that if a tree is not complete then it is also not Perfect Binary Tree.Input 2 / \ ... Read More
Suppose we want to make a house on an empty land which reaches all buildings in the shortest amount of distance. We can only move four directions like up, down, left and right. We have a 2D grid of values 0, 1 or 2, where −0 represents an empty land which we can pass by freely.1 represents a building which we cannot pass through.2 represents an obstacle which we cannot pass through.So, if the input is like102010000000100then the output will be 7 as Given three buildings are present at (0, 0), (0, 4), (2, 2), and an obstacle is at ... Read More
Suppose we have one matrix; we have to find the length of the longest increasing path. From each cell, we can either move to four directions − left, right, up or down. We cannot move diagonally or move outside of the boundary.So, if the input is like994668211then the output will be 4 as the longest increasing path is [3, 4, 5, 6].To solve this, we will follow these steps −Define a function solve(). This will take i, j, matrixif dp[i, j] is non-zero, thenreturn dp[i, j]dp[i, j] := 1temp := 0for r in range i-1 to i+2, dofor c in ... Read More
ConceptThe article explains a method to solving the problem of finding the LCA of two nodes in a tree by reducing it to a RMQ problem.Examples Lowest Common Ancestor (LCA) of two nodes a and b in a rooted tree T is defined as the node located farthest from the root that has both a and b as descendants.For example, according to below diagram, LCA of node D and node I is node B.We can apply so many approaches to solve the LCA problem. These approaches differ with respect of their time and space complexities.Range Minimum Query (RMQ) is applied on ... Read More
ConceptWith respect of given an array arr[] of n positive integers, the task is to determineelements arr[i] and arr[j] from the array such that arr[i]Carr[j] is at most possible. With respect of more than 1 valid pairs, print any one of them.Input arr[] = {4, 1, 2}Output 4 2 4C1 = 4 4C2 = 4 2C1 = 4 (4, 2) is the only pairs with maximum nCr.MethodnCr is treated as a monotonic increasing function, that is n+1Cr > nCr. We can apply this fact to get close to our answer; we will select the max n among all the given integers. In ... Read More
ConceptWith respect of given N numbers, the target is to determine the minimum removal of numbers such that GCD of the remaining numbers is larger than initial GCD of N numbers. If it is impossible to increase the GCD, print “NO”.Input b[] = {1, 2, 4}Output1After removing the first element, then the new GCD is 2, which is larger than the initialGCD i.e., 1.Input b[] = {6, 9, 15, 30}Output 3The initial gcd is 3, after removing 6 and 9 to obtain a gcd of 15 which is larger than 3. We can also remove 9 and 15 to get a gcd of ... Read More
ConceptWith respect of a given undirected graph of b nodes and a edges, the job is to determine minimum edges needed to build Euler Circuit in the given graph.Input b = 3, a = 2 Edges[] = {{1, 2}, {2, 3}}Output 1By connecting 1 to 3, we can build a Euler Circuit.MethodWith respect of a Euler Circuit to exist in the graph we need that every node should haveeven degree because then there exists an edge that can be applied to exit the node after entering it.Now, there can be two cases −Existence of one connected component in the graphWith respect of ... Read More
ConceptGiven A x B Chessboard, the task is to calculate the Maximum numbers of cuts that we can build in the Chessboard so that the Chessboard is not divided into 2 parts.Examples The examples are given below −Input A = 2, B = 4Output Number of maximum cuts = 3Input A = 2, B = 2Output Number of maximum cuts = 1MethodFor A = 2, B = 2 ,we can only build 1 cut (mark in red). If we build 1 more cut then the chessboard will divide into 2 piecesFor A = 2, B = 4 ,we can makes 3 cuts (marks in red). ... Read More
ConceptSuppose a board of length p and width q is given, we require to break this board into p*q squares such that cost of breaking is least. For this board, cutting cost for each edge will be given. In a nutshell, we require selecting such a sequence of cutting such that cost is minimized.Examples With respect of above board optimal way to cut into square is −Total minimum cost in above case is 65. It is computed evaluated implementing following steps.Initial Value : Total_cost = 0 Total_cost = Total_cost + edge_cost * total_pieces Cost 5 Horizontal cut Cost = 0 + ... Read More
The IEEE 802.1Q networking standard lays down the specifications for VLANs (Virtual Local Area Networks or Virtual LANs) on an IEEE 802.3 Ethernet network. The standard is generally referred as Dot1Q. VLANs are a logical group of computers that appear to be on the same LAN irrespective of the configuration of the underlying physical network. Network administrators partition the networks to match the functional requirements of the VLANs so that each VLAN comprise of a subset of ports on a single or multiple switches or bridges. This allows computers and devices in a VLAN to communicate in the simulated environment ... Read More
 Data Structure
 Networking
 RDBMS
 Operating System
 Java
 iOS
 HTML
 CSS
 Android
 Python
 C Programming
 C++
 C#
 MongoDB
 MySQL
 Javascript
 PHP