***Welcome to ashrafedu.blogspot.com * * * This website is maintained by ASHRAF***

    Saturday, September 10, 2022

    Array Implementation of Binary Trees

    One of the ways to represent a tree using an array is to store the nodes level-by-level, starting from the level 0.

    Let us consider the complete binary tree


    Disadvantages

    The various demerits when representing binary trees using arrays are as follows:

    1. Other than full binary trees, majority of the array entries may be empty.

    2. Dynamic resizing of array is not possible.

    3. Insertion and deletions of new nodes is inefficient. ( Requires considerable data movement up and down the array, which demand excessive amount of processing time.)

    Advantages

    The various merits of representing binary trees using arrays are as follows:

    1. Any node can be accessed from any other node by calculating the index.

    2. No use of pointers.


    No comments:

    Post a Comment

    Prim’s algorithm for finding MST (Minimum Spanning Tree)

    Prim's algorithm to find minimum cost spanning tree uses the greedy approach. Prim's algorithm, in contrast with Kruskal's algor...