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

Expression trees

An arithmetic expression is represented by a combination of operators and operands where the operators can be unary or binary. An arithmetic expression can also be represented using a binary tree, which is called an expression tree. This tree structure can also be used to parse arithmetic and boolean expressions. In an expression tree, all the leaf nodes contain the operands and non-leaf nodes contain the operators. We should also note that the expression tree will have one of its sub-trees (right sub-tree or left sub-tree) empty in the case of a unary operator.

For example, the expression tree for 3 + 4 would look as follows:

For a slightly more complex expression, (4 + 5) * (5-3), we would get the following:

The arithmetic ...

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