Preorder traversal with a stack
Download
1 / 13

Preorder Traversal with a Stack - PowerPoint PPT Presentation


  • 121 Views
  • Updated On :

Preorder Traversal with a Stack. Push the root onto the stack. While the stack is not empty pop the stack and visit it push its two children. 14. 14 84 13 53 06 99 72 43 33 64 97 51 25. Stack. 14. 43. 84. 16. 33. 97. 13. 72. 53. 99. 64. Preorder Traversal with a Stack.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Preorder Traversal with a Stack' - lilianna


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Preorder traversal with a stack
Preorder Traversal with a Stack

  • Push the root onto the stack.

  • While the stack is not empty

    • pop the stack and visit it

    • push its two children

14

14 84 13 53 06 99 72 43 33 64 97 51 25

Stack

14

43

84

16

33

97

13

72

53

99

64


Preorder traversal with a stack1
Preorder Traversal with a Stack

  • Push the root onto the stack.

  • While the stack is not empty

    • pop the stack and visit it

    • push its two children

84

43

14 84 13 53 06 99 72 43 33 64 97 51 25

Stack

14

14

43

84

16

33

97

13

72

53

99

64


Preorder traversal with a stack2
Preorder Traversal with a Stack

  • Push the root onto the stack.

  • While the stack is not empty

    • pop the stack and visit it

    • push its two children

13

16

43

14 84 13 53 06 99 72 43 33 64 97 51 25

Stack

14

43

84

16

33

97

13

72

53

99

64


Preorder traversal with a stack3
Preorder Traversal with a Stack

  • Push the root onto the stack.

  • While the stack is not empty

    • pop the stack and visit it

    • push its two children

53

16

43

14 84 13 53 06 99 72 43 33 64 97 51 25

Stack

14

43

84

16

33

97

13

13

72

53

99

64


Preorder traversal with a stack4
Preorder Traversal with a Stack

  • Push the root onto the stack.

  • While the stack is not empty

    • pop the stack and visit it

    • push its two children

16

43

14 84 13 53 06 99 72 43 33 64 97 51 25

Stack

14

43

84

16

33

97

13

72

53

99

53

64


Preorder traversal with a stack5
Preorder Traversal with a Stack

  • Push the root onto the stack.

  • While the stack is not empty

    • pop the stack and visit it

    • push its two children

99

72

43

14 84 13 53 16 99 72 43 33 64 97 51 25

Stack

14

43

84

16

6

33

97

13

72

53

99

64


Preorder traversal with a stack6
Preorder Traversal with a Stack

  • Push the root onto the stack.

  • While the stack is not empty

    • pop the stack and visit it

    • push its two children

72

43

14 84 13 53 16 99 72 43 33 64 97 51 25

Stack

14

43

84

16

33

97

13

72

53

99

99

64


Preorder traversal with a stack7
Preorder Traversal with a Stack

  • Push the root onto the stack.

  • While the stack is not empty

    • pop the stack and visit it

    • push its two children

43

14 84 13 53 16 99 72 43 33 64 97 51 25

Stack

14

43

84

16

33

97

13

72

72

53

99

64


Preorder traversal with a stack8
Preorder Traversal with a Stack

  • Push the root onto the stack.

  • While the stack is not empty

    • pop the stack and visit it

    • push its two children

33

97

14 84 13 53 16 99 72 43 33 64 97 51 25

Stack

14

43

43

84

16

33

97

13

72

53

99

64


Preorder traversal with a stack9
Preorder Traversal with a Stack

  • Push the root onto the stack.

  • While the stack is not empty

    • pop the stack and visit it

    • push its two children

64

97

14 84 13 53 16 99 72 43 33 64 97 51 25

Stack

14

43

84

16

33

33

97

13

72

53

99

64


Preorder traversal with a stack10
Preorder Traversal with a Stack

  • Push the root onto the stack.

  • While the stack is not empty

    • pop the stack and visit it

    • push its two children

97

14 84 13 53 16 99 72 43 33 64 97 51 25

Stack

14

43

84

16

33

97

13

72

53

99

64

64


Preorder traversal with a stack11
Preorder Traversal with a Stack

  • Push the root onto the stack.

  • While the stack is not empty

    • pop the stack and visit it

    • push its two children

14 84 13 53 16 99 72 43 33 64 97 51 25

Stack

14

43

84

16

33

97

97

13

72

53

99

64


Preorder traversal with a stack12
Preorder Traversal with a Stack

  • Push the root onto the stack.

  • While the stack is not empty

    • pop the stack and visit it

    • push its two children

14 84 13 53 16 99 72 43 33 64 97 51 25

Stack

14

43

84

16

33

97

13

72

53

99

64


ad