DSW algorithm - PowerPoint PPT Presentation

1 / 10
About This Presentation
Title:

DSW algorithm

Description:

Devised by Colin Day and improved by Quentin F. Stout and Bette L. Warren ... Transfigure this tree into backbone. Then, create a perfect balanced binary search tree ... – PowerPoint PPT presentation

Number of Views:3193
Avg rating:3.0/5.0
Slides: 11
Provided by: mailTm
Category:
Tags: dsw | algorithm

less

Transcript and Presenter's Notes

Title: DSW algorithm


1
DSW algorithm
2
DSW algorithm
  • To avoid sorting, it required deconstructing and
    then reconstructing the tree, which is
    inefficient except for relatively small trees
  • DSW algorithm require little additional storage
    for intermediate variables and use no sorting
    procedure
  • Devised by Colin Day and improved by Quentin F.
    Stout and Bette L. Warren

3
  • First phase The DSW algorithm transfigures an
    arbitrary BST into a link listlike tree called a
    backbone (or a vine).
  • Second phase This elongated tree is transformed
    in a series of passes into a perfected tree by
    repeatedly rotating every second node of the
    backbone about its parent

4
First phase
  • Createbackbone(root,n)
  • tmproot
  • while (tmp!null)
  • if (tmp has a left child)
  • rotate this child about tmp
  • //hence the left child became parent of
    tmp
  • set tmp to the child which just became
    parent
  • else set tmp to the right child

5
Transforming a BST into a backbone
6
  • The building block for the tranformations is the
    rotation. (rotate right, left)
  • Rotateright(gr,par, ch)
  • if par is not the root of the tree //i.e., if
    gr isnt null
  • grandparent gr of child ch becomes chs
    parent by replacing par
  • right subtree of ch becomes left subtree of
    chs parent par
  • node ch acquires par as its right child

7
the second phase
  • Createperfecttree(n)
  • m2 lg(n1) -1
  • Make n-m rotations starting from the top of
    backbone//first pass
  • while (mgt1)
  • mm/2
  • Make m rotations starting from the top
    of backbone

In the second phase, the backbone is transformed
into a tree, but this time, the tree is perfectly
balanced by having leaves only on two adjacent
levels. In each pass down the backbone, every
second node is rotated about its parent. On such
pass decreases the size of the backbone by
one-half. But the first pass
8
M3/2 Make 1 rotation
M7/2 Make 3 rotations
First pass make 9-7 rotations
9
Exercise-1
  • Transfigure this tree into backbone
  • Then, create a perfect balanced binary search tree

10
Exercise-2
  • Transfigure the backbone to create a perfect
    balanced binary search tree
Write a Comment
User Comments (0)
About PowerShow.com