Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   Dev Hardware ForumsSOFTWAREProgramming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Hardware Forums Sponsor:
  Trader Rating: 0 · #1  
Old April 20th, 2008, 01:13 PM
Code_Programs Code_Programs is offline
n00b DevH'er
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 4 Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 55 m 16 sec
Reputation Power: 0
Creating binary tree from an array

I have to create a binary tree from an array of elements level wise..i.e a[0] is root.a[1] and a[2] are a[0]'s children.a[4],a[5] are a[2] children and so on.

Can someone tell me how to do this recursively or non-recursively?

Thanks
Comments on this post
madhyena agrees: link. Learn from the lesson, and do it
yourself.

Reply With Quote
  Trader Rating: 0 · #2  
Old April 20th, 2008, 01:25 PM
Sand Man's Avatar
Sand Man Sand Man is offline
¯\(º_o)/¯
Click here for more information.
 
Join Date: Jun 2005
Location: in a daydream
Posts: 3,504 Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)  Folding Points: 169610 Folding Title: Super Ultimate Folder - Level 1Folding Points: 169610 Folding Title: Super Ultimate Folder - Level 1Folding Points: 169610 Folding Title: Super Ultimate Folder - Level 1Folding Points: 169610 Folding Title: Super Ultimate Folder - Level 1Folding Points: 169610 Folding Title: Super Ultimate Folder - Level 1Folding Points: 169610 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Weeks 1 Day 13 h 19 m 21 sec
Reputation Power: 5143
Send a message via MSN to Sand Man Send a message via Google Talk to Sand Man
what programming language? and did you search google first?
Comments on this post
madhyena agrees: Classic Homework Problem.
__________________
How much net work could a network work, if a network could net work?


Reply With Quote
  Trader Rating: 0 · #3  
Old April 20th, 2008, 11:12 PM
Code_Programs Code_Programs is offline
n00b DevH'er
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 4 Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 55 m 16 sec
Reputation Power: 0
Quote:
Originally Posted by Sand Man
what programming language? and did you search google first?


It's in C++ and i searched a lot in Google. It's NOT the binary search tree that we have to implement in which the root value is taken and elements smaller than the root are placed at the left and larger elements are placed on the right.

It's actually a threaded binary tree that we have to implement. Here we are not concerned about the actual values of the elements.All we have to do is take an array of values as user input and create a binary tree as I told above.
array[0] -- root
array[1] -- root's left child
array[2] -- root's right child
array[3] -- array[1] 's left child
array[4] -- array[1]'s right child
and so on...

the tree would look like this
-----------------a[0]-------------

----------a[1]----------a[2]------

-------a[3]----a[4]---a[5]---a[6]---

----a[7]--a[8] .......................

and so on.(hope the above looks like a tree,I tried my best to show it!!)
So, it's basically filling up the tree level wise from the elements in the given array(irrespective of the actual values of the elements)

Last edited by Code_Programs : April 20th, 2008 at 11:16 PM. Reason: diagram isnt represented correctly

Reply With Quote
  Trader Rating: 0 · #4  
Old April 20th, 2008, 11:20 PM
Code_Programs Code_Programs is offline
n00b DevH'er
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 4 Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 55 m 16 sec
Reputation Power: 0
To Madhyena,

Thanks for the link, but the way i have to create my binary tree -- that's no where mentioned in the link you sent me. I am very willing to learn myself given the right resource.Let me know if you find something related to my description which I posted earlier.

Thanks!!

Reply With Quote
  Trader Rating: 0 · #5  
Old April 21st, 2008, 06:31 AM
Sand Man's Avatar
Sand Man Sand Man is offline
¯\(º_o)/¯
Click here for more information.
 
Join Date: Jun 2005
Location: in a daydream
Posts: 3,504 Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)Sand Man User rank is General 63rd Grade (Above 100000 Reputation Level)  Folding Points: 169610 Folding Title: Super Ultimate Folder - Level 1Folding Points: 169610 Folding Title: Super Ultimate Folder - Level 1Folding Points: 169610 Folding Title: Super Ultimate Folder - Level 1Folding Points: 169610 Folding Title: Super Ultimate Folder - Level 1Folding Points: 169610 Folding Title: Super Ultimate Folder - Level 1Folding Points: 169610 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Weeks 1 Day 13 h 19 m 21 sec
Reputation Power: 5143
Send a message via MSN to Sand Man Send a message via Google Talk to Sand Man
the first google link should answer your question.

Reply With Quote
  Trader Rating: 0 · #6  
Old April 29th, 2008, 07:01 PM
Code_Programs Code_Programs is offline
n00b DevH'er
Dev Hardware Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 4 Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level)Code_Programs User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 55 m 16 sec
Reputation Power: 0
The link which I followed -- It shows how to count the nodes. I am not sure how my problem is cleared.

Reply With Quote
  Trader Rating: 0 · #7  
Old April 29th, 2008, 09:16 PM
drumz0rz's Avatar
drumz0rz drumz0rz is offline
Has really smelly feet
Click here for more information.
 
Join Date: Jun 2004
Location: NY
Posts: 5,170 drumz0rz User rank is General 51st Grade (Above 100000 Reputation Level)drumz0rz User rank is General 51st Grade (Above 100000 Reputation Level)drumz0rz User rank is General 51st Grade (Above 100000 Reputation Level)drumz0rz User rank is General 51st Grade (Above 100000 Reputation Level)drumz0rz User rank is General 51st Grade (Above 100000 Reputation Level)drumz0rz User rank is General 51st Grade (Above 100000 Reputation Level)drumz0rz User rank is General 51st Grade (Above 100000 Reputation Level)drumz0rz User rank is General 51st Grade (Above 100000 Reputation Level)drumz0rz User rank is General 51st Grade (Above 100000 Reputation Level)drumz0rz User rank is General 51st Grade (Above 100000 Reputation Level)drumz0rz User rank is General 51st Grade (Above 100000 Reputation Level)drumz0rz User rank is General 51st Grade (Above 100000 Reputation Level)drumz0rz User rank is General 51st Grade (Above 100000 Reputation Level)drumz0rz User rank is General 51st Grade (Above 100000 Reputation Level)drumz0rz User rank is General 51st Grade (Above 100000 Reputation Level)drumz0rz User rank is General 51st Grade (Above 100000 Reputation Level)  Folding Points: 424369 Folding Title: Super Ultimate Folder - Level 1Folding Points: 424369 Folding Title: Super Ultimate Folder - Level 1Folding Points: 424369 Folding Title: Super Ultimate Folder - Level 1Folding Points: 424369 Folding Title: Super Ultimate Folder - Level 1Folding Points: 424369 Folding Title: Super Ultimate Folder - Level 1Folding Points: 424369 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 3 Weeks 6 Days 1 h 14 m 55 sec
Reputation Power: 4383
Send a message via AIM to drumz0rz Send a message via Google Talk to drumz0rz
I just did a program in Java that dealt with trees, but not in arrays, but apparently the way I did it was 'unorthodox', and I worked with a friend... we weren't allowed to work together, so we both got 0's. We were lucky she didn't give us an F though for cheating. Because I'm too busy to figure out exactly what part might help you, here's my whole program. It's java, but it might help you with an idea, probably not. To have it work with arrays you just need a way of keeping track of what array position your in and then have each new node advance that spot.
Really Long Program (that'll probably just confuse you)