Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSS446 Spring 2014 Nan Wang.  to study trees and binary trees  to understand how binary search trees can implement sets  to learn how red-black trees.

Similar presentations


Presentation on theme: "CSS446 Spring 2014 Nan Wang.  to study trees and binary trees  to understand how binary search trees can implement sets  to learn how red-black trees."— Presentation transcript:

1 CSS446 Spring 2014 Nan Wang

2  to study trees and binary trees  to understand how binary search trees can implement sets  to learn how red-black trees provide performance guarantees for set operations  to choose appropriate methods for tree traversal  to become familiar with the heap data structure  to use heaps for implementing priority queues and for sorting 2

3  In computer science, a tree is a hierarchical data structure composed of nodes.  Each node has a sequence of child nodes,  and one of the nodes is the root node.  LinkedList -- linear chain of nodes  Tree – a node can have more than one child 3

4 4

5 5

6  A node holds ◦ a data item and ◦ a list of references to the child nodes  A tree holds a reference to the root node 6 It is different from the LinkedList node

7  When computing tree properties, it is common to recursively visit smaller and smaller subtrees. 7 1 2 3

8  A binary tree consists of nodes, each of which has at most two child nodes. 8

9 9

10 10

11  In a balanced tree, all paths from the root to the leaves have approximately the same length.  What is height of the tree?  Which one hold more nodes? 11

12  Given the height of a tree of h, what is the number of the nodes for a complete binary tree?  Given the number of nodes in a complete binary tree, what is the height of the tree? 12

13 13

14  Recursive Method 14 Recursive helper Without recursive helper Method in next slides

15 15

16  HashSet & TreeSet  A set implementation rearrange its elements in way so that finding elements quickly. (sort elements)  Binary Search takes O(log(n))  Array takes O(n) 16

17 17

18 18

19 19

20 20

21 21

22 22

23 23

24 24

25 25

26 26

27 27

28 28

29 29

30 30

31 31  Start with an empty binary search tree. ◦ Insert the keys 4,12,8,16,6,18,24,2,14,3, draw the tree following each insert. ◦ From the tree above, delete the keys, 6,14,16,4 in order, draw the search tree following each deletion.

32 32


Download ppt "CSS446 Spring 2014 Nan Wang.  to study trees and binary trees  to understand how binary search trees can implement sets  to learn how red-black trees."

Similar presentations


Ads by Google