From 5ec85879110c3a915e84e69c67c751159124540d Mon Sep 17 00:00:00 2001 From: bt3gl <138340846+cypher-bt3gl@users.noreply.github.com> Date: Sat, 29 Jul 2023 15:37:01 -0700 Subject: [PATCH] Update README.md --- trees_and_graphs/README.md | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/trees_and_graphs/README.md b/trees_and_graphs/README.md index d99e73e..d8a5697 100644 --- a/trees_and_graphs/README.md +++ b/trees_and_graphs/README.md @@ -9,14 +9,21 @@
-* if the depth of the tree is too large, stack overflow might happen, therefore iterative solutions might be better. -* **in-order** are similar to breath-first search (level order problems) - - work with queues -* **pre-order** is top-down (parameters are passed down to children). - - work with stacks -* **post-order** is a bottom-up solution (if you know the answer of the children, can you concatenate the answer of the nodes?): - - deletion process is always post-order: when you delete a node, you will delete its left child and its right child before you delete the node itself. - - also, post-order is used in mathematical expressions as it's easier to write a program to parse a post-order expression. using a stack, each time when you meet a operator, you can just pop 2 elements from the stack, calculate the result and push the result back into the stack. +* **breath-first search**: + - similar to pre-order, but work with queue (level order problem) +* **depth-first search**: + * if the depth of the tree is too large, stack overflow might happen, therefore iterative solutions might be better. + * work with stacks + * **in-order**: + * left -> node -> right + * **pre-order** + * node -> left -> right + * top-down (parameters are passed down to children). + * **post-order** + * left -> right -> node + * bottom-up solution (if you know the answer of the children, can you concatenate the answer of the nodes?): + - deletion process is always post-order: when you delete a node, you will delete its left child and its right child before you delete the node itself. + - also, post-order is used in mathematical expressions as it's easier to write a program to parse a post-order expression. using a stack, each time when you meet a operator, you can just pop 2 elements from the stack, calculate the result and push the result back into the stack.