560 likes | 653 Vues
Discover the Inorder traversal technique to visit nodes in the left subtree, then the current node, and finally the right subtree. Dive into the detailed steps and learn how to implement this method efficiently in tree data structures. Elevate your algorithmic knowledge with this fundamental approach.
E N D
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi no at do if pi go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi no at do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi no at do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi inorder(be)do inorder(go) inorder(do) no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi inorder(be)do inorder(go) inorder(do) no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. inorder(null)be inorder(null) inorder(be) hi inorder(be)do inorder(go) inorder(do) no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. inorder(null)be inorder(null) inorder(be) hi inorder(be)do inorder(go) inorder(do) no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. inorder(null)be inorder(null) inorder(be) hi inorder(be)do inorder(go) inorder(do) no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. inorder(null)be inorder(null) inorder(be) hi inorder(be)do inorder(go) inorder(do) no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi inorder(be)do inorder(go) inorder(do) no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi inorder(be)do inorder(go) inorder(do) no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi inorder(be)do inorder(go) inorder(do) no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. inorder(null)go inorder(null) inorder(go) hi inorder(be)do inorder(go) inorder(do) no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. inorder(null)go inorder(null) inorder(go) hi inorder(be)do inorder(go) inorder(do) no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. inorder(null)go inorder(null) inorder(go) hi inorder(be)do inorder(go) inorder(do) no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. inorder(null)go inorder(null) inorder(go) hi inorder(be)do inorder(go) inorder(do) no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi inorder(be)do inorder(go) inorder(do) no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi no at inorder(null)at inorder(do) inorder(at) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi no at do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi no at do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi no at do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi inorder(null)if inorder(me) inorder(if) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi inorder(null)if inorder(me) inorder(if) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi inorder(null)if inorder(me) inorder(if) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi inorder(null)if inorder(me) inorder(if) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. inorder(null)me inorder(null) inorder(me) hi inorder(null)if inorder(me) inorder(if) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. inorder(null)me inorder(null) inorder(me) hi inorder(null)if inorder(me) inorder(if) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. inorder(null)me inorder(null) inorder(me) hi inorder(null)if inorder(me) inorder(if) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. inorder(null)me inorder(null) inorder(me) hi inorder(null)if inorder(me) inorder(if) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi inorder(null)if inorder(me) inorder(if) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi inorder(of)pi inorder(we) inorder(pi) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi inorder(of)pi inorder(we) inorder(pi) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. inorder(null)of inorder(null) inorder(of) hi inorder(of)pi inorder(we) inorder(pi) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. inorder(null)of inorder(null) inorder(of) hi inorder(of)pi inorder(we) inorder(pi) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. inorder(null)of inorder(null) inorder(of) hi inorder(of)pi inorder(we) inorder(pi) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. inorder(null)of inorder(null) inorder(of) hi inorder(of)pi inorder(we) inorder(pi) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi inorder(of)pi inorder(we) inorder(pi) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi inorder(of)pi inorder(we) inorder(pi) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. hi inorder(of)pi inorder(we) inorder(pi) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. inorder(null)we inorder(null) inorder(we) hi inorder(of)pi inorder(we) inorder(pi) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we
Inorder Traversal • Inorder traversal. • Visit the left subtree. • Visit the node. • Visit the right subtree. inorder(null)we inorder(null) inorder(we) hi inorder(of)pi inorder(we) inorder(pi) no at inorder(if)no inorder(pi) inorder(no) do if pi inorder(at)hi inorder(no) inorder(hi) go be we me of at be do go hi if me no of pi we