If I have an array of entries 5, 10, and 20.

How many heaps are there for each?

Since there are two sorting algorithms, bottom-up and top-down,

Are there 2 heaps for each entries?

Help me guys :D

Your question makes very little sense. I think you have a confused idea of "heap". There are two things that are commonly referred to as a "heap".

Formally, a heap is a type of data tree-structure typically used for implementing a priority queue. Wiki.

Colloquially, people say "heap-allocated memory" or "memory from the heap", when they really should be saying "dynamically allocated memory". Wiki. The reason people use the term "heap" is because every program is assigned an entity that manages the dynamic allocation of the memory for the program, and that entity is (almost) always implemented using a heap data structure (or something very similar). Now, using the term "heap" to designate the entity that allocates dynamic memory has become ubiquitous in programming vocabulary, compiler/software error reports and operating system functions.

So, in light of the above, for your questions:
>>How many heaps are there for each?
There is one heap per process (exe or dll running). So, if those arrays are all in the same program, there is just one heap. That question makes no sense.

>>Since there are two sorting algorithms, bottom-up and top-down,
I would assume only one is used (or maybe a dual version). This is implementation specific, and it shouldn't be of any concern to you.

>>Are there 2 heaps for each entries?
Again, no. There is one heap, regardless of what you allocate on in, there is always just one (that is, one per running program).

To complicate it a little more, the main program and DLL each have their own heaps (and memory managers), and that's why memory allocated in a DLL can not be released in the main program (or another DLL) and vice versa. I'm not sure if shared libraries on *nix work that way.

This article has been dead for over six months. Start a new discussion instead.