???? ?????? 09a - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

???? ?????? 09a

Description:

Title: Recitation 3 - Data Structures 07b Subject: Binary Search Tress - AVL Keywords: datastructures avl binarysearchtrees trees recitation Created Date – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 20
Provided by: mitEdu69
Category:
Tags: 09a | heap | sort

less

Transcript and Presenter's Notes

Title: ???? ?????? 09a


1
???? ?????? 09a
  • ?????

????? ?? ????? ?? ????? ?????, ???? ???? ??????
2
?????? Heaps
  • ?? ?????? ???
  • ???? ??????
  • ?? ???? B ???? ?? ???? A ??? Key(A)Key(B)
  • ??????? ???????
  • Find-min
  • Delete-min
  • Decrease-key
  • Insert
  • Merge

3
?????? Heaps
????? ???? (???? max-heap)
15
????? ?????
15
4
4
????? 1
  • ?????? ???? ????? n, ???? ????? min heap ?"?
    ????? ?????? ?? ???? ?????. ???? ???? ???????
    ????? O(nlogn) ????? ??? ???? (worst case)
  • ?????
  • ????? ?????? ????? ?? ???? ??????? ??????
    O(nlogn) ??????
  • ???? ???? ?"????" ??? ????? ?? ?-heap

5
????? 1
n
n
n-1
n-1
n
n-2
n-1
n-2
n
n
n-1
6
????? 1
  • ?? ??? ?????? ???? ????? ???? ???
  • n/2 ??????? ???????? ?????? ????? log(n/2) ?? ???
  • ????? W.C O(nlogn)

7
????? 2
  • ?????? heap ????? ??????? extract-min ?-insert
    ???? f(n) amortized, ???? ????? ????? ???? ?????
    n ???? O(nf(n))
  • ?????
  • ???? n ?????? ????? ???? O(nf(n))
  • ???? n ?????? ????? ??????? ???? O(nf(n))
  • ??"? O(nf(n))
  • ???????? ???? ?? ???? heap-sort
  • ?????? ????? ?? ???? n ????? ??? O(nlogn)

8
????? 3 Median Heap
  • ???? ???? ?????? ????? ???????
  • insert ???? O(logn)
  • extract-median ???? O(logn)
  • find-median ???? O(1)

8
9
????? 3 - ?????
Max-heap
Min-heap

?????? ?????? (?? ??????)
?????? ??????? (???????)
10
????? 3 - ?????
Max-heap
Min-heap
  • ????? ?-max-heap ?-min-heap
  • n/2 ?????? ??????? ????? ?????? ?-max-heap
  • ???? ?????? ?-min-heap
  • ?????? ???? ???? ????? ?? ??? ???

Max-Heap
Min-Heap
2
4
5
7
8
12
14
15
20
11
????? 3 - ?????
  • Find-median
  • If (size(minheap)gtsize(maxheap))
  • return getmin(minheap)
  • Else
  • return getmax(maxheap)
  • Insert(x)
  • If (xltgetmin(minheap))
  • Insert(maxheap,x)
  • Else
  • Insert(minheap,x)
  • If (abs(size(minheap)-size(maxheap))gt1)
  • Balance heaps (move root from bigger heap to
    smaller heap)
  • Extract-Median
  • Extract median from the max-heap or min-heap

O(1)
O(logn)
O(logn)
12
???? 1
  • ?????? ???????, ?????? ???? ?????
  • ?. ?????.
  • ?. ????? ??? ????? .
  • ?. ????? ??? ?????
  • ?. ???? ?????? ??????? ?????.
  • ?. ?? ??? ???"?.

13
????? 1
  • ?. ?????? ???? ????? ?? ???? ?? ????? (???? ?? ??
    ?? ?? ???? ?????? ??? ?? ?? ????) ????? ?? ?????
    ???? ????? (?? ??? ?????? ?????? ????? ??????
    ?????). ???????? ???? ?????? ????? ???????.

14
????????? 2
  • ??? ???? ?????? ???? ???? ??? ??????

????? ??. ????? ????? ?-i ???? ?????? ?-2i1
?-2i (??? ????) ??? i.
15
???? 3
16
????? 3
  • ?. ??? ?????
  • ???? ?? ?????? ??? O(lg n). ??? ????? ??? O(n lg
    n).
  • ??? ????? ???? ?? ????? ??? O(lg n) ??? O(n)
    ???? ??? ????? ??? ?? O(n lg n)

17
???? 4
18
????? 4
  • ?. ?????? ????? ?????? ??? ????? ?? Build-Heap.

19
????
Write a Comment
User Comments (0)
About PowerShow.com