# Array Representation

Good Essays
Topics: Reference
Array Representation

A complete binary tree has a simple array representation. Suppose we number the nodes from left to right, beginning at the top and ending at the bottom. Then we can store the various data items in the corresponding elements of an array. For example

can be represented by the array

This in fact corresponds to the level order enumeration of the tree. Note that we only use an initial segment of the array. Provided the array is long enough, and we know the number of tree nodes, it doesn't matter how many unused components there are at the end.

* length[A]: the size of the array * heap-size[A]: the number of items stored into the array A * Note: heap-size[A] <= length[A] * The root of the tree is at A[1], i.e., the indexing typically begins at index 1 (not 0). A[0] can be reserved for the variable heap-size[A].
Heap is implemented as an array, but its operations can be grasped more easily by looking at the binary tree representation. The mapping between the array representation and binary tree representation is unambiguous. The array representation can be achieved by traversing the binary tree in level order.

Figure 1: Binary tree and array representation for the MaxHeap containing elements (that has the priorities) [16,14,10,8,7,9,3,2,4,1].
2.1 Routines to access the array
Lets consider the i:th node in a Heap that has the value A[i] PARENT(i) = i/2 | Return the index of the father node | LEFT(i) = 2i | Return the index of the left child | RIGHT(i) = 2i+1 | Return the index of the right child |
Example 1: In Figure 1, node i=3 (A[3]=10) has father at index PARENT(3) = 3/2 = 1 (A[1] = 16). In addition, its left and right children are at LEFT(3) = 2*3 = 6 and RIGHT(3) = 2*3 + 1 = 7 (A[6] = 9 andA[7] = 3,

## You May Also Find These Documents Helpful

• Satisfactory Essays

Student Name | | Class | Comp230 | Date | 03/04/2013 | Windows CLI Commands Lab Report NOTE: Please use Carriage Returns and Page Breaks as needed to prevent box contents from extending across page boundaries. Task 1: Displaying IP Configuration Settings Open the Windows Command Prompt using the desktop or the Taskbar icon. Maximize the size of the CLI. Use the ipconfig /all command to determine the following IP configuration settings for “Wired” Ethernet NIC: IP Address: | 169…

• 843 Words
• 4 Pages
Satisfactory Essays
• Good Essays

Parallel arrays and arrays of structures An array of structures are usually equivalent to parallel arrays of the components. For example, if each student record consists of an ID number and a GPA value, then a list of students can be represented as an array of structure: The same data can be stored as two arrays that "parallel" to each other, in the sense that the same index in them indicate data for the same student: Usually the first way is more natural and convenient. Advantages and…

• 427 Words
• 2 Pages
Good Essays
• Satisfactory Essays

DERIVED DATA TYPES: REFERENCES, ARRAYS AND POINTERS Krishna M. Singh Department of Mechanical and Industrial Engineering Indian Institute of Technology Roorkee Roorkee 247667 Reference: Deitel and Deitel. C++ : How to Program. Prentice Hall, 2008 Krishna M. Singh, Department of Mechanical & Industrial Engineerig, IIT-Roorkee 1 Fundamental Data Types Basic Types: Boolean, character, integer and floating point types. Additional Types: void : To signify absence of information…

• 326 Words
• 2 Pages
Satisfactory Essays
• Good Essays

1. An array is a list of data items that _____. are of different data types are all integers have different names are indexed | 2. An array that stores five days of closing stock prices can be declared as _____. decimal price1, price2, price3, price4, price5; decimal [] price = new decimal[5]; decimal price[] = new decimal[5]; decimal [] price = new price[5]; | 3. Which statement is true about this array declaration? int [] myArray = {1,4,3,5,6}; It declares a 5 dimensional array…

• 500 Words
• 2 Pages
Good Essays
• Satisfactory Essays

Student Name Class Comp 230 Date VBScript IP Array Report In the space provided below, copy and paste your IP_Array.vbs Program Code. If it doesn’t fit, use the next page for the continuation of your sourcecode program ' VBScript: IP_Array.vbs ' Written by: Student Name ' Date: Today's Date ' Class: COMP230 ' Professor: Professor Name ' =================================== ' Below is an initialize a 2-dimension ' array of IP Address. The first index ' +100 is the room# and the…

• 644 Words
• 5 Pages
Satisfactory Essays
• Good Essays

EE4101 Antenna Arrays 1 Introduction Antenna arrays are becoming increasingly important in wireless communications. Advantages of using antenna arrays: 1. They can provide the capability of a steerable beam (radiation direction change) as in smart antennas. 2. They can provide a high gain (array gain) by using simple antenna elements. 3. They provide a diversity gain in multipath signal reception. 4. They enable array signal processing. Hon Tat Hui 1 Antenna Arrays NUS/ECE EE4101…

• 1346 Words
• 6 Pages
Good Essays
• Good Essays

Tapering of Arrays By Jaydeep Trivedi (09BEC096) And Kedar Trivedi (09BEC097) 1) Introduction: The code shown below is used to show the radiation pattern due to variable no of point sources, variable distance of the point of interest and variable wavelength. This code also determines the locations of all the nulls due to different input fed to the sources. Mostly we will be discussing three different feeding methods: uniform feeding, edge feeding and binomial feeding. 1.1) uniform pattern:…

• 410 Words
• 2 Pages
Good Essays
• Satisfactory Essays

JavaScript arrays, and JavaScript debugging. Startup Start by downloading and extracting a file named ChineseZodiacForLoopStartup.zip. You will find the following files: The Images folder contains 12 images that represent the Chinese Zodiac animals. Notice that some images are in GIF format and others are in PNG format. Chinese_Zodiac_for_loop_1D.html has the code that declares and initializes two arrays. The first array SignNames contains the Chinese Zodiac signs. The second array SignImages contains…

• 531 Words
• 4 Pages
Satisfactory Essays
• Better Essays

use array in c# 5 Introduction In this tutorial I am going to explain about these questions answer below help of example in c# in visual studio 2012. 1. What is array? 2. How to declare an array in c# or How to Initializing Array? 3. How to assigning values to the array in c# ? 4. How to use array in c# with example? 5. How to find even odd numbers in c# using array? What is array? An array is a collection of values of the same data type. The variables in an array are…

• 760 Words
• 4 Pages
Better Essays
• Better Essays

Arrays An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed. You've seen an example of arrays already, in the main method of the "Hello World!" application. This section discusses arrays in greater detail. Each item in an array is called an element, and each element is accessed by its numerical index. As shown in the above illustration, numbering begins with…

• 1094 Words
• 5 Pages
Better Essays