Skip to content

Instantly share code, notes, and snippets.

View sksoumik's full-sized avatar

Sadman Kabir Soumik sksoumik

View GitHub Profile
# Merge Sort | Time Complexity O(NlogN)
def mergeSort(alist):
print("Splitting ", alist)
if len(alist) > 1:
mid = len(alist) // 2
lefthalf = alist[:mid]
righthalf = alist[mid:]
mergeSort(lefthalf)
print("LeftHalf ", lefthalf)
# Fibonacci series using recursion
def fibonacci(n):
if n == 0:
return n
elif n == 1:
return n
else:
return fibonacci(n - 1) + fibonacci(n - 2)
n = int(input('Enter the number of n: '))
def fact(n):
# Base Case
if n == 1:
return 1
# Recursive case
else:
return n * fact(n - 1)
import java.io.*;
class MySingletonClass
{
static MySingletonClass instance = null;
public int x = 10;
// private constructor can't be accessed outside the class
private MySingletonClass() { }
# Insertion Sort Time complexity: Worst Case & Average Case: O(n**n)
# Insertion Sort Time complexity: Best Case: O(n)
def insertionSort(arr):
# Traverse through 1 to len(arr)
for i in range(1, len(arr)):
key = arr[i]