sw
BAN USER
I think this is more of a data structure question:
appropriate data structure for such problems is heap, represented in an array
now apply pseudo delete operation on nodes with key zero(non null), similar to what we do during heap sort
If we have to do it in a binary tree data structure, then approach would be:
do post order traversal and when processing root, sink root to the subtree which has a non zero root
- do a normal dfs from the source
- once you reach destination node, mark all nodes on the path as being connected to the destination
- now while exploring other paths, if you ever hit a node that has a path to destination, then mark all nodes on the current path as connected to destination and return
- to keep track of nodes connected to destination, we can simply keep connected nodes in a hash set
Repirenedpisano, Blockchain Developer at ABC TECH SUPPORT
Hello, I am Irene and I live in Pittsburgh, USA. I am working as A production worker and my duty ...
RepDustinSeals, Accountant at 247quickbookshelp
I am Dustin . Speech-language pathologist in Standard Brands Paint Company. I diagnose and swallow problems. I work with both children ...
Replillyalaird, Associate at Achieve Internet
I am Lilly from Eau Claire USA, I am working as a manager in a Best products company. My interest ...
Repruchikadolph, HR Executive at Accenture
I choose the talking books to match the book library clerk blind library patrons . I compare a list of borrowers ...
Repangelwilley8, xyz at Asiatic Solutions
I am Angel J. Willey from Gurnee. I am working as a truck driver in Asiatic Solutions company. I also ...
Repellaiyer15, Content Writer at Precious Moments
Committed to producing exceptional and creative types of content, including articles, internet content, advertisements, commercials, brochures, and publications. Experienced in ...
Repfloydmsnyder, Theoretical mathematician at STM Auto Parts
As a Theoretical Mathematician,I’m little more interested in the theory involved with mathematics. In my free time , I ...
Reppathfisher, Animator at Rack N Sack
I am Pat working in Rack N Sack where I use sequential images to produce the illusion of movement and ...
RepLuciaLuci, Animator at Barclays Capital
I am Lucia, a Neuropsychologist in Philadelphia USA . aiming to understand how behavior and cognition are influenced by brain function ...
Repellahrivas6, Android test engineer at 247quickbookshelp
I am working as an internist and I work in medical offices, clinics, and hospitals. An internist may work independently ...
I think, if we need to remove duplicates then answer should be : not possible
- sw August 06, 2014