Skip to content

Instantly share code, notes, and snippets.

@tamim
tamim / heap_example.py
Created June 1, 2018 15:35
Shows how can we use unit tests while implementing heap related functions in Python
def left(i):
return 2 * i
def test_left():
pass
def right(i):
return 2 * i + 1
@tamim
tamim / running_median.py
Last active September 16, 2018 01:51
implementation of max heap and min heap to solve running median problem
import sys
def left(i):
return i * 2
def right(i):
return i * 2 + 1
@tamim
tamim / allsubsets.py
Last active December 17, 2018 14:29
Python code to generate all subsets of a set.
"""
Generate all subsets of a set using recursion
"""
def subsets1(S):
if S == []:
return [[]]
result = [[]]
n = len(S)
visited = [False] * n
/***************************************************************************
Sort a struct array in C using qsort function
****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student {
char name[30];
@tamim
tamim / search_comparison.c
Last active February 15, 2019 03:26
A program to see the performance difference between linear search and binary search.
#include <stdio.h>
#include <time.h>
int linear_search(int ara[], int n, int key)
{
for (int i = 0; i < n; i++) {
if (ara[i] == key) {
return i;
}
}