?9? ????(Sorting) - PowerPoint PPT Presentation

1 / 60
About This Presentation
Title:

?9? ????(Sorting)

Description:

9 Sorting 9-1 9-2 9-3 9-4 9-1 - ... – PowerPoint PPT presentation

Number of Views:102
Avg rating:3.0/5.0
Slides: 61
Provided by: NB14
Category:
Tags: bubble | sorting

less

Transcript and Presenter's Notes

Title: ?9? ????(Sorting)


1
?9? ????(Sorting)
  • 9-1 ?????
  • 9-2 ??????
  • 9-3 ????????
  • 9-4 ??????

2
9-1 ?????-??
  • ????(Data)??????????????????????????,??????????
  • ??????????,???????????,???????????????????(Data
    Hierarchy)?

3
9-1 ?????-????
  • ?????????????????????,8????????,????????????,????
    ????,????????????,?????????????,?????

4
9-1 ?????-?????(??)
  • ??????????????????????,????????,??????(Key),??????
    ??????????
  • ???????????????????????????????,?????????????????
    ??????,????????90?,??????????????????,?????????
  • ????,????????????????,?????????????

5
9-1 ?????-?????(??)
6
9-1 ?????-?????(??)
  • ????,C?????????????????,????????data???????????,
    ????
  • data085 date177 date290 date365
  • ????data????????????????????????,?????????
  • data090 date185 date277 date365
  • ????data????,?????????
  • data0 gt data1 gt data2 gt data3

7
9-1 ?????-??
  • ????????????????????(Internal Sorting)??????(Exte
    rnal Sorting)???????????????????????,?????????????
    ????????????,???????????????,????????????????

8
9-1 ?????-????
  • ??????????????,?????????,????
  • ????(Computational Complexity)??Big
    Oh???????,????n??,????O(n Log n)?O(n2)?
  • ??????(Memory Usage)????????????,???????????????
  • ???(Stability)????????????????,???????,??????????
    ??,?????????
  • ?C?????????,??students5????,students6????,????
    ????77,????,?????????,??????????????,????????,????
    ??

9
9-2 ??????
  • 9-2-1 ?????
  • 9-2-2 ?????
  • 9-2-3 ?????
  • 9-2-4 ?????

10
9-2-1 ?????-??
  • ????????,???????????????(Bubble
    Sort),??????????????,?????????????,?????????????,?
    ????????,?????,?????????
  • ???????????????????????????????,??????????????,??
    ?????????????,????????????????,?????????????

11
9-2-1 ?????-??
  • ??????????data??????,??????????????????,????????
    data?????,?????

12
9-2-1 ?????-????
  • ??????????????????????????,??????n,????n-1??????,?
    ??????????,?????(n-1)?(n-2)?(n-3)?2?1,???n(n-1)
    /2???????,???????????????O(n2)?
  • ????????????????,???????????,???????,??????????

13
9-2-2 ?????-??
  • ???????(Selection Sort)?????????????????,?????????
    ?,????????????????????????,???????????????
  • ??????????,?????????????,???????????????????,?????
    ????????????,????????????,????????????,???????????
    ?

14
9-2-2 ?????-??
  • ??????data?????,?????

15
9-2-2 ?????-????
  • ?????????????,??????????n-1?,n??????????,????????n
    -1?n-2?.2?1?0,???n(n-1)/2????,?????????O(n2)?
  • ????????????????,?????????????,????????,??????????
    ???

16
9-2-3 ?????-??
  • ???????(Insertion Sort)????????2?????,????3???????
    ?????????,???????????????,??????????,?????????????
    ??
  • ???????????????,???????temp??,?temp
    ??????????,??????gttemp,????????????,????????temp
    ???????temp ??????????????????????????????

17
9-2-3 ?????-??
  • ??????data?????,?????

18
9-2-3 ?????-??
  • ?????????????????n??,?????????n-1???n-1???,???????
    ??????1?2?3?n-2?n-1????,???n(n-1)/2????,??????O(n
    2)?
  • ?????????????????,???????????,????????,??????????,
    ?????,???????????????

19
9-2-3 ?????-??
  • ??????????????,???????????????????????O(n)????3?4
    ???jkloab,????'o'?,??3????????,????????????,??????
    ?n-1?,?????????O(n)?
  • ????,????????????????,????????????????O(n2)?

20
9-2-4 ?????-??
  • ???????(Shell Sort)?1959?7??Donald L.
    Shell?????????????????????,????????????????,??????
    ???????????????????????????
  • ???????????????????,?????????,?????????,??????????
    ??????,?????????????????,????????1?
  • ?,?????????????,???????????

21
9-2-4 ?????-??
  • ????data????????????????,??h??(h-sequence)?????
    4?2?1???????,????????1??,???????,?????

22
9-2-4 ?????-??1
  • ?????????4,????????4?????????(0,4)?(1,5)?(2,6)?(3
    ,7),?????2???,?????

23
9-2-4 ?????-??2
  • ?????????????????,????
  • (0,4)?(a,s)
  • (1,5)?(g,h)
  • (2,6)?(d,c) ? ?dgtc ?? (c,d)
  • (3,7)?(f,k)

24
9-2-4 ?????-??3
  • ???????????data?,?????????,?????2??????,????????
    (0, 2, 4, 6)?(1, 3, 5, 7),?????4???,?????

25
9-2-4 ?????-??4
  • ?????4???,?????????????,????
  • (0, 2, 4, 6)?(a, c, s, d) ? ?sgtd ??(a, c, d, s)
  • (1, 3, 5, 7)?(g, f, h, k) ? ?ggtf ??(f, g, h, k)
  • ?????????????data,?????

26
9-2-4 ?????-??5
  • ??????????????1????,?????(0,1,2,3,4,5,6,7),???????
    ???????,?????

