Tài liệu Selection-Sort and Insertion-Sort

Thảo luận trong 'Thiết Kế Web' bắt đầu bởi Thúy Viết Bài, 5/12/13.

  1. Thúy Viết Bài

    Thành viên vàng

    Bài viết:
    198,891
    Được thích:
    173
    Điểm thành tích:
    0
    Xu:
    0Xu
    Recall the PriorityQueueSort scheme introduced in Section 8.1.4. We are
    given an unsorted sequence S containing n elements, which we sort using a priority
    queue P in two phases. In Phase 1 we insert all the elements into P and in Phase 2
    we repeatedly remove the elements from P using the removeMin() method.
    Selection-Sort
    If we implement P with an unsorted list, then Phase 1 of PriorityQueueSort
    takes O(n) time, for we can insert each element in O(1) time. In Phase 2, the
    running time of each removeMin operation is proportional to the size of P.
    Thus, the bottleneck computation is the repeated selection of the minimum
    element in Phase 2. For this reason, this algorithm is better known as selectionsort.
    (See Figure 8.1.)
    As noted above, the bottleneck is in Phase 2 where we repeatedly remove an entry
    with smallest key from the priority queue P. The size of P starts at n and
    incrementally decreases with each removeMin until it becomes 0. Thus, the first
    removeMin operation takes time O(n), the second one takes time O(n ư 1), and
    so on, until the last (nth) operation takes time O(1). Therefore, the total time
    needed for the second phase is
     

    Các file đính kèm:

Đang tải...
Chủ đề tương tự
  1. Thúy Viết Bài
    Trả lời:
    0
    Xem:
    829