Given a list of input elements or objects, sorting arranges the elements either in ascending order or descending order and produces a sorted list as the output. The elements to be sorted need to be stored in a data structure for manipulation. Among the various data structures usually used for sorting are: arrays, linked list, heap, etc. Sorting can either be internal or external. Internal sorting is the type of sorting that requires all the elements to be sorted to be in the main memory throughout the sorting process while an external sorting allows part of the elements to be sorted to be outside the main memory during the sorting process [6]. Examples of internal sorting algorithms are: Insertion Sort, Selection Sort, Bubble Sort, Shellsort, etc. There is no known “best” way to sort; there are many best methods, depending on what is to be sorted, on what machine and for what purpose [3]. What needs to be done is to learn the characteristics of each sorting algorithm and make a good choice for a particular problem.
Shellsort
Shellsort proposed by Donald L. Shell improves on Insertion Sort by reducing the number of comparisons made. It sorts an array A with n elements by dividing it into subsequences and sorts the subsequences. Any sequence s1, s2, s3,..., sn can be used for the subsequences in as much as the last subsequence is 1. In the first pass, elements that are s1 distance apart are sorted using insertion sort starting from the first on the list. For the second pass, elements that are s2 distance apart are sorted using Insertion sort also by starting from the first. This continues until elements that are 1 distance apart are sorted using straight Insertion Sort. Integer division is carried out on s1 to get s2, integer division also carried out on s2 to get s3 and so on. Shellsort is also called Diminishing Increment Sort. The elements to be sorted are assumed to be stored in an array.
Consider the worst-case problem of sorting the following elements in ascending
ให้รายการของข้อมูลองค์ประกอบหรือวัตถุ การจัดองค์ประกอบ ทั้งในน้อยไปหามากหรือน้อยสั่งและผลิตรายการที่เรียงลําดับตามผลผลิต องค์ประกอบที่จะถูกจัดเรียงต้องถูกเก็บไว้ในโครงสร้างของข้อมูลเพื่อการจัดการ โครงสร้างของข้อมูลต่างๆมักจะใช้สำหรับการเรียงลำดับ : อาร์เรย์ลิงค์รายการ , กอง , ฯลฯ การเรียงลำดับสามารถเป็นได้ทั้งภายในหรือภายนอกการจัดเรียงภายในเป็นชนิดของการแยกที่ต้องมีองค์ประกอบทั้งหมดจะถูกจัดเรียงให้อยู่ในหน่วยความจําหลักตลอดกระบวนการในขณะที่การเรียงลำดับการเรียงลำดับภายนอกช่วยให้ส่วนหนึ่งขององค์ประกอบที่จะถูกจัดเรียงเป็นภายนอกหน่วยความจำหลักในการเรียงลำดับกระบวนการ [ 6 ] ตัวอย่างภายในขั้นตอนวิธีการเรียงลำดับ : การแทรกการจัดเรียงฟองเรียง , เรียง , shellsort ฯลฯไม่มีรู้จัก " วิธีที่ดีที่สุด " เพื่อจัดเรียง ; มีหลายวิธีที่ดีที่สุดขึ้นอยู่กับสิ่งที่จะถูกเรียงบนเครื่องอะไร และเพื่ออะไร [ 3 ] สิ่งที่ต้องทำคือการ เรียนรู้ลักษณะของแต่ละขั้นตอนวิธีการเรียงลำดับและการทำให้เป็นทางเลือกที่ดีสำหรับปัญหาเฉพาะ shellsort
shellsort เสนอโดย Donald L . เปลือกช่วยในการเรียงลำดับแบบแทรก โดยการลดจำนวนของการทำมันประเภทอาร์เรย์เป็นองค์ประกอบด้วย โดยแบ่งออกเป็น subsequences และประเภทที่ subsequences . ใด ๆลำดับ S1 , S2 , S3 , . . . , ดีบุกสามารถใช้สำหรับ subsequences ในเท่าที่ตาม สุดท้ายคือ 1 . ในผ่านแรก องค์ประกอบที่มีระยะทางห่างกัน จะถูกจัดเรียงแทรก S1 ใช้เรียงเริ่มต้นจากครั้งแรกในรายการ สำหรับผ่านสององค์ประกอบที่มีระยะทางห่างกัน จะใช้ใส่ S2 เรียงเรียงโดยเริ่มจากคนแรก นี้อย่างต่อเนื่องจนกระทั่งองค์ประกอบที่ 1 ระยะทางห่างกัน จะถูกจัดเรียงจัดเรียงแทรกโดยตรง การหารจำนวนเต็มจะดําเนินการในการรับ S1 S2 การหารจำนวนเต็มยังดำเนินการใน S2 S3 ที่จะได้รับและอื่น ๆ shellsort ที่เรียกว่า diminishing การจัดเรียงองค์ประกอบที่จะถูกจัดเรียงจะถือว่าถูกเก็บไว้ใน array .
พิจารณาปัญหาเนื่องของการแยกองค์ประกอบต่อไปนี้จากน้อยไปมาก
การแปล กรุณารอสักครู่..
