Skip to content

Instantly share code, notes, and snippets.

View vividhsv's full-sized avatar

Vividh S Viswanatha vividhsv

View GitHub Profile
@vividhsv
vividhsv / bubble_sort.py
Created December 21, 2016 21:39
Bubble Sort
def bubble_sort(arr):
is_sorted = False
while not is_sorted:
is_sorted = True
for i in range(0, len(arr) -1):
if arr[i] > arr[i+1]:
is_sorted = False
arr[i], arr[i+1] = arr[i+1], arr[i]
return arr
@vividhsv
vividhsv / linear_search.py
Created December 21, 2016 20:48
Linear Search
def linear_search(item, list):
for i in list:
if i == item:
return True
return False
print(linear_search(4, [1, 2, 4, 4, 5]))
@vividhsv
vividhsv / binary_search.py
Last active December 21, 2016 20:22
Binary Search The binary search is used to find an item in an ORDERED list.
def binary_search(item, arr):
def _binary_search(item, first, last, arr):
if last < first:
return False
if last == first:
return arr[last] == item
mid = (first + last) // 2
if arr[mid] > item:
last = mid
import sys
import locust
import gevent
from gevent.socket import socket
from gevent.queue import Queue
import time
from utils.bootstrap import test_conf as TEST_CONFIG
import insight