27
9-2-4 ?????-????
  • ???????????????h????,?????????2???????????,???????
    ???,??????????????????,???h??,????
  • 1,3,7,15,31,63,127, , 2k-1??????n??????O(n3/2)?
  • 1,4,13,40,121, , 2h1??????n??????O(n(Log n)2)?
  • ????????????????,??????????????,???????????,??????
    ?????,???????????????

28
9-3 ????????
  • 9-3-1 ?????
  • 9-3-2 ?????

29
9-3 ????????
  • ????????????????(Divide and Conquer)???,??????????
    ?????????,?????????????,????????????

30
9-3-1 ?????-??
  • ???????(Merge Sort)?????????????(Linear
    List)???????????,?????????????????????,???????????
    ??????????????
  • ????????????????????????????????

31
9-3-1 ?????-????
  • ????A?1,4,5,6,??B?2,3,7,8,???????C??????A?B??
    ???,??A?B???????????????,??????????C,?????

32
9-3-1 ?????-??1
  • ???????????????,?????????????,????A???1???B???2?,?
    ????1???????C,?????A??????2???4,?????

33
9-3-1 ?????-??2
  • ??????2?4,????2?????????????C,?????

34
9-3-1 ?????-??3
  • ??????3?4,???3??????C,?????4?7?5?7?6?7,??3?4?5?6??
    ???????C,?????

35
9-3-1 ?????-??4
  • ??A??????,??B????,?????B????????????C,????????????
    ?C,?????

36
9-3-1 ?????-???
  • ????????????????????????,??????????????,?????????,
    ??????????,????
  • Step 1?n?????????????????n/2?
  • Step 2?????n/4?n/8????1???????
  • Step 3?????????????,????????

37
9-3-1 ?????-????
38
9-3-1 ?????-????
  • ????????????????,??????????????,??????O(n),???????
    ?1/2,????????Log n?????,?????????O(n Log n)?
  • ????????????,????????????????????????????????????,
    ?????????????,?????????????,???????????????

39
9-3-2 ?????-??
  • C.A.R. Hoare??????????(Quick Sort)?????????????,??
    ????????????????????????,????????,??????????????,?
    ?????????
  • ??????????????????,???????????????????,???????????
    ?,?????????????,??????????????
  • ????????????????,??????????????,????????????

40
9-3-2 ?????-????
  • ?????data?????????,?????????????????????????,???
    ????????,??????????,????
  • ??????????1?,????0?
  • ????????????,????????

41
9-3-2 ?????-??1
  • ????????????????,????d?
  • ???????d??????,???????????????,????????e?????
    d?,???left???????????

42
9-3-2 ?????-??2
  • ???????,??????d??b,?????

43
9-3-2 ?????-??3
  • ????????e?b,????????,?????

44
9-3-2 ?????-??4
  • ??????????????,????????????????left?????right,????
    ,??????????????,?????

45
9-3-2 ?????-??5
  • ????????????d?????????3??,????????,????????????
    d?,?????????????d????????????

46
9-3-2 ?????-??6
  • ???????????????,??????,??????c,??????????
  • ???????????????(a,b)??????????????(a,b),?????????
    ?????????(b)?

47
9-3-2 ?????-??7
  • ??????????(f,e,h,g),?????f,?????????,?????(e),??
    ??????,?????

48
9-3-2 ?????-??8
  • ?????(h,g)??????,????????(g)????????,?????

49
9-3-2 ?????-??9
  • ???????????,???????????????,?????

50
9-3-2 ?????-????
51
9-3-2 ?????-????
  • ??????????????????n????,??????,???????????????,???
    ?????Log n?,?????????????n???,????????????,???????
    n/2,??????2n/2???????????,???????????O(n Log n)?
  • ?????????????????n2???,????????O(n2)?????????????,
    ?????????????????????,??????????????,?????????????
    ?,???????????????

52
9-4 ??????
  • 9-4-1 ?????
  • 9-4-2 ????????
  • 9-4-3 ?????

53
9-4-1 ?????-??
  • ?????????????????????,???????????,????????????????
    ?,???????????????????????????????,????
  • MSD?????(Most Significant Digit
    First)????????????,?????????????????
  • LSD?????(Least Significant Digit
    First)????????????,??????????????

54
9-4-1 ?????-??1
  • ????????,????
  • 13,219,532,55,422,164,98,422,334
  • ??????????????????????,???????
  • Step 1????????,???????????????????,???????,?????

55
9-4-1 ?????-??2,3
  • Step 2?????0??????0?9,??????????,?????????????,??
    ??
  • 532,422,422,13,164,334,55,98,219
  • Step 3????????,?????????????????????????,?????

56
9-4-1 ?????-??4,5
  • Step 4?????0?????,??????????,?????????????,????
  • 13,219,422,422,532,334,55,164,98
  • Step 5????????,?????????????????????????,?????

57
9-4-1 ?????-??6
  • Step 6???0?????,???????????,?????????????,???????
    ???,????
  • 13,55,98,164,219,334,422,422,532

58
9-4-1 ?????-????
  • ??????????????????,?n?????,???????????O(n),??????L
    og n???,???????O(n Log n)?
  • ??????????????????????,???????????,?????????,?????
    ????,?????????????

59
9-4-2 ????????-??
  • ???????????????,??????????(Binary Tree
    Sort)?????????????,??????????????????????????????
    ?,?????

60
9-4-2 ????????-????
  • ????????????????????????,??????????????????????,??
    ?????????????????Log n,n?????,??????n??????,??????
    ???O(n Log n)?
  • ??????????????????????????????,???????????????????
    ?,?????????,???????????????????????,??????????????
    ????,??????????,??????????????,????????????????
Write a Comment
User Comments (0)
About PowerShow.com