Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 200551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:07:18+00:00 2026-05-11T17:07:18+00:00

What kind of math do you use to traverse the 4-heap when using an

  • 0

What kind of math do you use to traverse the 4-heap when using an array to store all the elements? Specifically, how do you find the index of a parent node to a specific leaf?

Let’s say I have the following array:

0|1|2|3|4|5|6|7|8|9|10|… etc.

with the heap then constructed from that with 1 being the root, 2..5 its children, 6..9 2’s children etc.

What exactly is the math i need if I need to find (for example) the parent of 6?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:07:18+00:00Added an answer on May 11, 2026 at 5:07 pm

    To find the parent of any child (other than 1, which has no parent):

    parent = int((child + 2) / 4)
    

    To find the first and last child of a parent:

    child_first = parent * 4 - 2
    child_last  = parent * 4 + 1
    

    You can see this in operation since, at each level, you add four times as many elements as you did in the previous level:

      1           (   1)
      2 thru    5 (   4)
      6 thru   21 (  16)
     22 thru   85 (  64)
     86 thru  341 ( 256)
    342 thru 1365 (1024)
    
    Level 1:
    1 -> 2 3 4 5
    
    Level 2:
    2 ->  6  7  8  9
    3 -> 10 11 12 13
    4 -> 14 15 16 17
    5 -> 18 19 20 21
    
    Level 3:
     6 -> 22 23 24 25
     7 -> 26 27 28 29
     8 -> 30 31 32 33
     9 -> 34 35 36 37
    10 -> 38 39 40 41
    11 -> 42 43 44 45
    12 -> 46 47 48 49
    13 -> 50 51 52 53
    14 -> 54 55 56 57
    15 -> 58 59 60 61
    16 -> 62 63 64 65
    17 -> 66 67 68 69
    18 -> 70 71 72 73
    19 -> 74 75 76 77
    20 -> 78 79 80 81
    21 -> 82 83 84 85
    

     

    Level 4:
     22 ->  86  87  88  89
     23 ->  90  91  92  93
     24 ->  94  95  96  97
     25 ->  98  99 100 101
     : : : :
     82 -> 326 327 328 329
     83 -> 330 331 332 333
     84 -> 334 335 336 337
     85 -> 338 339 340 341
    

    Examples are:

    parent of 342 = int(344/4) = 86 (same for 343,344,345).
    parent of 346 = int(348/4) = 87 (same for 347,348,349).
    first child of 21 = 21 * 4 - 2 = 82
    last  child of 21 = 21 * 4 + 1 = 85
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Kind of like this question I have many text snippets that I use many,
Kind sirs, I'm using Codeigniter to build a blog. I might need a way
Which regular expression can I use to match (allow) any kind of letter from
I am writing a small utility for calculating a complicated mathematical formula (using commons-math
I'd like to get an idea what kind of math is typically necessary for
I want to to math operations with some kind of prepared formula that would
This is my first time building an iOS project using any kind of advanced
Kind of a follow up to a question from yesterday. I have a hash
Kind of need help understanding what this code actually outputs. Does it out put
Kind of a ruby-noob active record query question: Magazine has_many :subscriptions User has_many :subscriptions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.