CODEPROGRAMMER Telegram 2218
đź–Ą Unraveling the Magic of Sorting: A Python Guide for Novices

â–ŞBubble Sort

def bubble_sort(list):
for i in range(len(list)):
for j in range(len(list) - 1):
if list[j] > list[j + 1]:
list[j], list[j + 1] = list[j + 1], list[j] # swap
return list


â–ŞSelection Sort

def selection_sort(list):
for i in range(len(list)):
min_index = i
for j in range(i + 1, len(list)):
if list[min_index] > list[j]:
min_index = j
list[i], list[min_index] = list[min_index], list[i] # swap
return list


â–ŞInsertion Sort

def insertion_sort(list):
for i in range(1, len(list)):
key = list[i]
j = i - 1
while j >=0 and key < list[j] :
list[j+1] = list[j]
j -= 1
list[j+1] = key
return list

â–ŞQuick Sort

def partition(array, low, high):
i = (low-1)
pivot = array[high]

for j in range(low, high):
if array[j] <= pivot:
i = i+1
array[i], array[j] = array[j], array[i]
array[i+1], array[high] = array[high], array[i+1]
return (i+1)

def quick_sort(array, low, high):
if len(array) == 1:
return array
if low < high:
partition_index = partition(array, low, high)
quick_sort(array, low, partition_index-1)
quick_sort(array, partition_index+1, high)

https://www.tgoop.com/CodeProgrammer
👍6❤2



tgoop.com/CodeProgrammer/2218
Create:
Last Update:

đź–Ą Unraveling the Magic of Sorting: A Python Guide for Novices

â–ŞBubble Sort

def bubble_sort(list):
for i in range(len(list)):
for j in range(len(list) - 1):
if list[j] > list[j + 1]:
list[j], list[j + 1] = list[j + 1], list[j] # swap
return list


â–ŞSelection Sort

def selection_sort(list):
for i in range(len(list)):
min_index = i
for j in range(i + 1, len(list)):
if list[min_index] > list[j]:
min_index = j
list[i], list[min_index] = list[min_index], list[i] # swap
return list


â–ŞInsertion Sort

def insertion_sort(list):
for i in range(1, len(list)):
key = list[i]
j = i - 1
while j >=0 and key < list[j] :
list[j+1] = list[j]
j -= 1
list[j+1] = key
return list

â–ŞQuick Sort

def partition(array, low, high):
i = (low-1)
pivot = array[high]

for j in range(low, high):
if array[j] <= pivot:
i = i+1
array[i], array[j] = array[j], array[i]
array[i+1], array[high] = array[high], array[i+1]
return (i+1)

def quick_sort(array, low, high):
if len(array) == 1:
return array
if low < high:
partition_index = partition(array, low, high)
quick_sort(array, low, partition_index-1)
quick_sort(array, partition_index+1, high)

https://www.tgoop.com/CodeProgrammer

BY Python | Machine Learning | Coding | R


Share with your friend now:
tgoop.com/CodeProgrammer/2218

View MORE
Open in Telegram


Telegram News

Date: |

While some crypto traders move toward screaming as a coping mechanism, many mental health experts have argued that “scream therapy” is pseudoscience. Scientific research or no, it obviously feels good. Telegram Channels requirements & features How to Create a Private or Public Channel on Telegram? Telegram iOS app: In the “Chats” tab, click the new message icon in the right upper corner. Select “New Channel.” In the next window, choose the type of your channel. If you want your channel to be public, you need to develop a link for it. In the screenshot below, it’s ”/catmarketing.” If your selected link is unavailable, you’ll need to suggest another option.
from us


Telegram Python | Machine Learning | Coding | R
FROM American