## 18 Replies - 834 Views - Last Post: 30 December 2018 - 09:43 AM

### #1

# data structure heap of one single node concept!

Posted 29 December 2018 - 12:11 PM

Hi please don't close this thread because I have already posted a thread on the same subject and who closed it claiming that I need to code and show some effort .. to code what?! I don't know what he's meaning !! I need to understand the concept of single node of heap, I don't know what code to show.. I'm asking on the concept why single node is immediately already a heap!

thanks

##
**Replies To:** data structure heap of one single node concept!

### #2

## Re: data structure heap of one single node concept!

Posted 29 December 2018 - 12:19 PM

Quote

> Software Development

> Computer Science

https://www.dreaminc...mputer-science/

Are you asking why a single node, the root only, satisfies the min/max tree requirements?

One would figure a single root node is both the smallest, and largest, element in the tree.. as it is the only element in the tree!

https://en.wikipedia...ki/Min-max_heap

### #3

## Re: data structure heap of one single node concept!

Posted 29 December 2018 - 01:07 PM

sepp2k, on 29 December 2018 - 09:39 AM, said:

- For all children c of n, it must be true that n.value >= c.value.
- There must be no child c of n, such that n.value < c.value.
- In the set containing the node n and all of its children, n's value must be the maximum in the set.

I think it's easiest to see why version 3 is true for nodes without children: If you have a set containing only one value, then that value is obviously the maximum in that set. It should also be intuitive that this is equivalent to the other two versions: Saying x is the maximum of a given set is the same as saying that there's no y in the set such that x < y or that for all ys in the set x >= y.

Another way to approach this would be to realize that the statement "there is no element x in the set X, such that ... whatever" is always true if X is the empty set - regardless of which condition you substitute for "whatever". It's already true without any condition ("there is no element x in the set X" is true for the empty set X) and adding an additional condition on the elements of X that we consider isn't going to affect anything.

By the same logic, any universally quantified (i.e. "for all") statement about the empty set must also be true since "for all elements x in X, foo(x) must be true" and "there must be no element x in X, such that foo(x) is false" are equivalent statements and the latter is obviously true for empty sets.

This concept is also known as vacuous truth.

### #4

## Re: data structure heap of one single node concept!

Posted 29 December 2018 - 01:16 PM

now I can reply to his reply..

Can you please explain the another approach you declared? it's still a lil not comprehended, you mean whenever there's empty set then any condition will satisfy it? if yes then why?! thanks !

This post has been edited by **Skydiver**: 29 December 2018 - 05:33 PM

Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

### #5

## Re: data structure heap of one single node concept!

Posted 29 December 2018 - 01:18 PM

### #6

## Re: data structure heap of one single node concept!

Posted 29 December 2018 - 02:12 PM

This post has been edited by **Skydiver**: 29 December 2018 - 05:34 PM

Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

### #7

## Re: data structure heap of one single node concept!

Posted 29 December 2018 - 02:21 PM

The answer to both of these questions is 3. We don't need an additional element to compare. The definitions of minima and maxima don't require the values of x and y to be distinct.

### #8

## Re: data structure heap of one single node concept!

Posted 29 December 2018 - 02:38 PM

what's actually confusing me that if there's two elements like {3,4} the biggest element is 4 so its the maximal because its greater from 3 !.. here all fine !!

now about this {3} its biggest element so its the maximal because its greater from________ ? you got my point?!

This post has been edited by **Skydiver**: 29 December 2018 - 05:34 PM

Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

### #9

## Re: data structure heap of one single node concept!

Posted 29 December 2018 - 02:39 PM

Note that there is nothing in the definition saying that y != x.

Quote

No. See my previous post.

Also, there is no need to quote the post above you. There is a Reply button at the bottom of every page.

### #10

## Re: data structure heap of one single node concept!

Posted 29 December 2018 - 02:47 PM

min or max value is the smaller/greatest value in the list ! specifically if there's one single value then immediate it's the minimal/max value found in the list !

thanks !

This post has been edited by **macosxnerd101**: 29 December 2018 - 02:48 PM

Reason for edit:: There is no need to quote the post above yours

### #11

## Re: data structure heap of one single node concept!

Posted 29 December 2018 - 02:51 PM

Quote

You are rambling again. This doesn't make any sense.

### #12

## Re: data structure heap of one single node concept!

Posted 29 December 2018 - 02:51 PM

meaning to find max, I ask myself what's the greatest value among the others? but if there's no others then we just pass the value itself?

thanks

### #13

## Re: data structure heap of one single node concept!

Posted 29 December 2018 - 02:53 PM

### #14

## Re: data structure heap of one single node concept!

Posted 29 December 2018 - 03:29 PM

Quote

If there is no other values then that single number is the greatest.

If you need the crutch then look.. if you have one number by itself you would compare it to an empty set of number. A value compared to that empty set is the max and is the minimum.

This isn't some philosophy class where 'things can only be known when compared and cannot exist in a vacuum'.

### #15

## Re: data structure heap of one single node concept!

Posted 29 December 2018 - 03:31 PM

Quote

This is why definitions are helpful. Start with the definition. Take an ordered set S with a single element. Show that the single element in S satisfies the definition of a maximal element.