Skip to Content
Hands-On Data Structures and Algorithms with Python - Second Edition
book

Hands-On Data Structures and Algorithms with Python - Second Edition

by Dr. Basant Agarwal, Benjamin Baka, David Julian
October 2018
Beginner to intermediate
398 pages
11h 1m
English
Packt Publishing
Content preview from Hands-On Data Structures and Algorithms with Python - Second Edition

Pre-order traversal and prefix notation

Pre-order tree traversal works as follows. First of all, we check if the current node is null or empty. If it is not empty, we traverse the tree. The pre-order tree traversal works as follows:

  1. We start traversing with the root node
  2. Next, we traverse the left sub-tree and call the preorder function with the left sub-tree recursively
  3. Next, we visit the right sub-tree and call the preorder function with the right sub-tree recursively

So, to traverse a tree in pre-order mode, we visit the tree in the order of root node, the left sub-tree, and the right sub-tree node.

Consider the following example tree to understand pre-order traversal:

In the preceding example of a binary tree, first, we visit root ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Hands-On Data Structures and Algorithms with Python - Third Edition

Hands-On Data Structures and Algorithms with Python - Third Edition

Dr. Basant Agarwal
Data Structures & Algorithms in Python

Data Structures & Algorithms in Python

John Canning, Alan Broder, Robert Lafore
Data Structures and Algorithms in Python

Data Structures and Algorithms in Python

Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser

Publisher Resources

ISBN: 9781788995573Supplemental Content