Results 1 to 1 of 1
Thread: Is a tree a heap?
- 06-19-2010, 06:16 PM #1
Senior Member
- Join Date
- Feb 2010
- Location
- Ljubljana, Slovenia
- Posts
- 470
- Rep Power
- 4
Is a tree a heap?
Hey guys, I'm studying for an exam, and have come across the assignment to check if a binary tree is a heap (Heap (data structure) - Wikipedia, the free encyclopedia).
The tree is represented like this:
Now, my first idea was simple, if I come across a node that doesn't have a left ancestor (root.left == null), return (root.right == null), but a few runs with pen and paper soon disproved this theory. It's kinda unnerving since identifying the structure of a heap is so easy by looking at it, but I've been coding for some time and haven't come up with a solution. Of course, I'm not looking for a complete solution, nor any bit of code. Just a nudge in the right direction, some property I can use to solve this.Java Code:public class TreeNode { public TreeNode parent, left, right; }Ever seen a dog chase its tail? Now that's an infinite loop.
Similar Threads
-
Data Structures(Binary Search Tree to AVL Tree)ASAP pls
By jfAdik in forum Forum LobbyReplies: 0Last Post: 04-04-2010, 07:40 AM -
no heap space... need more heap
By anupam.kumar in forum Advanced JavaReplies: 3Last Post: 02-08-2010, 04:42 PM -
Heap memory
By gayathri_g in forum New To JavaReplies: 12Last Post: 09-10-2009, 08:45 AM -
Creating a Tree and then saving the Tree
By jackmatt2 in forum New To JavaReplies: 0Last Post: 08-22-2009, 12:51 PM -
Heap Sort
By kesav2005 in forum Advanced JavaReplies: 1Last Post: 11-13-2007, 11:40 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks