Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View RafaelBroseghini's full-sized avatar
🥋

Rafael Broseghini RafaelBroseghini

🥋
View GitHub Profile
@RafaelBroseghini
RafaelBroseghini / add-to-linked-list-recursively.py
Created November 18, 2018 16:34
Add a node to a Linked List, recursively
class LinkedList(object):
class __Node(object):
def __init__(self, val, next=None):
self.val = val
self.next = next
def __init__(self, head):
self.head = LinkedList.__Node(head)
def add(self, val):
@RafaelBroseghini
RafaelBroseghini / you-are-now-an-expert-at-matrices.py
Created November 15, 2018 17:33
Handling Matrices Like a PRO
"""
Given a N x N matrix, let us extract the rows and columns.
This function takes a matrix as parameter and returns a
tuple of rows and columns. Both rows and columns are also matrices. (lists of lists)
NOTE: matrix passed in as parameter must have N rows and N columns for this algorithm
to work.
"""
@RafaelBroseghini
RafaelBroseghini / guess-and-check.py
Created November 14, 2018 04:08
Guess and Check Pattern
"""
This pattern guesses and checks if there are any even numbers in a given array
and returns True or False.
"""
def guess_and_check(array: list) -> bool:
if len(array) == 0:
return False
found = False
@RafaelBroseghini
RafaelBroseghini / linked-list-stack.py
Created October 30, 2018 05:10
Stack using Linked List
"""
Implementation of a Stack (FILO) Data Structure
using a Linked List.
"""
class LinkedList(object):
class __Node(object):
def __init__(self, val):
self.val = val
@RafaelBroseghini
RafaelBroseghini / bfs.py
Last active November 15, 2018 17:36
Breadth First Search
"""
Let's assume we have a Binary Tree.
class BinaryTree(object):
def __init__(self, val):
self.val = val
self.right = None
self.left = None
I understand there may be some breaking of data encapsulation below.
@RafaelBroseghini
RafaelBroseghini / binary_search.py
Last active November 15, 2018 17:38
Iterative and Recursive Binary Search
"""
Both binary search functions implemented below assume the element being searched
is an integer but this can certainly be done with strings as well.
"""
# Iterative Binary Search
def iterative_binary_search(arr: list, element: int) -> bool:
start = 0
end = len(arr) - 1
@RafaelBroseghini
RafaelBroseghini / hello_flask.py
Created August 8, 2018 21:14
Simple Flask App setup
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return "You have reached the index route!"
if __name__ == "__main__":
app.run(debug=True)