![]() |
|
#1
|
||||
|
||||
Binary tree deletion algorithmHello,
Ive been trying to write a program to delete a node from a binary tree. The algorithm is pretty simple for a node with no children (leaf) and a node with one child. However for a node with 2 children, heres what the problem is (what the text says so atleast): When a node with 2 children is deleted, another node must take its place. However we cannot simply assign the parent of the node being deleted to one of the children of the deleted node as then the following characteristic of a binary tree doesn't hold: values in any left subtree are to be less than the value in the parent node and values in any right subtree are to be greater than the parent node. I am having trouble understanding or rather visualizing this problem. So heres to give an example: Shown in the picture attached is a sample binary tree in which I decide to delete node 97. If I replace it with 92 then as it shows there is no problem except that I would have to assign the right pointer of 92 to 99 and the rest takes care of itself. However when I replace 97 with 99, then in that case I have no where to shift 92 as it will be competing with 98 (since neither 92 nor 98 can be on the right side of 99). Is this the problem that the text talks about in the last paragraph? __________________
Hope to hear from you guys! -------------------------------------------------- Best Regards, Aijaz Baig. |
||||
|
#2
|
|||
|
|||
Re: Binary tree deletion algorithmDear Friend,
I have attached program to delete the element in the Binary Tree CPP / C++ / C Code:
Last edited by LuciWiz : 27-Feb-2010 at 02:17.
Reason: Please insert your C++ code between [cpp] & [/cpp] tags
|
Recent GIDBlog
Install Adobe Flash - Without Administrator Rights by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Link List In C | Peter_APIIT | C Programming Language | 33 | 12-Jun-2008 14:33 |
| Please Help. I have 3 Qns regarding AVL tree in data structure , Kindly give answer | syamsankar | C++ Forum | 1 | 30-Mar-2007 09:29 |
| can anyone help me with my tree :) | bioeng_mtm | C++ Forum | 5 | 22-Apr-2006 13:50 |
| printing binary search tree | nkhambal | C Programming Language | 2 | 26-Mar-2005 04:01 |
| Binary Tree Trouble | neufunk | C Programming Language | 4 | 06-Dec-2004 10:52 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The