Lesson 12 of 23

Searching மற்றும் Bubble SortSearching and Bubble Sort

11 min 30 XP

Bubble sort அடுத்தடுத்த இரண்டு உறுப்புகளை ஒப்பிட்டு தவறான வரிசையில் இருந்தால் swap செய்யும். ஒவ்வொரு சுற்றிலும் பெரியது கடைசிக்குச் செல்லும். Time complexity O(n²).

Bubble sort compares neighbours and swaps them when they're out of order; each pass bubbles the largest value to the end. Time complexity: O(n²).

Example: edit me and press Run

Output Loading C (first time takes a few seconds)
Press Run to see the result here.

வரிசைப்படுத்திய array-ல் binary search: நடுவை ஒப்பிட்டு பாதியைத் தூக்கி எறியும். O(log n), 10 லட்சம் உறுப்புகளிலும் 20 படிகளில் கண்டுபிடிக்கும்!

Binary search on a sorted array compares the middle element and discards half each time: O(log n), so even a million elements take about 20 steps!

Example: edit me and press Run

Output Loading C (first time takes a few seconds)
Press Run to see the result here.

Challenge

+30 XP

n மற்றும் n எண்களைப் படித்து, bubble sort மூலம் இறங்கு வரிசையில் (பெரியது முதல்) space விட்டு print செய்யுங்கள். Input: 5 3 8 1 9 4 Output: 9 8 4 3 1

Read n and n numbers, sort them in descending order with bubble sort and print them separated by spaces. Input: 5 3 8 1 9 4 Output: 9 8 4 3 1

Output Loading C (first time takes a few seconds)
Press Run to see the result here.