Topological sorting is about DAG(Directed Acyclic Graph). The main idea of Kahn algorithm is to: Repeatedly find the start node(no income path, in-degree is 0) and print it. To find the start node, there are many ways. Given in-degree is the most convenient one. While sometimes we might need a map(hash map) to map the … More BFS in Topological Sorting(Kahn)
Heap vs Stack more information: http://www.journaldev.com/4098/java-heap-space-vs-stack-memory
Initialize a graph in java Usually, we use Hashmap to store a graph in java. Because in hashmap/hashset, there won’t be a duplicate even if we repeat putting a same item in the map/set. Here is a template of initializing a hashmap graph:
Template: If a layer traversal is needed, add a “for” loop. (Attention that queue.size will change). If in a graph, we need a hash set to store the statue of node ( visited or not), and check set.contains(child) before offerring it into queue.
1.Initialization String a ; a must be initialized if further operations will be taken (unless assignment). eg. String a = null; a += “aaa”; System.out.println(a); This will print “nullaaa”. 2. Int to String to Int String a = Integer.toString(i); Int a = Integer.parseInt(a);
FIFO: Queue FILO: Stack Queue Since java 5 we can use queue by importing import java.util.Queue; Insert an item at the end of a queue and pop out from the head of the queue. Queue is an interface that there are several implementing classes, but the most used class is LinkedList Queue<TreeNode> queue = new … More Java Queue, Stack
I decided to write some technical blog on this site. But I’m not a native English speaker, I will try my best to write in English. I might write in Chinese if I really want to write something. I used MS SQLServer a few years ago. And I found that MySQL is very alike SQLServer. The … More Start MySQL server