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
# Simple implementation of Binary Search algorithm | |
# Sorting included | |
from math import ceil | |
def Bsearch(item, list): | |
s_index = int(ceil(len(list)/2)) | |
list.sort() | |
found = False | |
while True: |
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
# Simple implementation of Breadth-First Search on a binary tree | |
from collections import deque | |
class Node: | |
def __init__(self, newData): | |
self.data = newData | |
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
# Simple graph implementation (not tested) | |
class Node: | |
def __init__(self, newData): | |
self.data = newData | |
self.adjacencyList = {} | |
def addAdjacent(self, adj, weight): | |
self.adjacencyList[adj] = weight |
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
# A simple of implementation of a hash table | |
class Node: | |
def __init__(self, key, newData): | |
self.key = key | |
self.data = newData | |
def getKey(self): | |
return self.key |
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
//A Simple implementation of vector(containing objects of a class) data structure | |
#include <iostream> | |
#include <vector> | |
using namespace std; | |
class Salad{ | |
private: | |
int oranges, apples; | |
public: | |
void setOranges(int numOranges){ oranges = numOranges; } |
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
# A simple Trie implementation | |
class Node: | |
def __init__(self): | |
self.children = dict() | |
self.count = 0 | |
class Trie: |
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
# A simple complete binary tree implementation with DFS methods | |
class Node: | |
def __init__(self, newData): | |
self.data = newData | |
self.left = None | |
self.right = None | |
def getData(self): |
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
# Basic implementation of doubly linked list | |
class Node: | |
def __init__(self, data): | |
self.data = data | |
self.next = None | |
self.prev = None | |
def getData(self): | |
return self.data |
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
# Basic implementation of singly linked list | |
class Node: | |
def __init__(self, data): | |
self.data = data | |
self.next = None | |
def getData(self): | |
return self.data | |
def setData(self, newData): |
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
# Basic queue implementation: using collections | |
from collections import deque | |
class Queue: | |
def __init__(self): | |
self.items = deque() | |
def isEmpty(self): | |
return self.items == deque([]) |