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

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

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

Bubble Sort: Neighbours, Passes, and When to Stop

Trace both scan directions, understand the sorted flag, and prepare for Divide and Conquer.

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

Compare two neighbours

Goal: Explain what one comparison can fix.

Start with [5,2,4,6,1]. We want the same five values in ascending order. Compare the first neighbours, 5 and 2. Since 5 is larger, swap them: [2,5,4,6,1].

Compare the next neighbours, 5 and 4. Swap again: [2,4,5,6,1]. Comparing 5 and 6 needs no swap. Comparing 6 and 1 does need a swap, giving [2,4,5,1,6].

One pass means a complete scan of the current unsorted part. This left-to-right pass moved its largest value, 6, to the end. The entire array is not sorted yet: 1 is still after 5.

Quick check · predict, then try

After one left-to-right pass

Which value is guaranteed to be in its final position?

Choose your prediction

Remember: An ascending pair is in order when the left value is no larger.

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

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

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

PDF46–56 inspected visually; channel message119 corrects PDF54 to Insertion Sort. The forward conceptual trace and backward code are different variants. PDF48 marks 6>1 false although the shown swap and arithmetic require true. A swap does not prove the final array is unsorted; it only prevents the no-swap certificate for that pass. PDF52 draws an extra phase after termination; it is not a body execution. Average case requires a distribution. No universal ranking of sorting algorithms is adopted.

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