Chapter 02 Selection Sort

Chapter 02

In this chapter, you’ll learn about arrays and linked lists, two fundamental data structures.

You’ll learn how they store data, how their performance differs, and when to use each one.

Then, you’ll learn your first sorting algorithm : Selection Sort.


1. Arrays & Linked Lists

قبل ما نبدأ في الـSelection Sort ، لازم نفهم الفرق بين الـArray والـLinked List .

الاتنين بيستخدموا لتخزين مجموعة من العناصر، لكن طريقة تخزينهم في الذاكرة مختلفة ،

وده بيأثر على الـPerformance بتاع العمليات اللي بنعملها عليهم.


Array

الـArray بتخزن العناصر في أماكن متجاورة في الذاكرة.

مثلاً:

[10] [20] [30] [40] [50]
  0    1    2    3    4

كل عنصر عنده Index، والـIndex بيسمحلي أوصل للعنصر مباشرة.

مثلاً:

int[]numbers= {10,20,30,40,50 };
Console.WriteLine(numbers[3]);

Output : 40

أنا عارف إن العنصر موجود في Index 3، فمش محتاج أعدي على العناصر اللي قبله.