Skip to content

Comments

[TREE] - Custom Generic heap and root builder#3

Merged
thenameisvicky merged 2 commits intomasterfrom
TREE/treeHelpersAndClasses
Oct 12, 2025
Merged

[TREE] - Custom Generic heap and root builder#3
thenameisvicky merged 2 commits intomasterfrom
TREE/treeHelpersAndClasses

Conversation

@thenameisvicky
Copy link
Owner

@thenameisvicky thenameisvicky commented Oct 12, 2025

Problem Description

Implemented generic heap and tree helper function

Type of Problem solved

  • Leetcode Algorithum
  • Engineering Drill

Approach

  • Getting the data type as prop when the heap is initialized.
  • Getting the array and comparator function as prop to constructor, then initialized them.
  • Written Public functions for insert, remove, peek and poll actions.
  • Written Private inner functions to find Parent, left and right Index.
  • Written Private inner functions to bubbleUp and bubbleDown the heap.
  • Used bubbleUp to move the index to it's correct positon according to the compare function received as prop.
  • Used bubbleDown to move the root the first element in the heap to it's correct position according to the comapare function came as prop.
  • For In-depth approach refer the code.

Changes Made

  • Implemented generic heap which can be used accross the functions, it can either be min or max, the heap is determined by the comparator function.
  • Implemented Tree builder to get the Tree node with array as input.

Learnings

  • Learnt about heap and tree structures.

Alternate Approaches

Edge Cases Covered

Make sure to check

Before submitting, please ensure:

  • Code compiles without errors
  • Code follows the existing style guide
  • No console.log statements in strategy
  • Time and space complexity updated in PR
  • Edge cases are handled

Stay Locked In!

@thenameisvicky thenameisvicky merged commit b7a0585 into master Oct 12, 2025
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.

1 participant