Thread: BST - delete node

  1. #1
    Registered User marrk's Avatar
    Join Date
    Sep 2006
    Posts
    23

    BST - delete node

    One quick qestion, which is probably also silly but anyway, when I deletenig a node in BST which has a right child and it's right child has a left child, does it matter if I swap deleting node with a smallest value from a right subtree or with a greatest value from a left subtree?

    Thanks
    Last edited by marrk; 12-19-2006 at 05:25 PM.

  2. #2
    Registered User
    Join Date
    Dec 2006
    Posts
    30
    both should be okay

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >does it matter if I swap deleting node with a smallest value from a right subtree or with a greatest value from a left subtree?
    In theory, you should alternate between them because focusing on one subtree can cause an imbalance. However, in practice you're extremely unlikely to see that case with an unbalanced tree, so it doesn't matter.
    My best code is written with the delete key.

  4. #4
    Registered User marrk's Avatar
    Join Date
    Sep 2006
    Posts
    23
    I will stick to practice

    btw - nice tutorial on C++ World

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >btw - nice tutorial on C++ World
    Eew, you're still reading those old ones? I've updated several times since those were written, and you can find the latest at http://eternallyconfuzzled.com/brain.html.
    My best code is written with the delete key.

  6. #6
    Registered User marrk's Avatar
    Join Date
    Sep 2006
    Posts
    23
    Wow your tutorials are great
    keep on the good work

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help Debugging my AVL tree program.
    By Nextstopearth in forum C Programming
    Replies: 2
    Last Post: 04-04-2009, 01:48 AM
  2. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM