Introduction to Trees


Problems

It is possible to represent arithmetic, parenthesized expressions using a tree. If a node is an operator, such as a plus or a division sign, then each of the two children must be either a number or an expression which will evaluate to a number. In other words, the two children of an operator will be its operands.

Figure %: Simple Arithmetic Tree
The above represents (3 + 4) .

Problem : Convert the following expression into such a tree: ((3 + 4)*5)/6


Problem : Convert the following expression into such a tree: 3 + 4*(5/6)


Problem : How could you use this tree representation to devise a scheme to represent the expressions without using any parentheses. Hint: Consider a the different sorts of traversals. See the recursion SparkNote for information on tree traversals.


Take a Study Break

SparkLife

Star Trek gets SEXY

Chris Pine and Zoe Saldana heat up the red carpet!

SparkLife

Are you afraid of relationships?

Auntie SparkNotes can help!

SparkLife

Wanna get JLaw's gorgeous glow?

Click here for simple, sexy makeup tricks!

SparkLife

Sexy starlet style

See every single look from the Met Gala!

SparkLife

Who'd be on your zombie-apocalypse crew?

We already dib'sed Genghis Khan.

Geek out!

The MindHut

Geeky Actors: Then and Now

Travel back in time!

The MindHut

Villains We Want These Actresses to Play

From super cute to super bad!

The MindHut

10 Movies Better Than Their Books

What do you think?

The MindHut

How To Look Like J-Law...

When you don't look like J-Law.

The MindHut

12 Scientific Inaccuracies in Into Darkness

What did Star Trek get wrong?

The Book

Cover image

Read What You Love, Anywhere You Like

Get Our FREE NOOK Reading Apps