10.09.2013 Views

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

LECTURE NOTES OF ADVANCED DATA STRUCTURE (MT-CSE 110)<br />

DELETING FROM A BINARY TREE.<br />

4 cases to consider, although some may be handled by the same strategy:<br />

1) Node is a leaf.<br />

2) Node has a left child only.<br />

3) Node has a right child.<br />

4) Node has two children.<br />

Case 1 is obviously simple:<br />

Case <strong>1.</strong> Delete a leaf (node with 0 children).<br />

Easy: (a) Find node’s address and store it.<br />

(b) Set parent’s pointer to NULL.<br />

(c) delete leaf node.<br />

Case 2: Node has a left child only.<br />

Want to dispose of parent, but keep left child (and any of its children).<br />

Case 3: Node has a right child only.<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

Assist Prof., CSE, H.C.T.M (Kaithal) Page ‐ 199 ‐

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!