3 Replies - 1898 Views - Last Post: 23 March 2010 - 10:19 AM Rate Topic: -----

#1 tnecniv  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • 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??

please advise
Is This A Good Question/Topic? 0
  • +

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

#2 Martyn.Rae  Icon User is offline

  • The programming dinosaur
  • member icon

Reputation: 540
  • View blog
  • Posts: 1,406
  • 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.
Was This Post Helpful? 0
  • +
  • -

#3 tnecniv  Icon User is offline

  • D.I.C Head

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

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

Posted 23 March 2010 - 09:12 AM

View PostMartyn.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.
please advise how i can start?
cause i also duno wat the question is about
Was This Post Helpful? 0
  • +
  • -

#4 Martyn.Rae  Icon User is offline

  • The programming dinosaur
  • member icon

Reputation: 540
  • View blog
  • Posts: 1,406
  • 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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1