1 / 17

Operations on 2-4 Trees: Find, Insert, Delete, Catenate & Split

This document details the operations performed on 2-4 trees, a type of balanced search tree. Operations include finding an element, inserting a new node while maintaining balance, deleting nodes using established rules, concatenating two sorted lists, and splitting a list based on a specified value. 2-4 trees ensure that all leaves are at equal depth and can have 2, 3, or 4 children per internal node, providing efficient logarithmic time complexity for these operations. The provided guidelines outline the mechanics behind each operation for efficient data handling.

Télécharger la présentation

Operations on 2-4 Trees: Find, Insert, Delete, Catenate & Split

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 2-4 Trees

  2. Goal Keep sorted lists subject to the following operations: find(x,L) insert(x,L) delete(x,L) catenate(L1,L2) : Assumes that all items in L2 are greater than all items in L1. split(x,L) : returns two lists one with all item less than or equal to x and the other with all items greater than x.

  3. . . . . . . . . . . . . . . . . . 1 3 12 14 15 18 20 21 28 40 2-4 trees • Items are at the leaves. • All leaves are at the same distance from the root. • Every internal node has 2, 3, or 4 children.

  4. Insert . . . . . . . . . . . . . . . . . 1 3 12 14 15 18 20 21 28 40 16

  5. Insert (cont) . . . . . . . . . . . . . . . 1 3 12 14 15 16 18 20 21 28 40

  6. Insert (cont) . . . . . . . . . . . . . . . 1 3 12 14 15 16 18 20 21 28 40 23

  7. Insert (cont) . . . . . . . . . . . 1 3 12 14 15 16 18 20 21 23 28 40

  8. Insert (cont) . . . . . . . . . . . 1 3 12 14 15 16 18 20 21 23 28 40

  9. Insert (cont) . . . . . . . . . . . 1 3 12 14 15 16 18 20 21 23 28 40

  10. Insert -- definition Add the new leaf in its position. Say under a node v. (*) If the degree of v is 5 split v into a 2-node u and a 3-node w. If v was the root then create a new root r parent of u and w and stop. Replace v by u and w as children of p(v). Repeat (*) for v := p(v).

  11. Delete . . . . . . . . . . . 1 3 12 14 15 16 18 20 21 23 28 40

  12. Delete . . . . . . . . . . . 1 3 12 14 15 18 20 21 23 28 40

  13. Delete . . . . . . . . . . . 1 3 12 14 15 18 20 21 23 28 40

  14. Delete . . . . . . . . . . . 1 3 12 14 18 20 21 23 28 40

  15. Delete . . . . . . . . . . . 1 3 12 14 18 20 21 23 28 40

  16. Delete -- definition Remove the leaf. Let v be the parent of the removed leaf. (*) If the degree of v is one, and v is the root discard v. Otherwise (v is not a root), if v has a sibling w of degree 3 or 4, borrow a child from w to v and terminate. Otherwise, fuse v with its sibling to a degree 3 node and repeat (*) with the parent of v.

  17. Summary Delete and insert take O(log n) on the worst case. Theorem (homework) : A sequence of m delete and insert operations on an initial tree with n nodes takes O(m+n) time Can do catenate and split in a way similar to red-black trees.

More Related