Data Structures & Algorithms
10X Training
Why data structures & algorithms?
Agenda
Array & linked list
What’s an array?
What’s an array?
What’s a linked list?
What’s a linked list?
Reverse a linked list
Given pointer to the head node of a linked list, the task is to reverse the linked list.
Input : Head of following linked list
1->2->3->4->NULL
Output : Linked list should be changed to,
4->3->2->1->NULL
How are arrays & lists implemented in Java?
34
How many data structures classes/interfaces in JDK 1.8?
queue & stack
What’s a queue?
What’s a queue?
What’s a stack?
What’s a stack?
MinStack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.
push(x) – Push element x onto stack.
pop() – Removes the element on top of the stack.
top() – Get the top element.
getMin() – Retrieve the minimum element in the stack.
MinStack minStack = new MinStack();
minStack.push(-2);
minStack.push(0);
minStack.push(-3);
minStack.getMin(); // Returns -3.
minStack.pop();
minStack.peek(); // Returns 0.
minStack.getMin(); // Returns -2.
hashtable & tree
What’s a hash table?
What’s a hash table?
Fast LRU Cache
Implement an LRU cache.
LruCache cache = new LruCache();
cache.put(k, v); // O(1)
cache.get(k); // O(1)
How are hash tables implemented in Java?
tree
What’s a tree?
What’s a tree?
112
What type of trees do you know?�How Pages in category "Trees (data structures)" on Wikipedia?
What’s a BST?
What’s a red-black tree?
Breadth first search
What’s a trie?
What’s a heap?
How are trees implemented in Java?
What’s a graph?
NY Metro
Given a square matrix representing the intersections of streets in a BIG city (like New York City) where each element of the matrix contains either 1 or 0 (meaning that there is or is not a stairwell to a subway at that location respectively)
Produce a new matrix of the same size where each element is the distance to the nearest subway stair well from that street intersection.
Example:
0 0 1 0
0 0 0 0
1 0 0 0
0 0 0 0
2 1 0 1
1 2 1 2
0 1 2 3
1 2 3 4
No
Is there a graph data structure in JDK 1.9?
concurrency
❓ How does concurrency affect DS?
❓ What are iterators?
What’s CopyOnWriteArrayList?
Any other Java Data Structures?
What have we learned?
What have we learned?
What have we learned?
What have we learned?
What have we learned?
What have we learned?
Thank you
Homework�Implement NY Metro�Homework2.nearestStairwell([][])�B+tree VS B-tree
Next�10X - Clean code