Skip to content

Instantly share code, notes, and snippets.

View harendra21's full-sized avatar
🏠
Working from home

Harendra Kumar Kanojiya harendra21

🏠
Working from home
View GitHub Profile
def binary_search(mylist,low,k,key):
high = k - 1
mid = (low + high)//2
if mylist[mid]==key:
return mid
elif key > mylist[mid]:
return binary_search(mylist,mid + 1,k ,key)
else:
return binary_search(mylist,0,mid, key)
#libraraies
from pytube import *
import os
from tkinter import *
from tkinter.filedialog import *
from tkinter.messagebox import *
from threading import *
file_size = 0
def selection_sort (num_list):
for items in range(len(num_list)-1,0,-1):
max_pos = 0
for item in range(1,items+1):
if num_list[max_pos] < num_list[item]:
max_pos = item
temp = num_list[max_pos]
num_list[max_pos] = num_list[item]
num_list[item] = temp
return num_list
def bubble_sort(num_list):
for items in range(len(num_list)-1,0,-1):
for item in range(items):
if num_list[item] > num_list[item+1]:
# Swap
temp = num_list[item]
num_list[item] = num_list[item+1]
num_list[item+1] = temp
return num_list
# Python program for implementation of Bubble Sort
def bubbleSort(arr):
n = len(arr)
# Traverse through all array elements
for i in range(n):
# Last i elements are already in place
for j in range(0, n-i-1):
def insertion_sort(num_list):
for num in range(1,len(num_list)):
cur_val = num_list[num]
pos = num
while pos > 0 and num_list[pos-1] > cur_val :
num_list[pos] = num_list[pos-1]
pos = pos -1
num_list[pos]= cur_val
return num_list
def insertion(s):
for i in range(0,len(s)-1):
if s[i]>s[i+1]:
s[i],s[i+1]=s[i+1],s[i]
for j in range(i,0,-1):
if s[j]<s[j-1]:
s[j],s[j-1]=s[j-1],s[j]
print(s)
insertion([5,2,1,9,0,4,6])
def insertionSort(alist):
for i in range(1,len(alist)):
#element to be compared
current = alist[i]
#comparing the current element with the sorted portion and swapping
while i>0 and alist[i-1]>current:
alist[i] = alist[i-1]
algorithm quicksort(A, lo, hi) is
if lo < hi then
p := partition(A, lo, hi)
quicksort(A, lo, p - 1)
quicksort(A, p + 1, hi)
algorithm partition(A, lo, hi) is
pivot := A[hi]
i := lo
for j := lo to hi do
def partition(a,l,h):
pivot = a[l]
i = l
j=h
while i<j:
while a[i]<=pivot and i<h: i+=1
while a[j]>pivot and j>l: j-=1
if i<j: a[i],a[j]=a[j],a[i]
a[j],a[l]=a[l],a[j]