Array and two-dimensional array, Data Structure & Algorithms

Assignment Help:

Q. Describe the term array.  How do we represent two-dimensional arrays in memory?  Explain how we calculate the address of an element in a two dimensional array.                                                

Ans:

An array is a systematic arrangement of objects generally in rows and columns

Each memory location is defined by an array element. An array element is similar to one variable except it is identified by an index value as a substitute of a name. An index value is a number used to recognize an array element.

Declaration of a two dimensional array- A two dimensional array is declared similarly as we declare a one-dimensional array except that we specify the number of elements in both dimensions. Such as,

int grades[3][4];

The first bracket ([3]) tells the compiler that we are declaring 3 number of pointers, each of them pointing to an array. Here we are not talking about a pointer variable or pointer array. Instead of that, we are saying that each element of the first dimension of a two dimensional array reference a corresponding second dimension. In the above example, all the arrays pointed to by the first index are of the same size. The second index may be of variable size. For example, the earlier statement declares a two- dimensional  array  where  there  are  3  elements  in  the  first  dimension  and  4 elements in the second dimension array.

Two-dimensional array can be represented in memory by following two ways:

1.  Row major representation: To attain b this linear representation, the first row of the array is stored in the first memory locations reserved for the array, then the second row and this process continues.

2.  Column major representation: In this elements of the column are stored next to one another.

In row major representation, the address is always calculated in a two dimensional array as per the formula written below. The address of a[i][j]=base(a)+(i*m+ j)*size in which base(a) is the address of a[0][0], m is second dimension of array a and size represent size of the data type.


Related Discussions:- Array and two-dimensional array

Applications of linear and binary search, The searching method are applicab...

The searching method are applicable to a number of places in current's world, may it be Internet, search engines, text pattern matching, on line enquiry, finding a record from data

#title., Ask quapplication of data structure estion #Minimum 100 words acce...

Ask quapplication of data structure estion #Minimum 100 words accepted#

Define a b-tree, Define a B-Tree Justas AVL trees are balanced binary s...

Define a B-Tree Justas AVL trees are balanced binary search trees, B-trees are balanced M-way search trees. A B-Tree of order M is either the empty tree or it is an M-way searc

Demonstrate that dijkstra''s algorithm, Demonstrate that Dijkstra's algorit...

Demonstrate that Dijkstra's algorithm does not necessarily work if some of the costs are negative by finding a digraph with negative costs (but no negative cost dicircuits) for whi

Explain stacks, What are stacks? A stack is a data structure that organ...

What are stacks? A stack is a data structure that organizes data similar to how one organizes a pile of coins. The new coin is always placed on the top and the oldest is on the

How conquer technique can be applied to binary trees, How divide and conque...

How divide and conquer technique can be applied to binary trees?  As the binary tree definition itself separates a binary tree into two smaller structures of the similar type,

Ruby implementation of the symbol abstract data type, Ruby implementation o...

Ruby implementation of the Symbol ADT Ruby implementation of the Symbol ADT, as mentioned, hinges on making Symbol class instances immutable that corresponds to the relative la

Linear array - numerical, Q. A linear array A is given with lower bound as ...

Q. A linear array A is given with lower bound as 1. If address of A[25] is 375 and A[30] is 390, then find address of A[16].

Explain memory allocation strategies, Memory Allocation Strategies If i...

Memory Allocation Strategies If it is not desirable to move blocks of due storage from one area of memory to another, it must be possible to relocate memory blocks that have be

Explain about hidden-surface, Explain about Hidden-surface Hidden-line...

Explain about Hidden-surface Hidden-line removal refers to wire-frame diagrams without surface rendering and polygonal surfaces with straight edges. Hidden-surface removal ref

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd