jeudi 5 octobre 2023

Name of this sorting algo [closed]

from numpy import random
leng = random.randint(1,25)
x = list(random.randint(100, size=leng))
a = sorted(x)

for i in range(int(len(x)/2)):
    mini = min(x[i:len(x)-i])
    maxi = max(x[i:len(x)-i])
    #insert mini to the beginning of the list
    x.pop(x.index(mini))
    x.insert(i,mini)
    #insert maxi to the beginning of reverserd list a.k.a the ending of the unreversed list
    x.reverse()
    x.pop(x.index(maxi))
    x.insert(i, maxi)
    x.reverse()
    
if sorted(x) == a:
    print('I DON\'T KNOW HOW I DID IT BUT IT WORKS')
    print(x)
    print(len(x))`

I am very new to codeing and I recently found out that interviewers often ask about sorting algos and I tried one out myself. I don't know any specifics about it though. I would like to request help in analyzing it. Is it any good? What's it called? How do I calculate time and memory efficieny?

Any help is welcommed!!!




Aucun commentaire:

Enregistrer un commentaire