Download presentation
Presentation is loading. Please wait.
Published byHassan Dorrance Modified over 10 years ago
1
CS-2852 Data Structures LECTURE 11 Andrew J. Wozniewicz Image copyright © 2010 andyjphoto.com
2
CS-2852 Data Structures, Andrew J. Wozniewicz Agenda Binary Search Trees – Removing Data
3
CS-2852 Data Structures, Andrew J. Wozniewicz Removing Data Arguably, the most complex algorithm of the course! Find the node to be deleted – If it doesn’t exist: exit Leaf (Terminal) Node: – Remove the parent’s reference to deleted node Non-Leaf Node: – Find the child to replace the deleted node – THREE scenarios…
4
Remove: Case 1 Removed Node has no right child – Left child replaces removed remove(8)
5
Remove: Case 1 Removed Node has no right child – Left child replaces removed remove(8) – Find node to remove – Has no right child ?
6
Remove: Case 1 Removed Node has no right child – Left child replaces removed remove(8) – Find node to remove – Has no right child – Promote left child
7
Remove: Case 2 Removed right child has no left – Right child replaces removed remove(6)
8
Remove: Case 2 Removed right child has no left – Right child replaces removed remove(6) – Find node to remove – Node right has no left
9
Remove: Case 2 Removed right child has no left – Right child replaces removed remove(6) – Find node to remove – Node right has no left – Promote right child
10
Remove: Case 2 Removed right child has no left – Right child replaces removed remove(6) – Find node to remove – Node right has no left – Promote right child
11
Remove: Case 3 Removed right child has left child – Right child’s left-most child replaces removed remove(6)
12
Remove: Case 3 Removed right child has left child – Right child’s left-most child replaces removed remove(6) – Find node to remove – Node on right has left – Find right’s leftmost child – Promote leftmost child
13
Remove: Case 3 Removed right child has left child – Right child’s left-most child replaces removed remove(6) – Find node to remove – Node on right has left – Find right’s leftmost child – Promote leftmost child
14
Remove: Case 3 Removed right child has left child – Right child’s left-most child replaces removed remove(6) – Find node to remove – Node on right has left – Find right’s leftmost child – Promote leftmost child
15
Remove: Case 3 Removed right child has left child – Right child’s left-most child replaces removed remove(6) – Find node to remove – Node on right has left – Find right’s leftmost child – Promote leftmost child
16
CS-2852 Data Structures, Andrew J. Wozniewicz Summary Binary Search Trees – Removing Data
17
Questions? Image copyright © 2010 andyjphoto.com
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.