Skip to content

Add binary heap (min-heap) implementation in R#296

Merged
siriak merged 2 commits into
TheAlgorithms:masterfrom
sora16bit:add-binary-heap
Jun 12, 2026
Merged

Add binary heap (min-heap) implementation in R#296
siriak merged 2 commits into
TheAlgorithms:masterfrom
sora16bit:add-binary-heap

Conversation

@sora16bit

Copy link
Copy Markdown
Contributor

Description

Adds a binary heap (min-heap) implementation to the data_structures directory.

The heap is represented as a plain R vector using value-passing semantics,
consistent with the existing simple data-structure implementations in the repo.

Operations

  • push(heap, value) — insert a value and sift up — O(log n)
  • pop(heap) — extract the minimum and sift down — O(log n), returns list(value, heap)
  • peek(heap) — view the minimum without removing it — O(1)

Checklist

  • Not already implemented in the repository (BST exists, but a heap is a different structure)
  • Recognized CS data structure (not a LeetCode-specific adaptation)
  • Lowercase .r file extension
  • Docstring with explanation, complexities, applications, and usage example
  • Runs without errors and produces expected output

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new data_structures/binary_heap.r script implementing a vector-backed min binary heap in R, intended to support priority-queue style usage consistent with other simple data-structure scripts in this repository.

Changes:

  • Introduces push(heap, value), pop(heap), and peek(heap) operations for a min-heap stored in a plain R vector.
  • Adds inline documentation describing heap properties, complexities, applications, and example usage.

Comment thread data_structures/binary_heap.r
Comment thread data_structures/binary_heap.r
Comment thread data_structures/binary_heap.r Outdated
Comment thread data_structures/binary_heap.r

@siriak siriak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address Copilot's comments

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread data_structures/binary_heap.r
Comment thread data_structures/binary_heap.r
Comment thread data_structures/binary_heap.r

@siriak siriak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@siriak siriak merged commit f65344f into TheAlgorithms:master Jun 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants