Hi I have studied min heap and max heap and I have these questions that

```
- a sorted array is a min heap?
- where is the minimum value of a max heap?
```

please help me thanks {if you put some link I will be so glad}

An array sorted from lowest to highest is a min-heap when using the array-based heap implementation. The heap property that the parent node is greater than it's child nodes (2i + 1 and 2i + 2, using zero-based arrays) holds for all nodes that have children.

The minimum value of a max heap is in one of the leaf nodes, but you don't know which. Since the minimum node cannot, by definition, have any child nodes, it must be a leaf. The heap property, however, does not specify how leaf nodes compare with each other, only with their parent.

- a sorted array is a min heap?

Yes, if you're using the typical array-stored heap convention.

- where is the minimum value of a max heap?

At one of the leafs. Which exactly is undefined.

You can implement binary heap as a array for index i compare with 2*i+1 and 2*i+2 (i starts from 0). in min heap a[i] < a[2*i+1] and a[i] < a[2*i+2]

so

1 . A sorted array is a min heap.

2 . It hasn't specific index. All we know that it is just a leaf

I suggest you read this http://en.wikipedia.org/wiki/Binary_heap

where is the minimum value of a max heap?

Ans: Max heap can be represented using simple array with index start from 1 to n. 1st element is the root of the max heap. Heap property: The node at index i has left child at 2i and right child at 2i+1 (if 2i and 2i+1 are less than heap size i.e. array length).

Leaf nodes of the max heap are found from index i+1 to n. Here i=n/2; n is array length. And one of the leaf nodes has the minimum value.

So we can find the minimum value of max heap from the values of a[i+1] to a[n]. Time complexity to find minimum value is order-of(n-i).

- a sorted array is a min heap?

If it is ordered ascending - yes, generally speaking it is a min heap, more precisely - an **array implementation of a binary heap** with the following rules:

- Children of the node with index
*i*can be found at indexes*2i + 1*and*2i + 2* - The parent of the node with index
*i*can be found at index*floor((i - 1)/2)*

At the same time, it doesn't work in reverse - an array-based binary heap will not store a sorted list.

- where is the minimum value of a max heap?

It is not defined, and it is not the question that you want to answer quickly when you store your keys in a min heap. If you want to be able to peek both min and max of the heap in O(1) time, you can use classes like MinMaxPriorityQueue in Java.

Similar Questions

