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&mC0pYGzQGNj^O-|V!Gi?aqK|fW6G?u
z_3-e^@r$8b_r;VQAN}17Zpq&*f=WOED4ScYUvSOzOYL&0CVPYe5J-9^p`&?B!#lq>
zN?5@Ld@g2i;0CzgVcn0^gX@j~km}tQ0@q9PPyU96LKZteVVs)3y*k(UQ%`X<&ugG?
zY6NZux~>X+XoBy5bp{sw?^|7<;D3LN2DbR0Z`A&WX4c?;3jq1jKRy553}pV(%#!*4
pP42&@`_JV5TMO1;-wx)1HEY#83w)so_@GR{{l7)3!wl2
literal 0
HcmV?d00001
diff --git a/sorts/timsort.py b/sorts/timsort.py
new file mode 100644
index 000000000..8c75b5191
--- /dev/null
+++ b/sorts/timsort.py
@@ -0,0 +1,81 @@
+def binary_search(lst, item, start, end):
+ if start == end:
+ if lst[start] > item:
+ return start
+ else:
+ return start + 1
+ if start > end:
+ return start
+
+ mid = (start + end) // 2
+ if lst[mid] < item:
+ return binary_search(lst, item, mid + 1, end)
+ elif lst[mid] > item:
+ return binary_search(lst, item, start, mid - 1)
+ else:
+ return mid
+
+
+def insertion_sort(lst):
+ length = len(lst)
+
+ for index in range(1, length):
+ value = lst[index]
+ pos = binary_search(lst, value, 0, index - 1)
+ lst = lst[:pos] + [value] + lst[pos:index] + lst[index+1:]
+
+ return lst
+
+
+def merge(left, right):
+ if not left:
+ return right
+
+ if not right:
+ return left
+
+ if left[0] < right[0]:
+ return [left[0]] + merge(left[1:], right)
+
+ return [right[0]] + merge(left, right[1:])
+
+
+def timsort(lst):
+ runs, sorted_runs = [], []
+ length = len(lst)
+ new_run = [lst[0]]
+ sorted_array = []
+
+ for i in range(1, length):
+ if i == length - 1:
+ new_run.append(lst[i])
+ runs.append(new_run)
+ break
+
+ if lst[i] < lst[i - 1]:
+ if not new_run:
+ runs.append([lst[i - 1]])
+ new_run.append(lst[i])
+ else:
+ runs.append(new_run)
+ new_run = []
+ else:
+ new_run.append(lst[i])
+
+ for run in runs:
+ sorted_runs.append(insertion_sort(run))
+
+ for run in sorted_runs:
+ sorted_array = merge(sorted_array, run)
+
+ return sorted_array
+
+
+def main():
+
+ lst = [5,9,10,3,-4,5,178,92,46,-18,0,7]
+ sorted_lst = timsort(lst)
+ print(sorted_lst)
+
+if __name__ == '__main__':
+ main()
diff --git a/sorts/topological_sort.py b/sorts/topological_sort.py
new file mode 100644
index 000000000..5de1cc2b7
--- /dev/null
+++ b/sorts/topological_sort.py
@@ -0,0 +1,32 @@
+# a
+# / \
+# b c
+# / \
+# d e
+edges = {'a': ['c', 'b'], 'b': ['d', 'e'], 'c': [], 'd': [], 'e': []}
+vertices = ['a', 'b', 'c', 'd', 'e']
+
+
+def topological_sort(start, visited, sort):
+ """Perform topolical sort on a directed acyclic graph."""
+ current = start
+ # add current to visited
+ visited.append(current)
+ neighbors = edges[current]
+ for neighbor in neighbors:
+ # if neighbor not in visited, visit
+ if neighbor not in visited:
+ sort = topological_sort(neighbor, visited, sort)
+ # if all neighbors visited add current to sort
+ sort.append(current)
+ # if all vertices haven't been visited select a new one to visit
+ if len(visited) != len(vertices):
+ for vertice in vertices:
+ if vertice not in visited:
+ sort = topological_sort(vertice, visited, sort)
+ # return sort
+ return sort
+
+
+sort = topological_sort('a', [], [])
+print(sort)
diff --git a/traversals/binary_tree_traversals.py b/traversals/binary_tree_traversals.py
new file mode 100644
index 000000000..9d14a1e7e
--- /dev/null
+++ b/traversals/binary_tree_traversals.py
@@ -0,0 +1,109 @@
+"""
+This is pure python implementation of tree traversal algorithms
+"""
+from __future__ import print_function
+import queue
+
+
+class TreeNode:
+ def __init__(self, data):
+ self.data = data
+ self.right = None
+ self.left = None
+
+
+def build_tree():
+ print("\n********Press N to stop entering at any point of time********\n")
+ print("Enter the value of the root node: ", end="")
+ check=input()
+ if check=='N' or check=='n':
+ return None
+ data=int(check)
+ q = queue.Queue()
+ tree_node = TreeNode(data)
+ q.put(tree_node)
+ while not q.empty():
+ node_found = q.get()
+ print("Enter the left node of %s: " % node_found.data, end="")
+ check=input()
+ if check=='N' or check =='n':
+ return tree_node
+ left_data = int(check)
+ left_node = TreeNode(left_data)
+ node_found.left = left_node
+ q.put(left_node)
+ print("Enter the right node of %s: " % node_found.data, end="")
+ check = input()
+ if check == 'N' or check == 'n':
+ return tree_node
+ right_data = int(check)
+ right_node = TreeNode(right_data)
+ node_found.right = right_node
+ q.put(right_node)
+
+
+def pre_order(node):
+ if not isinstance(node, TreeNode) or not node:
+ return
+ print(node.data, end=" ")
+ pre_order(node.left)
+ pre_order(node.right)
+
+
+def in_order(node):
+ if not isinstance(node, TreeNode) or not node:
+ return
+ in_order(node.left)
+ print(node.data, end=" ")
+ in_order(node.right)
+
+
+def post_order(node):
+ if not isinstance(node, TreeNode) or not node:
+ return
+ post_order(node.left)
+ post_order(node.right)
+ print(node.data, end=" ")
+
+
+def level_order(node):
+ if not isinstance(node, TreeNode) or not node:
+ return
+ q = queue.Queue()
+ q.put(node)
+ while not q.empty():
+ node_dequeued = q.get()
+ print(node_dequeued.data, end=" ")
+ if node_dequeued.left:
+ q.put(node_dequeued.left)
+ if node_dequeued.right:
+ q.put(node_dequeued.right)
+
+
+if __name__ == '__main__':
+ import sys
+
+ print("\n********* Binary Tree Traversals ************\n")
+ # For python 2.x and 3.x compatibility: 3.x has no raw_input builtin
+ # otherwise 2.x's input builtin function is too "smart"
+ if sys.version_info.major < 3:
+ input_function = raw_input
+ else:
+ input_function = input
+
+ node = build_tree()
+ print("\n********* Pre Order Traversal ************")
+ pre_order(node)
+ print("\n******************************************\n")
+
+ print("\n********* In Order Traversal ************")
+ in_order(node)
+ print("\n******************************************\n")
+
+ print("\n********* Post Order Traversal ************")
+ post_order(node)
+ print("\n******************************************\n")
+
+ print("\n********* Level Order Traversal ************")
+ level_order(node)
+ print("\n******************************************\n")