Results 1 to 4 of 4
Thread: need help with big O notations
- 04-09-2011, 04:11 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
- 04-09-2011, 05:16 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
No one is going to give you the answer. I'm assuming this assignment is homework. Have you done anything to try to figure this out yourself yet?
- 04-09-2011, 06:51 AM #3
Member
- Join Date
- Apr 2011
- Posts
- 2
- Rep Power
- 0
Just wanted to see if I'm correct or not, from my understanding accessing a node in a binary tree takes o(logn) time. So does this mean that to get all of the leaf nodes in a tree is just o(logn) then. And for getting the sum of all the numbers in a binary tree should be o(n) right? Since we are iterating through every node in the tree and adding the values together.
- 04-09-2011, 08:18 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Also posted at OTN
It may help to think about what counting the nodes and finding the sum have in common. COunting adds 1 every time it finds a node while the sum calculation involves adding the node's value. From a complexity point of view they are pretty much the same thing.Last edited by pbrockway2; 04-09-2011 at 08:24 AM.
Similar Threads
-
myPatterns: pattern matching in custom notations for Java & JavaScript
By Nic Volanschi in forum Java SoftwareReplies: 0Last Post: 06-29-2010, 08:16 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks