/ProblemSolving

Solutions for questions from interviews, general exploration of data structures and algorithms

Primary LanguageJava

Graph Learning Notes:

1. Add DFS and BFS functions with start node specification, rather than try to construct whole graph.
List<Node<T>> graphDfs(Node<T> startNode);

2. Reverse Adj list can be kept to determine roots for graph.
```
        Set<Node<String>> startNodes = graphAdjacency
                .keySet()
                .stream()
                .filter(node -> reverseAdjacency.get(node) == null)
                .collect(Collectors.toSet());
```

3. Element should be removed from Queue or Stack only if can be processed immediately, otherwise use peek().

4. If we do pre-order in DFS, iterative logic is simpler because we do not need to keep track if new nodes got added to stack or not.

5. Topological sort: reverse of pre-order DFS = Post order DFS. Graph must be DAG. All trees, since trees do not have cycles.

6. Recursive DFS. Since in general DAG graph we can have multiple nodes point to same next node, we need to keep track of visited nodes. But we do not need to keep track of visited nodes in tree. Tracking List of nodes to store traversal, is required to be passed as function parameter.

TODO:
* Write a Trie:
    - single character per level.
    - Prefix per level.

* Detect cycle in graph.

* Topological Sort: What is difference between DFS - post and reverse v/s pre v/s use adjList v/s use reverseAdjList.

* Write Algorithms on paper.

* Problems to solve
    - Prefix, postfix, infix notation
    - algo to generate prime numbers
    - pre generate prime numbers to optimize isprime

* Code formatting settings for intellij java projects.
    - Integrate checkstyle.
    - Integrate findbugs.


References:
Topological Sort Algorithm | Graph Theory: https://www.youtube.com/watch?v=eL-KzMXSXXI