Skip to content

Instantly share code, notes, and snippets.

View charlespunk's full-sized avatar

charlespunk charlespunk

View GitHub Profile
Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node.
Implement an algorithm to find the kth to last element of a singly linked list.
Write code to remove duplicates from an unsorted linked list.
FOLLOW UP
How would you solve this problem if a temporary buffer is not allowed?
You are given a binary tree in which each node contains a value. Design an algorithm to print all paths which sum to a given vaue. Note that a path can start or end anythere in the tree.
/*
CacheForRecentlyAccess
[A, B, C, D]
[B, C, D, A]
[C, D, A, F, G]
[C, A, F, G, D]
[A, F, G, D, N] C evicted
[F, G, D, N, M] A evicted
You have two very large binary trees: T1, with millions of nodes, and T2, with hundreds of nodes. Create an algorithm to decide if T2 is a subtree of T1.
A tree T2 is a subtree if T1 if there exists a node n in T1 such that the subtree of n is identical to T2. That is, if you cut of the tree at node n, the two trees would be identical.
Design an algorithm and write code to find the first common ancestor of two nodes in a binary tree. Avoid sorting additional nodes in a data structure. NODE: This is not necessarily a binary search tree.
Write an algorithm to find the 'next' node (i.e., in-order successor) of a given node in a binary search tree. You may assume that each node has a link to its parent.
Implement a function to check is a binary tree is a binary search tree.
Given a binary tree, design an algorithm which creates a linked list of all the nodes at each depth(e.g., if you have a tree with depth D, you'll have D linked lists).