A binary search algorithm allows you to search an ordered list of elements using divide and conquer strategy. But before we dive in, lets have a gentle reminder of a linear search. Whats linear se...
Websockets with python
I attended a meet up the other day and found myself working on a task that involved the websocket protocol. I haven’t used it much before and thought it would be a good opportunity to explore a sma...
Leetcode 209 - Minimum Size Subarray Sum
Given an array of positive integers nums and a positive integer target, return the minimal length of a subarray whose sum is greater than or equal to target. If there is no such subarray, return 0 ...
Binary Search Tree - Validate BST
Question Validate if a binary tree satisifies the binary search tree property. Example: Valid BST flowchart TD 8((8)) --> 3((3)) 8((8)) --> 10((10)) 3((3)) --> 1((1)) 3(...
Binary Search Tree - Insert into BST
Write a function that takes in a root, value as arguments and returns the root with the new node inserted into the correct position of the binary search tree. class Node: def __init__(self, d...
Leetcode 1035 - All Elements in Two Binary Search Trees
Given two binary search trees root1 and root2, return a list containing all the integers from both trees sorted in ascending order. Full question details here. # Definition for a binary tree node...
Binary Search Tree - Introduction
Let’s start with a quick definition: The property of a binary search tree is that the left child is always less than the current node and the right child is always greater than the current node. ...
Binary Trees - Size of binary tree
Question Given a binary tree, find the number of nodes it contains. Consider the following input: flowchart TD 2((2)) --> 7((7)) 7((7)) --> 4((4)) 7((7)) --> 6((6)) 2((2)) ...
Binary Trees - Reverse level order traversal
Question Write an algorithm that traverses the binary tree in reverse order from the bottom level to the top level. Consider the example: flowchart TD 2((2)) --> 7((7)) 7((7)) --> 4((...
Binary Trees - Height of tree
Question Given a binary tree, write a recursive algorithm to find the height of the tree. class Node: def __init__(self, value) -> None: self.value = value self.left = No...