do O(1) sorting algorithm exist

Revision en1, by swarya, 2025-05-27 08:17:18

took a array of 2 elements let's suppose [3,1]

now you have to sort it in ascending order

import random

arr = [2, 3] if random.randint(0, 1) == 1: # 50% chance to swap (1 out of 0 or 1) arr[0], arr[1] = arr[1], arr[0] print(arr) it will swap elements in O(1)

and it's sorting so, it's best case is O(1) so, worst case is O(n!)

so actually their is a chance that in first iteration

we will get sorted array

but chances and probablity are 50%

so can we say that O(1) sorting algorithm exist

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English swarya 2025-05-27 09:16:25 233
en2 English swarya 2025-05-27 08:56:39 86
en1 English swarya 2025-05-27 08:17:18 550 Initial revision (published)