2620001 data structures
This presentation is the property of its rightful owner.
Sponsored Links
1 / 18

2620001 Data Structures PowerPoint PPT Presentation


  • 52 Views
  • Uploaded on
  • Presentation posted in: General

2620001 Data Structures. Search Trees. B+ - Tree Structure. A B+ - Tree is in the form of a balanced tree in which every path from the root of the tree to a leaf of the tree is the same length. Each nonleaf node in the tree has between [n/2] and n children, where n is fixed.

Download Presentation

2620001 Data Structures

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


2620001 data structures

2620001Data Structures

Search Trees


B tree structure

B+ - Tree Structure

  • A B+ - Tree is in the form of a balanced tree in which every path from the root of the tree to a leaf of the tree is the same length.

  • Each nonleaf node in the tree has between [n/2] and n children, where n is fixed.

  • B+ - Trees are good for searches, but cause some overhead issues in wasted space.


B trees summary

B+ Trees: Summary

  • Searching:

    • logd(n) – Where d is the order, and n is the number of entries

  • Insertion:

    • Find the leaf to insert into

    • If full, split the node, and adjust index accordingly

    • Similar cost as searching

  • Deletion

    • Find the leaf node

    • Delete

    • May not remain half-full; must adjust the index accordingly


Standard tries

Standard Tries

  • The standard trie for a set of strings S is an ordered tree such that:

    • Each node but the root is labeled with a character

    • The children of a node are alphabetically ordered

    • The paths from the external nodes to the root yield the strings of S

  • Example: standard trie for the set of strings

    S = { bear, bell, bid, bull, buy, sell, stock, stop }


Trie suffix tree

Trie / Suffix Tree

  • A tree representing a set of strings.

c

a

{

aeef

ad

bbfe

bbfg

c }

b

e

b

d

e

f

c

f

e

g


Threaded binary trees

Threaded Binary Trees

  • Binary trees have a lot of wasted space: the leaf nodes each have 2 null pointers

  • We can use these pointers to help us in inorder traversals

  • We have the pointers reference the next node in an inorder traversal; called threads

  • We need to know if a pointer is an actual link or a thread, so we keep a boolean for each pointer


Threaded tree code

Threaded Tree Code

  • Example code:

class Node {

Node left, right;

boolean leftThread, rightThread;

}


Threaded tree example

Threaded Tree Example

6

8

3

1

5

7

11

9

13


Threaded binary tree traversal

Threaded Binary Tree Traversal

  • We start at the leftmost node in the tree, print it, and follow its right thread

  • If we follow a thread to the right, we output the node and continue to its right

  • If we follow a link to the right, we go to the leftmost node, print it, and continue


Threaded tree traversal

Threaded Tree Traversal

Output

1

3

6

8

3

1

5

7

11

9

13

Follow thread to right, print node


Threaded tree traversal1

Threaded Tree Traversal

Output

1

3

5

6

8

3

1

5

7

11

9

13

Follow link to right, go to leftmost node and print


Threaded tree traversal2

Threaded Tree Traversal

Output

1

3

5

6

6

8

3

1

5

7

11

9

13

Follow thread to right, print node


Threaded tree traversal3

Threaded Tree Traversal

Output

1

3

5

6

7

6

8

3

1

5

7

11

9

13

Follow link to right, go to leftmost node and print


Threaded tree traversal4

Threaded Tree Traversal

Output

1

3

5

6

7

8

6

8

3

1

5

7

11

9

13

Follow thread to right, print node


Threaded tree traversal5

Threaded Tree Traversal

Output

1

3

5

6

7

8

9

6

8

3

1

5

7

11

9

13

Follow link to right, go to leftmost node and print


Threaded tree traversal6

Threaded Tree Traversal

Output

1

3

5

6

7

8

9

11

6

8

3

1

5

7

11

9

13

Follow thread to right, print node


Threaded tree traversal7

Threaded Tree Traversal

Output

1

3

5

6

7

8

9

11

13

6

8

3

1

5

7

11

9

13

Follow link to right, go to leftmost node and print


Example 2

Example - 2


  • Login