Skip to content

Instantly share code, notes, and snippets.

View sujayy1983's full-sized avatar

Sujayyendhiren Ramarao srinivasamurthi sujayy1983

View GitHub Profile
@sujayy1983
sujayy1983 / CreateBTfromSortedArray.py
Created January 30, 2015 16:36
create balanced tree for a sorted array.
"""
@Author: Sujayyendhiren
@Description: Sorted array for binary tree construction
"""
class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
@sujayy1983
sujayy1983 / GraphTraversal.py
Last active August 29, 2015 14:14
Traverse unidirectional graph. DFS another example.
"""
@Author: Sujayyendhiren
@Description: Depth first search
"""
def backtrack( visitedParent, start, end ):
result = []
node = end
result.insert(0,end)
@sujayy1983
sujayy1983 / Bubble.py
Created January 29, 2015 23:41
Implementation of bubble sort
"""
@Author: Sujayyendhiren Ramarao Srinivasamurthi
@Description: Bubble sort implementation
"""
def bubble_sor( arr2Sort ):
for x in range(len(arr2Sort)):
sortCnt = 0
for idx in range( len(arr2Sort) - x - 1):
if (arr2Sort[idx] > arr2Sort[idx+1]):
@sujayy1983
sujayy1983 / Selection.py
Created January 29, 2015 23:41
Implementation of selection sort.
"""
@Author: Sujayyendhiren Ramarao Srinivasamurthi
@Description: Selection sort
"""
def selection_sort( arr2sort ):
for idx in range(len(arr2sort)):
min = idx
"""
@Author: Sujayyendhiren Ramarao srinivasamurthi
@Description: Scalar product Reference data and code used from
http://www.python-course.eu/matrix_arithmetic.php
"""
import numpy as np
#Dot product
x = np.array( [1, 2, 3])
y = np.array( [-7, 8, 9])
@sujayy1983
sujayy1983 / VarArgument.py
Created January 26, 2015 00:07
Fun with *args and **kwargs
"""
@Author: Sujayyendhiren Ramarao Srinivasamurthi
@Description: Fun with args and kwargs
"""
def function1 ( *args, ** kwargs):
print ""
print args
print kwargs
@sujayy1983
sujayy1983 / Insertion.py
Created January 25, 2015 19:03
Implementaion of insertion sort.
"""
@Author: Sujayyendhiren Ramarao Srinivasamurthi
@Description: Insertion sort
"""
def insertion_sort( data ):
length = len(data)
for idx in range(1, length):
val = data[idx]
@sujayy1983
sujayy1983 / dfs.py
Created January 25, 2015 18:36
Depth First Search
"""
@Author: Sujayyendhiren Ramarao Srinivasamurthi
@Description: My implementation of DFS
"""
graph = {
'1': ['2', '3', '4'],
'2': ['5', '6'],
'5': ['9', '10'],
'4': ['7', '8'],
'7': ['11', '12']
@sujayy1983
sujayy1983 / DenominationCombination.py
Last active August 29, 2015 14:14
Given a value in cents. Find the corresponding combinations in which that money maybe paid.
"""
@Author Sujayyendhiren ramarao srinivasamurthi
@Description For a given value find denominations in cents
"""
lDenom = [ 100 ,50, 25, 10, 5 ,1 ]
lDepth = [ '', '\t', '\t\t', '\t\t\t', '\t\t\t\t', '\t\t\t\t\t']
def combinations ( num , depth ):
for denom in lDenom[depth:6]:
@sujayy1983
sujayy1983 / MyIterator.py
Created January 25, 2015 02:07
1. My iterator implementation. 2. Using the iterator in two ways.
"""
@Author: Sujayyendhiren Ramrarao Srinivasamurthi
@Description: My own iterator.
"""
class Myfib:
""" Fibonacci class"""
def __init__(self, max):
self.max = max
def __iter__(self):