do O(1) sorting algorithm exist

Правка en1, от 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

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский swarya 2025-05-27 09:16:25 233
en2 Английский swarya 2025-05-27 08:56:39 86
en1 Английский swarya 2025-05-27 08:17:18 550 Initial revision (published)