Find LCA in Binary Tree Using RMQ in C++

Arnab Chakraborty
Updated on 23-Jul-2020 07:24:02

179 Views

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

Find Pair with Maximum NCR Value in C++

Arnab Chakraborty
Updated on 23-Jul-2020 07:17:14

196 Views

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

Minimum Removals from Array to Make GCD Greater in C++

Arnab Chakraborty
Updated on 23-Jul-2020 07:09:21

291 Views

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

Minimum Edges Required to Make Euler Circuit in C++

Arnab Chakraborty
Updated on 23-Jul-2020 06:48:55

262 Views

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

Minimum Cuts in Chessboard Using C++

Arnab Chakraborty
Updated on 23-Jul-2020 06:45:17

227 Views

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

Minimum Cost to Cut a Board into Squares in C++

Arnab Chakraborty
Updated on 23-Jul-2020 06:42:24

393 Views

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 Standard

Moumita
Updated on 22-Jul-2020 08:44:39

3K+ Views

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

Filtering Data with Pandas Query Method in Python

Pradeep Elance
Updated on 22-Jul-2020 08:41:05

2K+ Views

Pandas is a very widely used python library for data cleansing, data analysis etc. In this article we will see how we can use the query method to fetch specific data from a given data set. We can have both single and multiple conditions inside a query.Reading the dataLet’s first read the data into a pandas data frame using the pandas library. The below program just does that.Exampleimport pandas as pd # Reading data frame from csv file data = pd.read_csv("D:\heart.csv") print(data)OutputRunning the above code gives us the following result −Query with single conditionNext we see how we ... Read More

What are Hubs in Computer Network

Moumita
Updated on 22-Jul-2020 08:36:59

20K+ Views

Hubs are networking devices operating at a physical layer of the OSI model that are used to connect multiple devices in a network. They are generally used to connect computers in a LAN.A hub has many ports in it. A computer which intends to be connected to the network is plugged in to one of these ports. When a data frame arrives at a port, it is broadcast to every other port, without considering whether it is destined for a particular destination device or not.Features of HubsA hub operates in the physical layer of the OSI model.A hub cannot filter ... Read More

Filter Out Integers from Float Numpy Array in Python

Pradeep Elance
Updated on 22-Jul-2020 08:36:16

510 Views

As part of data cleansing activities, we may sometimes need to take out the integers present in a list. In this article we will have an array containing both floats and integers. We will remove the integers from the array and print out the floats.With astypeThe astype function will be used to find if an element from the array is an integer or not. Accordingly we will decide to keep or remove the element from the array and store it in the result set.Example Live Demoimport numpy as np # initialising array A_array = np.array([3.2, 5.5, 2.0, 4.1, 5]) ... Read More

Advertisements