diff --git a/Sorting/Bubble Sort.cpp b/Sorting/Bubble Sort.cpp index f1a8701a9..7bc5c0be8 100644 --- a/Sorting/Bubble Sort.cpp +++ b/Sorting/Bubble Sort.cpp @@ -31,7 +31,7 @@ int main() if(numbers[j]>numbers[j+1]) { swap_check=1; - swap(numbers[j], numbers[j+1]); //swap yer değiştirme demektir. Yani j. sayi, j+1. sayıdan büyükse yer değiştir anlamındadır. + swap(numbers[j], numbers[j+1]);// by changing swap location. I mean, j. If the number is greater than j + 1, then it means the location. } } if(swap_check == 0) @@ -55,34 +55,33 @@ int main() return 0; } -/* -Bubble sort algoritmasının çalışma prensibi: +/*The working principle of the Bubble sort algorithm: -Bubble sort algoritmasının türkçesi kabarcık sıralama algoritmasıdır. Kabarcık denmesinin en önemli sebebi bu algoritmada en büyük sayının en sona atılmasıdır. -Tüm mantığını bunun üzerinedir. -Her iterasyonda en büyük sayı sona atılır ve iterasyonlar tamamlandığında sıralama gerçekleşmiş olur. +Bubble sort algorithm is the bubble sorting algorithm. The most important reason for calling the bubble is that the largest number is thrown at the end of this algorithm. +This is all about the logic. +In each iteration, the largest number is expired and when iterations are completed, the sorting takes place. -Swap Ne Demektir? +What is Swap? -Yazılımda Swap demek iki değişkenin yer değiştirmesi demektir. -Bu işlem için ek bir değişkene ihtiyaç duyulur. x = 5, y = 10 olsun. -Biz istiyoruz ki x = 10, y = 5 olsun. İşte bunu yapmak için en bir değişken oluştururuz. +Swap in the software means that two variables are displaced. +An additional variable is required for this operation. x = 5, y = 10. +We want x = 10, y = 5. Here we create the most variable to do it. int z; z = x; x = y; y = z; -Yukarıdaki işlem tipik bir yer değiştirme işlemidir. -x değerine y’yi atayınca x’in eski değeri kaybolur. -Bu yüzden biz z diye bir değişken oluşturup ilk başka x değerini orada sakladık, en son olarak da y’ye atadık. +The above process is a typical displacement process. +When x assigns the value to x, the old value of x is lost. +That's why we created a variable z to create the first value of the value of x, and finally, we have assigned to y. -Bubble Sort Algoritma Analizi (Best Case – Worst Case – Avarage Case) En iyi Durum – En Kötü Durum: - -Bubble Sort En Kötü Durum (Worst Case) Performansı O(n²) şeklindedir. Neden? Çünkü Big O Notasyonu yazımızdan hatırlarsanız iç içe döngülerde algoritma karmaşıklığı hesaplarken döngülerin çarpımını alıyorduk. -n * (n – 1) çarpımı üzerinden bize yine O(n²) performansı gelir. En kötü durumda döngünün tüm adımları gerçekleşecektir. -Bubble Sort Ortalama Durum (Avarage Case) Performansı. Bubble Sort optimal bir algoritma değildir. -ortalama durumda da O(n²) performansı alınmaktadır. -Bubble Sort En iyi Durum (Best Case) Performansı. O(n) şeklindedir. -Ancak yukarıda paylaştığımız kodda en iyi durumu elde edemezsiniz. İyileştirilmiş bubble sort algoritması üzerinde bu durum gerçekleşir. Hemen aşağıda bulunmakta. -*/ +Bubble Sort Algorithm Analysis (Best Case - Worst Case - Average Case) + +Bubble Sort Worst Case Performance is O (n²). Why is that? Because if you remember Big O Notation, we were calculating the complexity of the algorithms in the nested loops. +The n * (n - 1) product gives us O (n²) performance. In the worst case all the steps of the cycle will occur. +Bubble Sort (Avarage Case) Performance. Bubble Sort is not an optimal algorithm. +in average, O (n²) performance is taken. +Bubble Sort Best Case Performance. O (n). +However, you can't get the best status in the code we shared above. This happens on the optimized bubble sort algorithm. It's right down there. +* /