1 / 10

Sorting

Sorting. สาขาวิชาคอมพิวเตอร์และเทคโนโลยี อ.เลาขวัญ งามประสิทธิ์. ประเภทของการเรียงลำดับข้อมูล. Internal Sort แต่ละขั้นตอนการทำงานที่เกิดขึ้น หมายถึงเกิดขึ้นภายใน main memory External Sort

ashley
Télécharger la présentation

Sorting

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Sorting สาขาวิชาคอมพิวเตอร์และเทคโนโลยี อ.เลาขวัญ งามประสิทธิ์

  2. ประเภทของการเรียงลำดับข้อมูลประเภทของการเรียงลำดับข้อมูล • Internal Sort แต่ละขั้นตอนการทำงานที่เกิดขึ้น หมายถึงเกิดขึ้นภายใน main memory • External Sort กรณีข้อมูลมีจำนวนมาก ไม่สามารถเก็บไว้ภายใน main memory ได้หมด ดังนั้นจะต้องมีข้อมูลบางส่วนเก็บไว้ที่ secondary storage

  3. Internal Sort • Bubble Sort : O(n2) • Selection Sort : O(n2) • Insertion Sort : O(n2) • Merge Sort : O(n log n) • Quick Sort : O(n log n)

  4. Bubble Sort • เปรียบเทียบข้อมูลเป็นคู่ที่อยู่ติดกันในแต่ละรอบการทำงาน • หากอยู่ผิดลำดับให้สลับตำแหน่งกัน

  5. Selection Sort • จัดเป็นวิธีหนึ่งที่มีอยู่ในสัญชาตญาณการจัดเรียงโดยธรรมชาติของมนุษย์ • ค้นหาตัวเลขที่มีค่าน้อย/มากที่สุดตั้งแต่ตัวแรกไปจนถึงตัวสุดท้าย • สลับตำแหน่งตัวเลขที่มีค่าน้อย/มากที่สุด • ใช้จำนวนรอบการทำงานมาก ไม่เหมาะกับการเรียงข้อมูลที่มีปริมาณมาก

  6. Insertion Sort • เทคนิคการเรียงไพ่ด้วยมือ • นำ selection sort มาปรับปรุง • แทนที่จะอ่านข้อมูลทุกตัวเพื่อหาค่าน้อย/มากที่สุด ก็จะเปรียบเทียบค่ากับตำแหน่งถัดไปแทน • สลับตำแหน่งให้อยู่ในตำแหน่งที่เหมาะสม

  7. Quick Sort • เป็น divide-and-conquer algorithm (Dijkstra’s algorithm ตัวอย่างของ greedy algorithm) • มีการเลือกข้อมูลตัวหนึ่งเรียกว่า Pivot ที่ใช้เป็นตัวแบ่งแยกชุดข้อมูลที่เรามีออกเป็นส่วน คือ ข้อมูลที่มีค่าน้อยกว่า Pivot และข้อมูลที่มีค่ามากกว่า Pivot • เรียงข้อมูลแต่ละส่วนย่อยๆ

  8. Quick Sort: Picking the pivot • Median-of-Three Partitioning 8, 1, 4, 9, 7, 3, 5, 2, 6, 0 ข้อมูลซ้ายสุด คือ เลข 8 ข้อมูลขวาสุด คือ เลข 0 ข้อมูลตรงกลาง คือ ตำแหน่งที่ (10+1)div 2 คือ เลข 7 ดังนั้น Pivot คือ 7 8, 1, 4, 9, 7, 3, 5, 2, 6, 0

  9. Merge Sort • เป็น divide-and-conquer algorithm เช่นเดียวกับ quick sort • แบ่งข้อมูลออกเป็นส่วนๆ แล้วจัดเรียงข้อมูลส่วนย่อยๆนั้น

  10. xSortLabSimulation • http://www.cs.iupui.edu/~aharris/n301/alg/tmcm-java-labs/labs/xSortLabLab.html • http://www.mwit.ac.th/~jeab/it40206.php

More Related