Created
July 13, 2016 21:10
-
-
Save Zhang/cde82c6b5d66eac7bce8fcd0b37b2ad6 to your computer and use it in GitHub Desktop.
Chris medisas interview
This file contains hidden or 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
5 | |
/ \ | |
3 7 | |
/ \ / \ | |
1 4 6 9 | |
\ | |
2 | |
//find the next highest node | |
//ex. given 5 | |
1. check the right side child | |
exisits | |
rightside child..traverse left most ancestor child..to give us the next highest | |
// ex. given 4 | |
4. right side child doesnt exist so go to parent | |
is the starter node a right side child? yes | |
go up again. | |
capacity: 5 | |
get (key) O(1) | |
set (key, value) O(1) | |
// If space set it | |
// If no space, kick out least recently used | |
LinkedList list = new LinkList(); | |
Node front = null; | |
Node back = null; | |
public void set(String input) { | |
if (list.size() < 5){ | |
if (front == null){ | |
Node newNode = new Node(input); | |
front = newNode; | |
back = newNode; | |
}else{ | |
Node newNode = new Node(input); | |
front.next = newNode; | |
back = newNode; | |
} | |
}else{ | |
//find the least used object aka last | |
list.delete_tail | |
list.insert_head | |
} | |
} | |
//it is in the list | |
//it is not in the list | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment