This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#libraraies | |
from pytube import * | |
import os | |
from tkinter import * | |
from tkinter.filedialog import * | |
from tkinter.messagebox import * | |
from threading import * | |
file_size = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |