|
SL Newsletter
|
| Recieve bi-weekly updates on news, new articles, and more |
|
|
|
|

04-20-01, 06:30 PM
|
 |
Feel The Burn
|
|
Join Date: Dec 2000
Location: Montreal
Posts: 467
|
|
[ No programming section, so I shall put this here  ]
How would you go about coding the removal of an element from a binary tree ?
If the element is the last of it's branch, you just set the parent's pointer to null. Example
If the element branches out only on one side, you change his parent's pointer to put on it's children. Example
But what if the element to be taken out has 2 children ? Example
I know many won't understand what the heck I'm talking about, so just ignore this post 
|

06-21-01, 01:04 PM
|
 |
SLCentral.com Staff
|
|
Join Date: Dec 2000
Location: New York, USA
Posts: 354
|
|
hehe this sounds like a good question. I'm kinda surprised no one's answered it yet... the concepts of removing elements in a binary tree were taught to me in my advanced algorithms class about a year ago so it's kinda hazy hehe. Language shouldn't be a problem, as long as you implement the algorithm correctly. If you want to remove a specific element, I suppose you can traverse the binary tree "in-order" recursively until you find your element and then remove it. I believe there is a transformation that you must do to the tree so that it preserves it's properties, or is that with heaps... I dunno I'm a programmer so this question kinda caught my eye. I could have probably answered this without a problem last year hehe, now I'll have to dig into my books... if I can find em hehehe
__________________
SystemLogic.net - Editor
2 Pentium III 1 Ghz 2 Alpha HeatSinks with 38 CFM Delta Fan | Abit VP6 | 512 MB PC-166 | Antec SX1030B with 4 High Output 80mm Sunon Fans | 2 30 GB IBm 75 Drives in RAID 0 | Plextor PlexWriter 16/10/40A | Mitsumi 40x CD-ROM | Generic 3.5" Floppy Drive | VisionTek Geforce 2 GTS 32 MB | Sound Blaster Live! Value | 3com NIC | Diamond Supra Modem | 19" Sony Monitor | Klipsch Promedia V.2-400 Speakers | PcMods.com Sound Sensitive Blue
"No more yankie my wankie. The Donger need food!"
More people are killed annually by donkeys than die in air crashes.
|

06-21-01, 04:35 PM
|
|
|
Hi,
Here's what you'll need to do:
Remove the element by pointing its parent node to the child node on the right. Traverse the binary subtree from the righthand child node till you get to the end on the left (the lowest value in the subtree), and attach the left child node of the element to be removed to the left of this last node in the subtree. Even if the lefthand child node has a subtree below it, you still maintain the binariness of the tree.
Cheers,
Sunil Bhadekar
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 09:37 PM.
Hardware
Reviews, Articles, News, All Reviews...
|
Gaming
Reviews, Articles, News...
|
 |
|
|
Regular Sections
A Guru's World, CPU/Memory Watch, SLDeals...
|
 |
SLBoards
Forums, Register(Free), Todays Discussions...
|
Site Info
Search, About Us, Advertise...
|
 |
|