[algogeeks] Special Binary Tree Again

2011-02-14 Thread bittu
You have a tree, in which each node has an additional pointer, P. P
can either be NULL or point a node preceding P’s node in the in-order
traversal of the tree. Write a program to check in a tree if each
node’s P is assigned correctly. If not, make P null

Thanks
Shashank

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Special Binary Tree Again

2011-02-14 Thread SEHAJ SINGH KALRA
What is meant by :
preceding P’s node in the in-order
traversal of the tree  ?

On Mon, Feb 14, 2011 at 7:03 PM, bittu shashank7andr...@gmail.com wrote:

 You have a tree, in which each node has an additional pointer, P. P
 can either be NULL or point a node preceding P’s node in the in-order
 traversal of the tree. Write a program to check in a tree if each
 node’s P is assigned correctly. If not, make P null

 Thanks
 Shashank

 --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Special Binary Tree Again

2011-02-14 Thread Tushar Bindal
I think the following algo should work:
1. Create a DLL of the inorder traversal of the tree
2. for each node, check whether P of that node points to the previous node
in the DLL or not.
3. If not, assign it value NULL



-- 
Tushar Bindal
Computer Engineering
Delhi College of Engineering
Mob: +919818442705
E-Mail : tusharbin...@jugadengg.com, tushicom...@gmail.com

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Special Binary Tree Again

2011-02-14 Thread jalaj jaiswal
@tushar that would modify the tree structure

here is a different approach

int count=0;  //global
void modified_inorder(node *root){
   if(root!=NULL){
 modified_inorder(root-left);
 node *temp;
 if(count==0){
  root-p=NULL;
  temp=root;
  count++;
  }
 else{
if(root-p!=temp){
root-p=NULL;
}
temp=root;
}

}

On Mon, Feb 14, 2011 at 7:59 PM, Tushar Bindal tushicom...@gmail.comwrote:

 I think the following algo should work:
 1. Create a DLL of the inorder traversal of the tree
 2. for each node, check whether P of that node points to the previous node
 in the DLL or not.
 3. If not, assign it value NULL



 --
 Tushar Bindal
 Computer Engineering
 Delhi College of Engineering
 Mob: +919818442705
 E-Mail : tusharbin...@jugadengg.com, tushicom...@gmail.com

  --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
With Regards,
*Jalaj Jaiswal* (+919019947895)
Software developer, Cisco Systems
B.Tech IIIT ALLAHABAD

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Special Binary Tree Again

2011-02-14 Thread sanchit mittal
explain algo instead of writing the code.
thanx

On Mon, Feb 14, 2011 at 9:28 PM, jalaj jaiswal jalaj.jaiswa...@gmail.comwrote:

 @tushar that would modify the tree structure

 here is a different approach

 int count=0;  //global
 void modified_inorder(node *root){
if(root!=NULL){
  modified_inorder(root-left);
  node *temp;
  if(count==0){
   root-p=NULL;
   temp=root;
   count++;
   }
  else{
 if(root-p!=temp){
 root-p=NULL;
 }
 temp=root;

 }

 }

 On Mon, Feb 14, 2011 at 7:59 PM, Tushar Bindal tushicom...@gmail.comwrote:

 I think the following algo should work:
 1. Create a DLL of the inorder traversal of the tree
 2. for each node, check whether P of that node points to the previous node
 in the DLL or not.
 3. If not, assign it value NULL



 --
 Tushar Bindal
 Computer Engineering
 Delhi College of Engineering
 Mob: +919818442705
 E-Mail : tusharbin...@jugadengg.com, tushicom...@gmail.com

  --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 With Regards,
 *Jalaj Jaiswal* (+919019947895)
 Software developer, Cisco Systems
 B.Tech IIIT ALLAHABAD

   --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Sanchit Mittal
Second Year Undergraduate
Computer Engineering
Delhi College of Engineering
ph- +919582414494

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Special Binary Tree Again

2011-02-14 Thread jalaj jaiswal
@ sanchit
m dong inorder traversal and at every step chking whether the node's p
pointer is pointing to its inorder predecesor, which is temp or not and
making it NULL otherwise. when count is 0 the node do not hv any predecessor
so m directly pointing that to NULL.

*please see the below alg0 , the abv algo by me is incomplete (sorry  :(
 ) *

int count=0;  //global
void modified_inorder(node *root){
   if(root!=NULL){
 modified_inorder(root-left);
 node *temp;
 if(count==0){
  root-p=NULL;
  temp=root;
  count++;
  }
 else{
if(root-p!=temp){
root-p=NULL;
}
temp=root;
 modified_inorder(root-right);
  }
}
}

On Mon, Feb 14, 2011 at 9:45 PM, sanchit mittal sm14it...@gmail.com wrote:

 explain algo instead of writing the code.
 thanx


 On Mon, Feb 14, 2011 at 9:28 PM, jalaj jaiswal 
 jalaj.jaiswa...@gmail.comwrote:

 @tushar that would modify the tree structure

 here is a different approach

 int count=0;  //global
 void modified_inorder(node *root){
if(root!=NULL){
  modified_inorder(root-left);
  node *temp;
  if(count==0){
   root-p=NULL;
   temp=root;
   count++;
   }
  else{
 if(root-p!=temp){
 root-p=NULL;
 }
 temp=root;

 }

 }

 On Mon, Feb 14, 2011 at 7:59 PM, Tushar Bindal tushicom...@gmail.comwrote:

 I think the following algo should work:
 1. Create a DLL of the inorder traversal of the tree
 2. for each node, check whether P of that node points to the previous
 node in the DLL or not.
 3. If not, assign it value NULL



 --
 Tushar Bindal
 Computer Engineering
 Delhi College of Engineering
 Mob: +919818442705
 E-Mail : tusharbin...@jugadengg.com, tushicom...@gmail.com

  --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 With Regards,
 *Jalaj Jaiswal* (+919019947895)
 Software developer, Cisco Systems
 B.Tech IIIT ALLAHABAD

   --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Sanchit Mittal
 Second Year Undergraduate
 Computer Engineering
 Delhi College of Engineering
 ph- +919582414494

  --
 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
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
With Regards,
*Jalaj Jaiswal* (+919019947895)
Software developer, Cisco Systems
B.Tech IIIT ALLAHABAD

-- 
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 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.