Click here to Skip to main content
15,913,140 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Saturday programming challenge Pin
PIEBALDconsult16-Nov-14 11:55
mvePIEBALDconsult16-Nov-14 11:55 
GeneralRe: Saturday programming challenge Pin
PIEBALDconsult16-Nov-14 16:37
mvePIEBALDconsult16-Nov-14 16:37 
GeneralRe: Saturday programming challenge Pin
Jörgen Andersson16-Nov-14 20:29
professionalJörgen Andersson16-Nov-14 20:29 
GeneralRe: Saturday programming challenge Pin
PIEBALDconsult17-Nov-14 4:05
mvePIEBALDconsult17-Nov-14 4:05 
GeneralRe: Saturday programming challenge Pin
PIEBALDconsult17-Nov-14 13:28
mvePIEBALDconsult17-Nov-14 13:28 
GeneralRe: Saturday programming challenge Pin
PIEBALDconsult16-Nov-14 13:57
mvePIEBALDconsult16-Nov-14 13:57 
GeneralRe: Saturday programming challenge Pin
Jörgen Andersson16-Nov-14 20:20
professionalJörgen Andersson16-Nov-14 20:20 
GeneralRe: Saturday programming challenge Pin
Michael Sisco17-Nov-14 7:14
Michael Sisco17-Nov-14 7:14 
It strikes me that this problem MIGHT be solved using the simplest approach, depending on the frequency of this search for LCA relative to adding or removing elements from the tree, and the efforts already taken to maintain some level of balance in the tree. Any work that's needed to maintain the ancestor lists for every node would slow down the (typically very common) task of adding and removing nodes. It could also add up to a very large amount of storage if the tree is sufficiently large.

However, the simple process starting with the two nodes and moving back up the tree a level at a time until a common ancestor is found should be relatively fast (tree depth should be relatively shallow for a balanced tree), and it requires no additional storage per node.

I realize that this question was asked as more of a "fun" thought experiment, but I think that without more information about the specific task at hand, it's not really possible to determine whether you've found "the most efficient way".

Sorry if I sound like a killjoy.
GeneralRe: Saturday programming challenge Pin
Jörgen Andersson17-Nov-14 8:59
professionalJörgen Andersson17-Nov-14 8:59 
JokeNew Tattoo PinPopular
Mike Hankey15-Nov-14 10:25
mveMike Hankey15-Nov-14 10:25 
GeneralRe: New Tattoo Pin
Oso Oluwafemi Ebenezer17-Nov-14 3:55
Oso Oluwafemi Ebenezer17-Nov-14 3:55 
GeneralRe: New Tattoo Pin
PhilLenoir17-Nov-14 4:33
professionalPhilLenoir17-Nov-14 4:33 
GeneralRe: New Tattoo Pin
Oso Oluwafemi Ebenezer17-Nov-14 5:09
Oso Oluwafemi Ebenezer17-Nov-14 5:09 
GeneralRe: New Tattoo Pin
Gary R. Wheeler21-Nov-14 12:56
Gary R. Wheeler21-Nov-14 12:56 
Generalfrom flippin' at the Golden Arches to Twitch super-star and Red-Bull-Boy Pin
BillWoodruff15-Nov-14 7:27
professionalBillWoodruff15-Nov-14 7:27 
GeneralRe: from flippin' at the Golden Arches to Twitch super-star and Red-Bull-Boy Pin
PIEBALDconsult15-Nov-14 8:09
mvePIEBALDconsult15-Nov-14 8:09 
GeneralRe: from flippin' at the Golden Arches to Twitch super-star and Red-Bull-Boy Pin
newton.saber15-Nov-14 9:32
newton.saber15-Nov-14 9:32 
GeneralRe: from flippin' at the Golden Arches to Twitch super-star and Red-Bull-Boy Pin
BillWoodruff15-Nov-14 10:19
professionalBillWoodruff15-Nov-14 10:19 
GeneralRe: from flippin' at the Golden Arches to Twitch super-star and Red-Bull-Boy Pin
newton.saber16-Nov-14 4:22
newton.saber16-Nov-14 4:22 
GeneralRe: from flippin' at the Golden Arches to Twitch super-star and Red-Bull-Boy Pin
Mark_Wallace15-Nov-14 9:14
Mark_Wallace15-Nov-14 9:14 
GeneralRe: from flippin' at the Golden Arches to Twitch super-star and Red-Bull-Boy Pin
newton.saber15-Nov-14 9:34
newton.saber15-Nov-14 9:34 
GeneralRe: from flippin' at the Golden Arches to Twitch super-star and Red-Bull-Boy Pin
BillWoodruff15-Nov-14 10:08
professionalBillWoodruff15-Nov-14 10:08 
GeneralRe: from flippin' at the Golden Arches to Twitch super-star and Red-Bull-Boy Pin
newton.saber16-Nov-14 4:19
newton.saber16-Nov-14 4:19 
GeneralAPOD Pin
R. Giskard Reventlov15-Nov-14 3:55
R. Giskard Reventlov15-Nov-14 3:55 
GeneralRe: APOD Pin
glennPattonWork315-Nov-14 4:31
professionalglennPattonWork315-Nov-14 4:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.