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

  • Home
  • SEARCH
  • 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 6636853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:14:18+00:00 2026-05-25T23:14:18+00:00

I have seen array based implementations of static binary trees which do not waste

  • 0

I have seen array based implementations of static binary trees which do not waste memory for pointers and instead do operations on the current index to go to its parent or children. Is there any articles that talk about similar methods for binary trees where you will have to insert or delete. I can see that array will no longer be useful for this unless you have an upper bound on the number of insertions that are allowed.

  • 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-25T23:14:19+00:00Added an answer on May 25, 2026 at 11:14 pm

    It’s always possible to build a binary tree in an array, using simple arithmetic to find child nodes from the parent. A common method (particularly for binary heaps) is to use the following…

    left_child_index  = (2 * parent_index) + 1
    right_child_index = (2 * parent_index) + 2
    

    So the root node at 0 has children at 1 and 2, the node at 1 has children at 3 and 4 etc.

    The downside of this scheme is that while you gain space by not storing pointers, you generally lose space by needing to leave gaps in the array for unused nodes. Binary heaps avoid this by being complete binary trees – every node in the range for the current number of items is valid. This works for heaps, but cannot work for binary search tree operations.

    As long as you can resize your arrays (e.g. std::vector in C++), you don’t need to place an upper bound on the number of inserts, but you can end up with a lot of gaps in the deeper parts of your array, especially if the tree gets unbalanced.

    You also need some way to determine if a position in the array contains a valid node or not – either a flag or a data value that cannot occur in a valid node. Flags could potentially be stored as a packed bit-array, separate from the main nodes.

    Another disadvantage is that restructuring the tree means moving data around – not just adjusting pointers. Pointer rotations (needed for many balanced binary trees, such as red-black trees and AVL trees) become potentially very costly operations – they don’t just need to move the usual three nodes, but the entire subtree descended from the rotated nodes.

    That said, if your items are very small, and if either your tree will stay small or you’re OK with a simple unbalanced tree, it’s just about possible that this scheme could be useful. This could just about be plausible as a set-of-integers data structure, maybe.

    BTW – “plausible” doesn’t mean “recommended”. Even if you manage to find a case where it’s more efficient, I’d find it hard to believe the development time was justified.

    Possibly more useful…

    Multiway trees contain small arrays of items in each node, rather than the usual one key. They are most often used for database indexes on hard disk. The most well known are B trees, B+ trees and B* trees.

    Multiway trees have child node pointers, but for a node that can hold at most n keys, the number of child pointers is typically either n or n+1 – not twice n. Also, a common strategy is to use different node layouts for branch and leaf nodes. Only branch nodes have child pointers. Every data item is in a leaf node, and only leaf nodes contain non-key data. Branch nodes are purely used to guide searches. Since leaf nodes are by far the most numerous nodes, not having child pointers in them is a useful saving.

    However – multiway tree nodes are rarely packed full. Again, there’s a space overhead for unused array slots. The usual rule is that every node (except the root) must be at least half full. Some implementations put quite a bit of effort into avoiding splitting nodes, and thereby minimizing space overheads, but there is generally an expected overhead roughly proportional to the number of items.

    I’ve also heard of a form of tree that holds multiple keys per node, but only has two child pointers per node. I can’t even remember what this is called, I’m afraid.

    It’s also possible to store (parent pointer, child pointer) pairs in a separate data structure. This is fairly common for representing trees in databases, using a table of (parent ID, child ID) pairs, or a table of (parent ID, sibling index, child ID) triples or whatever. One advantage is that you don’t need to store the ‘null’ pointers.

    However, possibly the best option, rather than trying to reduce or eliminate the overhead for storing pointers, is to put that overhead to better use. Threaded binary trees make better use of child pointers for supporting efficient traversals of the tree – http://en.wikipedia.org/wiki/Threaded_binary_tree.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little bit seen the representation of an array in memory with
I have seen different approaches to define a static array in Java. Either: String[]
I have seen examples of printing from a windows application but I have not
I have seen many times things like this: function customArrayIndexOf(item, array){ for (var i
I have a custom class in Obj-C called RouteManager which contains an array of
I have seen questions similar to this, but not one directly addressing the issue.
I have a TCHAR array in my C++ code which I want to assign
Possible Duplicate: Array of zero length I have seen such type of code :-
Have seen some similar questions: What is the difference between a JavaBean and a
I have seen lots of questions recently about WPF... What is it? What does

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.