This idea sems to be fastest what u can do ..as i know.
Then u need to have 2 booleans.

CanItBeLocked: true/false
ActualStatus: locked/unlocked.

So whenever you want to query a node u simply check CanItBeLocked.

But when u actually want to lock/unlock it. then you need to do a
status (CanItBeLocked) update for:

1) All its descendants
2) all the ascendants uptill root ( only parent, parent->parent etc)

So u end up with 2 pow (n-l) complexity , with 'n' being ht of tree and
'l' level of node being modified.

lock (node):
if ( node->CanItBeLocked)
{
ActualStatus = locked;
traverse all descendants->CanItBeLocked = FALSE;
traverse all parents till root CanItBeLocked = FALSE;
}

Exactly opposite for unlock(node) , because after when u have locked
this node,
none of ascendants path or descendants would get locked and all had
CanItBeLocked  = TRUE that time which u should return back while
unlocking.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to