# how do i construct a pre-ordered binary tree?

Page 1 of 1

## 3 Replies - 2213 Views - Last Post: 23 March 2010 - 10:19 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=163766&amp;s=f1fe9e9735789a6b90966135a4238a71&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 tnecniv

Reputation: 1
• Posts: 109
• Joined: 03-October 09

# how do i construct a pre-ordered binary tree?

Posted 23 March 2010 - 09:07 AM

Hi, is it possible to construct a pre oder binary tree?

i know how to do a pre order traversal. but constructing a binary tree using that i am not sure what it mean?

what is the purpose of doing a pre order construction of binary treE??

Is This A Good Question/Topic? 0

## Replies To: how do i construct a pre-ordered binary tree?

### #2 Martyn.Rae

• The programming dinosaur

Reputation: 547
• Posts: 1,420
• Joined: 22-August 09

## Re: how do i construct a pre-ordered binary tree?

Posted 23 March 2010 - 09:09 AM

What do you mean by a preorder binary tree? When you are building the tree you are building it in order so you are going to have to explain what you actually mean.

### #3 tnecniv

Reputation: 1
• Posts: 109
• Joined: 03-October 09

## Re: how do i construct a pre-ordered binary tree?

Posted 23 March 2010 - 09:12 AM

Martyn.Rae, on 23 March 2010 - 08:09 AM, said:

What do you mean by a preorder binary tree? When you are building the tree you are building it in order so you are going to have to explain what you actually mean.

Ok. my assigment below:

(Binary Tree Traversals) Suppose you have a binary tree T containing only distinct
items. The pre-order sequence of T is 8, 7, 5, 28, 4, 9, 18, 17, 16, and the in-order
sequence of T is 5, 7, 4, 28, 9, 8, 18, 16, and 17.

Suggest an algorithm to construct binary tree out of pre-order and in-order
sequence. (note: hard question)

i am quite lost with the question too.
cause i also duno wat the question is about

### #4 Martyn.Rae

• The programming dinosaur

Reputation: 547
• Posts: 1,420
• Joined: 22-August 09

## Re: how do i construct a pre-ordered binary tree?

Posted 23 March 2010 - 10:19 AM

I think I understand what is required for this assignment. You need to think about the order in which you could transverse a tree recursively. Preorder is root, then left then right for each node. So in pseudo code:

1. Consider this node
2. Call self with the left hand node
3. Call self with right hand node

Inorder is left node then root and then right node. So in pseudo code that would be

1. Call self with the left hand node
2. Consider this node
3. Call self with right hand node

Hope that helps you