gpt-4o-2024-11-20· OpenAI
LMArena Human Preference 140K
write a fast sort
- User
write a fast sort
- Assistant
Sure! Here's an implementation of the QuickSort algorithm in Python, which is one of the fastest sorting algorithms in practice for general-purpose use:
def quicksort(arr): if len(arr) <= 1: return arr # Base case: already sorted else: pivot = arr[len(arr) // 2] # Choose the middle element as the pivot left = [x for x in arr if x < pivot] # Elements less than the pivot middle = [x for x in arr if x == pivot] # Elements equal to the pivot right = [x for x in arr if x > pivot] # Elements greater than the pivot return quicksort(left) + middle + quicksort(right) # Recursively sort and combine # Example usage: arr = [3, 6, 8, 10, 1, 2, 1] sorted_arr = quicksort(arr) print(sorted_arr)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.