From 11ad8c6f7cb33538d7ebed518e24cdf7b7aa9a81 Mon Sep 17 00:00:00 2001 From: Yangshun Date: Sat, 29 May 2021 17:37:38 +0800 Subject: [PATCH] contents: audit algorithms formatting --- contents/algorithms/graph.md | 8 ++++++-- contents/algorithms/sorting-searching.md | 4 ++++ contents/algorithms/tree.md | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/contents/algorithms/graph.md b/contents/algorithms/graph.md index 4264d78d..7215f1e5 100644 --- a/contents/algorithms/graph.md +++ b/contents/algorithms/graph.md @@ -21,7 +21,7 @@ You can be given a list of edges and tasked to build your own graph from the edg A tree-like diagram could very well be a graph that allows for cycles and a naive recursive solution would not work. In that case you will have to handle cycles and keep a set of visited nodes when traversing. -## Graph search algorithms: +## Graph search algorithms - **Common** - Breadth-first Search, Depth-first Search - **Uncommon** - Topological Sort, Dijkstra's algorithm @@ -90,7 +90,11 @@ def bfs(matrix): traverse(i, j) ``` -> NOTE: While DFS is implemented using recursion in this sample, it could also be implemented iteratively similar to BFS. The key difference between the algorithms lies in the underlying data structure (BFS uses a queue while DFS uses a stack). The `deque` class in Python can function as both a stack and a queue +:::note + +While DFS is implemented using recursion in this sample, it could also be implemented iteratively similar to BFS. The key difference between the algorithms lies in the underlying data structure (BFS uses a queue while DFS uses a stack). The `deque` class in Python can function as both a stack and a queue + +::: For additional tips on BFS and DFS, you can refer to this [LeetCode post](https://leetcode.com/problems/pacific-atlantic-water-flow/discuss/90774/Python-solution-with-detailed-explanation) diff --git a/contents/algorithms/sorting-searching.md b/contents/algorithms/sorting-searching.md index 77ea6b55..01181156 100644 --- a/contents/algorithms/sorting-searching.md +++ b/contents/algorithms/sorting-searching.md @@ -3,6 +3,10 @@ id: sorting-searching title: Sorting and Searching --- +## Tips + +When a given sequence is in a sorted order (be it ascending or descending), using binary search should be one of the first things that come to your mind. + ## Sample questions - Sorting search results on a page given a certain set of criteria. diff --git a/contents/algorithms/tree.md b/contents/algorithms/tree.md index 5df7cdda..e79493cc 100644 --- a/contents/algorithms/tree.md +++ b/contents/algorithms/tree.md @@ -46,7 +46,7 @@ Be very familiar with the properties of a BST and validating that a binary tree When a question involves a BST, the interviewer is usually looking for a solution which runs faster than O(n). -#### Recommended LeetCode questions +## Recommended LeetCode questions - [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/) - [Same Tree](https://leetcode.com/problems/same-tree/)