All links of one day
in a single page.
<Previous day - Next day>

rss_feedDaily RSS Feed
floral_left The Daily Shaarli floral_right
——————————— February 6, 2022 - Sunday 06, February 2022 ———————————
algo -
thumbnail

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):

        # traverse the array from 0 to n-i-1
        # Swap if the element found is greater
        # than the next element
        if arr[j] > arr[j+1] :
            arr[j], arr[j+1] = arr[j+1], arr[j
algo - search -
def binary_search(l, item):
    first = 0
    last = len(l)-1
    found = False

    while first<=last and not found:
        midpoint = round((first + last)/2)
        if l[midpoint] == item:
            found = True
        else:
            if item < l[midpoint]:
                last = midpoint-1
            else:
                first = midpoint+1

    return found

input = [0, 1, 2, 8, 13, 17, 19, 32, 42,]

print(binary_search(input, 3))   # found: False
print(binary_search(input, 13))  # fount: True
algo - sort - recursiv -
from random import randrange

input = [10, 5, 2, 3, 7, 0, 9, 12]

def quicksort(arr):
    if len(arr) < 2:
        return arr
    else:
        rand = randrange(0, len(arr))  # grab a random index
        pivot = arr.pop(rand)
        less = [i for i in arr if i <= pivot]
        greater = [i for i in arr if i > pivot]
        return quicksort(less) + [pivot] + quicksort(greater)

print("sorted:  ", quicksort(input))
-