I'm sitting here looking at an algorithm for deleting the root node in a binary max heap, and then update the tree with a new root. Here's how it looks: if (n==0) { empty = true; } else { empty = fals

I've got some code that continuously extracts the max valued object from a heap and processes it. However, during processing of the max, other objects in the heap are affected, and may need to get del

There's a max_heap_table_size limit to 16 mb so how can i change this value and where?

I'm trying to implement a skew heap in C, but my code doesn't compile. I'm not that experienced in C and never created any type of heap in C. That is why I don't know how to fix it, I'm hoping someone

I am trying to create a Max-Heap in java using the following code: public class Heapify { // 16 14 10 8 7 9 3 2 4 1 public static int[] Arr = {4, 1, 3, 2, 16, 9, 10, 14, 8, 7}; public static int count

Hi I have this question that in the heap data structure , a left child can be more than a right child in its own level ? I mean that consider these three numbers 9,5,8 and I want to make a max-heap da

I am launching a java jar file which often requires more than the default 64MB max heap size. A 256MB heap size is sufficient for this app though. Is there anyway to specify (in the manifest maybe?) t

How do I set Java's min and max heap size through environment variables? I know that the heap sizes can be set when launching java, but I would like to have this adjusted through environment variables

I'm trying to figure out why I am getting an OOM error even though the byte array I am initializing plus the currently used memory is less than the max heap size (1000MB). Right before the array is in

I wonder if I can obtain the maximum size of the allocated heap using VM command line. From now I'm able to get it using Netbeans Profiler but I prefer getting result without have to launch an extra a

For an assignment I need to implement Dijkstra's algorithm using a priority queue implemented as a min heap. I already have an implementation in which I use a distance table and an unordered array of

I'm having trouble getting the native heap information from my HTC Magic running Android 2.2.1. I've configured the standalone DDMS setting native=true and used the commands: adb shell setprop libc

Are there examples of recursion using only heap area?

Trying to reproduce Heap's algorithm, for generating all possible permutations of an array of integers, but I can't solve it for other integers than three. Heap's algorithm from Wikipedia: procedure

Does Windows Phone have a limit on the amount of heap memory an app can use? Android has a heap limit of 24 mb. Does WP7 have a similar limit on heap?

Problem: I run mvn clean install -DskipTest and get [ERROR] The system is out of resources. [ERROR] Consult the following stack trace for details. [ERROR] java.lang.OutOfMemoryError: Java heap space

A program has three sections: text, data and stack. The function body lives in the text section. Can we let a function body live on heap? Because we can manipulate memory on heap more freely, we may g

My JVM heap max is configured at 8GB on the name node for one of my hadoop clusters. When I monitor that JVM using JMX, the reported maximum is constantly fluctuating, as shown in the attached image.

I have a small understanding problem with the heap in c++. I have created a small class to convert a Wchar_t-Array to a Char-Array. Here is a part of my convert class: .h class ConvertDataType { priva

I know how to sort in place an array using heapsort and max-heap property. But I can not think of how I could sort it in place using the min-heap property. I can sort it using a min-heap by using a t

I have been trying to get webstart to dump to a heap dump when it runs out of memory. I know the jmap/jconsole way of doing it, but what I really want to do is add the option to jnlp file and have tri

I have a Node class with the members int weight; Node *left; Node *right; I want to create a heap by using the STL functions make_heap(Iterator , Iterator, comp) pop_heap(Iterator, Iterator, comp)

I am working on a homework problem that involves a heap sort implementation in java. Here is what I have so far public class HeapSort { public static void maxHeapify(int[] a, int i) { int largest; int

I'm trying to create a Binary Min Heap in C using arrays. I wrote the code and tried multiple times to execute it with pen and paper and it seems to work. Can you please help me to understand why it

I am trying to build a min heap. I have already done the insert, delete,swap, up-heap, down-heap and it is working correctly. However, I am trying to write a method for Min-Heapify. Here is my Input:

Following code for max-heap implementation #include<iostream> #include<math.h> using namespace std; #define maxn 1000 int x[maxn]; int parent(int i){ return int(i/2); } int left(int i){ re

From the Soft Heap wikipedia page, it seems that the min extraction only takes constant time, thus using a soft heap to perform heapsort should lead to an amortized O(n). Even if the constant is large

I need your help trying to figure out/getting an approach to a simple proof. Suppose you are given a max-heap with n different elements and x is an element in the heap in deep D (in the tree represent

I work with Java 1.7 and I want to print Heap Dump from java ... Object heapDump=.... ; ... System.out.println(heapDump); Can anybody help me?

I want to Find Maximum number of comparison when convert min-heap to max-heap with n node. i think convert min-heap to max-heap with O(n). it means there is no way and re-create the heap.

I am getting a heap corruption error when trying to compile my program. The code in question is a pointer cparticle * particles. It is initialized to NULL and then set to particles = new cparticle[a

I have this code for a heap tree and I'm stuck with the iterators. I need in-order, pre-order and post-order iterators, but I have no idea how to do it. If someone has an idea or example please help.

Is it possible to view the heap and stack during debugging?

Is there any way to hide the options -Xmx and -Xmx from user? I mean don't let the user play with the java heap size. Set a X amount of max/min heap size for all the Java app. I tried to find some ki

Is there any way to figure out which application is using up all the desktop heap memory? For an explanation of 'desktop heap' see this MSDN blog. EDIT: If you don't know what desktop heap memory is

I'm trying to simulate memory exaustion. So here is what I'm thinking: turn off over commiting. reduce the available heap so that the memory exaustion can happen quicker. Run the program under test.

Is there a way to set the max java heap size programatically instead of as a vm argument? Something like: System.getProperties().put(<heap variable>, 1000m);

Is there any approach to estimating the insertion depth of a node in a d-heap that is able to beat (node_value / heap_max) * h, where h is the heap height, and heap_max is normalized to the heap minim

Assume we got 2 diffrent Heaps - first heap is a min heap and second heap is a max heap ,together, they contain n diffrent elements, with not nessecerly diffrent keys, I need to delete element x, whic

I'm in a beginner level computer programming class and I (along with 3 other students) want to implement a Fibonacci heap for a final project. Can anyone suggest some good applications of fibonacci he

I've tried to build a very minimalistic memory read library to read some unsigned ints out of it. However, I run into a HEAP CORRUPTION DETECTED error message when the ReadUnsignedInt method wants t

I am trying some heapsorting in java for fun. First, I create a max-heap. Then take the first element to variable max, move the last item from unarranged array to the heap top, and then push down. I t

I am having some problems with my program and getting this error : HEAP CORRUPTION DETECTED: before Normal block (#9873672) at 0x00968988. CRT detected that the application wrote to memory before star

I have a Java application, which is throwing Java Heap size Memory error. My application is about converting a file into .csv format and load it into DB. When the File content is less my application i

How to set java heap size and check it manually?

I've been working on a Fibonacci Heap implementation in Java for about a week now. It's the implementation based off of the CLRS book. I wanted to see if I would get any performance boost using it in

Saw this question somewhere in the internet and tried to solve it. I could solve it for cases where the heap is a strictly binary tree (by repeatedly partitioning the preorder traversal) but could not

I have read various posts in stackoverflow and I am trying to figure out how to increase my heap size for my JVM. I know that the command -vmargs -Xms256m -Xmx4096m will increase the heap size. But it

I'm inspecting running times, heap memory usage and non-heap memory usage of different algorithms to a specific sorting problem. I've successfully been able to measure running time and heap memory usa

Doesnt' have to be java, but I'm trying to understand the merging process for a skew heap. I don't get why the part in bold below in the steps is the way it is. Compare roots of two heaps; let p be