Loading in 5 sec....

2620001 Data StructuresPowerPoint Presentation

2620001 Data Structures

- 66 Views
- Uploaded on
- Presentation posted in: General

2620001 Data Structures

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 - - - - - - - - - - - - - - - - - - - - - - - - - -

2620001Data Structures

Search Trees

- 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.

- 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

- 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 }

- A tree representing a set of strings.

c

a

{

aeef

ad

bbfe

bbfg

c }

b

e

b

d

e

f

c

f

e

g

- 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

- Example code:

class Node {

Node left, right;

boolean leftThread, rightThread;

}

6

8

3

1

5

7

11

9

13

- 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

Output

1

3

6

8

3

1

5

7

11

9

13

Follow thread to right, print node

Output

1

3

5

6

8

3

1

5

7

11

9

13

Follow link to right, go to leftmost node and print

Output

1

3

5

6

6

8

3

1

5

7

11

9

13

Follow thread to right, print node

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

Output

1

3

5

6

7

8

6

8

3

1

5

7

11

9

13

Follow thread to right, print node

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

Output

1

3

5

6

7

8

9

11

6

8

3

1

5

7

11

9

13

Follow thread to right, print node

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