This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@Author: Sujayyendhiren | |
@Description: Sorted array for binary tree construction | |
""" | |
class Node: | |
def __init__(self, value): | |
self.value = value | |
self.left = None | |
self.right = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@Author: Sujayyendhiren | |
@Description: Depth first search | |
""" | |
def backtrack( visitedParent, start, end ): | |
result = [] | |
node = end | |
result.insert(0,end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@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]): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@Author: Sujayyendhiren Ramarao Srinivasamurthi | |
@Description: Selection sort | |
""" | |
def selection_sort( arr2sort ): | |
for idx in range(len(arr2sort)): | |
min = idx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@Author: Sujayyendhiren Ramarao Srinivasamurthi | |
@Description: Fun with args and kwargs | |
""" | |
def function1 ( *args, ** kwargs): | |
print "" | |
print args | |
print kwargs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@Author: Sujayyendhiren Ramarao Srinivasamurthi | |
@Description: Insertion sort | |
""" | |
def insertion_sort( data ): | |
length = len(data) | |
for idx in range(1, length): | |
val = data[idx] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@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]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
@Author: Sujayyendhiren Ramrarao Srinivasamurthi | |
@Description: My own iterator. | |
""" | |
class Myfib: | |
""" Fibonacci class""" | |
def __init__(self, max): | |
self.max = max | |
def __iter__(self): |