Tree 1 - PowerPoint PPT Presentation

1 / 30
About This Presentation
Title:

Tree 1

Description:

???????????????????????? (Introduction) ????????????????????? ????????? ... hmin = 3. hmax = 5. A. B. C. D. E. 19. ?????????????????????? (complete binary tree) ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:3.0/5.0
Slides: 31
Provided by: x7314
Category:
Tags: hmin | tree

less

Transcript and Presenter's Notes

Title: Tree 1


1
??????Tree (1)
  • ?????????????? ?????????
  • ???????????????????????????????????????

2
????????????
  • ???????????????????????? (Introduction)
  • ????????????????????? ????????? (terminology)
  • ??????????????? (binary tree)
  • ?????????????????????? (complete binary tree)
  • (nearly complete binary tree)
  • ??????????????????????????????????

3
root
node
branch
?????????????????????????????????
4
????????????????????????
  • ???? ???????????????????????????????????????
    (Non-Linear Data Structure)
  • ???????????????????????????? (??????????)
  • ????????????????????????????????? ??? (Root)
  • ??????????????????????????????????????? ????
    (Node)
  • ??????????????????????????????????????????? ????
    (Branch) ???? ????? (Link)
  • ????????????????? ???????????? (subtree)
  • ??????????? root ??? subtree ????????????

5
R ???? root ??? subtree A,B,C,D A ???? root ???
subtree E,F,G F ???? root ??? subtree J C ????
subtree ???????? root C
6
????????????????????? ?????????
  • ?????? (tree) ??????????
  • 1.node ??????????????
  • 2.branch ????????? node ???????????

node A, B, C branch AB, AC
7
  • root ??????? node ?????? tree

root A ????????? B , C
  • Degree ??????? ????? subtree ?????????????? Node
    ?????

node A ?? degree ??????? 2 node B ?? degree
??????? 0 node C ?? degree ??????? 0
8
  • leaf ??????? node ????????????????? 0

root A leaf D , E , C
  • internal node , branch node ??????? node
    ????????? root ??? leaf

branch node B
9
  • parent ??????? node ????????????????? 0 (node
    ????? subtree )

parent A , B
  • child ??????? node ??????? subtree ??? tree ????

child B , C , D , E
10
  • level ????????????????? root ????? node ?????
  • height ???? depth ??? tree ??????? level ??????
    ??? leaf ??????? 1

depth 2 1 3
11
  • sibling ???????????????? parent ???????

sibling ??? B ??? C sibling ??? D ??? E ??? F
12
parents children leaves internal nodes depth
degree(A) degree(B) degree(H) degree(C) degree(E)
A, B, F
3
B, E, F, C, D, G, H, I
2
E, C, D, G, H, I
0
B, F
0
3
0
13
Exercise 1
A
  • - node ??????? parent
  • - node ??????? child
  • - level ??? tree
  • - height ??? tree
  • - degree ????????????
  • - parent ????????????
  • - children ????????????
  • - sibling ????????????

C
B
H
G
D
F
E
L
I
K
J
L
1.??? tree ???????? ???? - node ??????? root -
node ??????? leaf - node ??????? internal node
14
??????????????? (binary tree)
  • ??????? tree ???????? node ??????? subtree lt 2
    ( ????? node ?? degree lt 2 )

15
Empty ???? Null Tree
16
???????????????????????????
  • ?????????????????????????? (hight) ???????? node
    ?? binary tree
  • ???????? h ?????????????? binary tree
  • n ????????? node ?? binary tree
  • ???????????????? (h) ????????????????? node
    (n)????????????????????????????????????? binary
    tree ???????
  • ?????????????? node (n) ??????????????????? (h)
    ????????????????????????????????????? binary tree
    ???????

17
  • ??????????????????? binary tree 3

nmax 7
nmin 3
???????? nmax 2h 1 nmin h
18
  • ?????????????????? node ??? binary tree 5

hmax 5
hmin 3
???????? hmin log2n 1 hmax n
19
?????????????????????? (complete binary tree)
  • ??? binary tree ????? node ??????? level (???
    node ????????? leaf ?? child ?????????????????????
    ?)

nearly complete binary tree
  • ??? binary tree ????? node ??????? level ??????
    level ??????? ??? node ?? level
    ?????????????????????????????

20
(No Transcript)
21
??????????????????????????????????
  • binary tree ????????????????????????? 2 ??? ???
  • ??????????????????????
  • ??????????? 3 ????????????????????
  • ??????????? 1 ?????????????????????????????
  • ?????????????? pointer

22
???????????????????? 3 ????????????????????
  • ?????????????????????????????????? 3 ??? ???
  • data ????????????????? node
  • left ?????????????? node ?????????????????
  • right ?????????????? node ????????????????
  • ??? node ??????? node ??? ?????????? -1 (???
    NULL)
  • ???????????? root ?????????????? node ????? tree

23
????????
???????????????????
general binary tree
data
left
right
root
A
A
2
3
1
1
2
B
6
4
B
C
C
7
-1
3
E
8
5
4
H
-1
-1
5
D
E
F
D
-1
-1
6
F
-1
-1
7
G
H
G
-1
-1
8
24
???????????????????? 1 ???????????????????????????
??
  • ???????????????????? complete binary tree
  • ?????????????????????????? node ??????? level 0 ,
    1 , , k ????????
  • ??????? level ?????????????? node
    ???????????????????????????????? ????????
  • ?????????????????????? tree ?????????????????
    ???? complete binary tree

25
????????
general binary tree
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
???????????????????
26
  • ???????????????????????? tree ??? ???????? ??????
  • ??? binary tree ???????????????? h
    ?????????????????????????? 2h 1 ????????????
  • parent ??????? i ??? ???????????????? i/2 ??? i
    ?????????? 1
  • left child ??????? i ??? ???????????????? 2i
  • right child ??????? i ??? ???????????????? 2i 1

27
?????????????? pointer
  • ??????????????????????????????????
    ??????????????????????????????????????????????????
  • ?????????????? node ??? tree ??????????????
  • data ????????????????? node
  • Lptr ???? address ??? node ?????????????????
  • Rptr ???? address ??? node ????????????????

28
????????
29
???????
  • ??? binary tree ??????????????????????????????????
    ???????? 1 ??????????????????????????????????
    ??????????????????????? 1024 ????????????????
    ??????????????????
  • 1. binary tree ??????????????????
  • 2. ?????? ? ??????????????? 837 ???? parent node
    ???????? ? ?????????????????

30
???????
  • 3. ?????? ? ??????????????? 422
    ??????????????????? ? ?????????????
  • 4. ?????????????????????????????????????????
    ????????? ????????????
  • 5. ???????????????????????????????????????????????
    ????????? ????????? ????????????
Write a Comment
User Comments (0)
About PowerShow.com