العودة إلى الدراسة

المحاضرة 7 من 10

40 دقيقة تقريبًا

Merge Sort: Small Sorted Parts Become One Sorted Array

Split the original eight values, merge them with two counters, and explain the work at each recursion level.

تصفّح الدفتر
Step 1 of 7 · Follow the example

Start with two already sorted lists

Goal: Choose the next output from the two front values.

Take the small example [4,3,5,2]. After sorting each pair, we have [3,4] and [2,5]. Compare their first unused values:

CompareAppendValues still unused
3 and 22[3,4] and [5]
3 and 53[4] and [5]
4 and 54[] and [5]
Left list is emptycopy 5[] and []

The result is [2,3,4,5]. There were 3 value comparisons during this merge, plus copying. Once a list is exhausted, copy the other list's remaining values; do not compare them with nonexistent elements.

Quick check · predict, then try

Choose the next merged value

The unused parts are [3,4] and [2,5]. Which value comes next?

Choose your prediction

Remember: Merging requires sorted inputs; it does not sort arbitrary halves by magic.

موضعك محفوظ تلقائيًا
مصادر الدرس وملاحظات المراجعة

يعتمد ترتيب الموضوعات والأمثلة على صفحات 57–65 من الدفتر. نسبة الدفتر إلى الدكتور غير مؤكدة. الشرح والتفاعلات التعليمية صياغة مساعدة، وليست نقلًا حرفيًا.

شرح تكميلي بالإنجليزية والعربية يتبع أمثلة وترتيب محاضرة الدفتر7 في صفحات PDF57–65. المصدر محفوظ وغير مؤكد النسبة لدكتور الطالب. الكود التكميلي وتصحيحات الادعاءات مفحوصة بصورة منفصلة؛ ليست اقتباسات من الأستاذ.

PDF57–65 inspected visually. The source uses “merge technique” for the general divide/conquer/combine framework; the lesson distinguishes that framework from the merge operation. PDF63–64 claims sorted runs must always be divided and sorted inputs need no comparisons; plain Merge Sort still compares/copies, while an explicitly checked adaptive variant may skip work. “No best case” is replaced by the same Θ(n log n) order for all cases of this implementation. Odd splits have equivalent asymptotic order, not necessarily identical exact counts. Code is a checked supplementary implementation, not a transcription of an unavailable linked resource.

تصفّح صفحات هذا الدرس من الدفتر
خطوة صغيرة. فهم أعمق.ألجولاب · دفتر شخصي للدراسة