Write a python code for a sorting algorithm
- User
Write a python code for a sorting algorithm
Assistant
Here's an implementation of the basic selection sort algorithm in Python:
pythondef selection_sort(arr): n = len(arr) for I in range(n): # Find the minimum element in remaining unsorted array min_index = i for j in range(i+1, n): if arr[j] < arr[min_index]: min_index = j # Swap the found minimum element with the first element arr[i], arr[min_index] = arr[min_index], arr[i] # Driver code to test above arr = [64, 25, 12, 22, 11] selection_sort(arr) print("Sorted array is:", arr)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.