# Create a heap for array with weights

**URL:** <https://discourse.julialang.org/t/create-a-heap-for-array-with-weights/41581>\
**Category:** New to Julia\
**Tags:** data\_structures\
**Created:** [June 17, 2020, 8:33am UTC](https://discourse.julialang.org/t/create-a-heap-for-array-with-weights/41581 "2020-06-17T08:33:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yusri-dh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yusri-dh/32/7404_2.png) [@yusri-dh](https://discourse.julialang.org/u/yusri-dh)\
**Post date:** [June 17, 2020, 8:33am UTC](https://discourse.julialang.org/t/create-a-heap-for-array-with-weights/41581/1 "2020-06-17T08:33:29Z")

</div>

Suppose that I have an array

```julia
X = ["a","b","c","d"]

```

with the corresponding weights

```julia
weight = [1,4,3,2]

```

How can I make heaps of X using weight

```julia
using DataStructures
weight_heaps =BinaryMaxHeap(weight)
# What I want to do
X_heaps = BinaryMaxHeap(X,weight=weight)

```

I can not find it in the DataStructures package documentation. Thank you so much.

---

<div class="post-metadata">

**Author:** ![robsmith11](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/robsmith11/32/29641_2.png) [@robsmith11](https://discourse.julialang.org/u/robsmith11)\
**Post date:** [June 17, 2020, 9:22am UTC](https://discourse.julialang.org/t/create-a-heap-for-array-with-weights/41581/2 "2020-06-17T09:22:20Z")

</div>

> [@yusri-dh](#):
>
> `BinaryMaxHeap`

So you want a heap with associated data? Perhaps you’re looking for a priority queue:

[https://juliacollections.github.io/DataStructures.jl/latest/priority-queue/](https://juliacollections.github.io/DataStructures.jl/latest/priority-queue/)

---

<div class="post-metadata">

**Author:** ![yusri-dh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yusri-dh/32/7404_2.png) [@yusri-dh](https://discourse.julialang.org/u/yusri-dh)\
**Post date:** [June 19, 2020, 2:11am UTC](https://discourse.julialang.org/t/create-a-heap-for-array-with-weights/41581/3 "2020-06-19T02:11:48Z")

</div>

Thank you so much, this solve my problem.
