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

Explain b tree (binary tree), B Tree Unlike a binary-tree, every node o...

B Tree Unlike a binary-tree, every node of a B-tree may have a variable number of keys and children. The keys are stored in non-decreasing order. Every key has an associated ch

Trees, What is AVL Tree? Describe the method of Deletion of a node from and...

What is AVL Tree? Describe the method of Deletion of a node from and AVL Tree ?

..#title, whate is meant by the term heuristic

whate is meant by the term heuristic

Effective way of storing two symmetric matrices, Explain an efficient and e...

Explain an efficient and effective way of storing two symmetric matrices of the same order in the memory. A n-square matrix array will be symmetric if a[j][k]=a[k][j] for all j

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

Algorithm to delete the specific node from binary searchtree, Q. Write down...

Q. Write down an algorithm to delete the specific node from binary search tree. Trace the algorithm to delete a node (10) from the following given tree. Ans. Algor

Physical database design and sql queries, In this part, students are allowe...

In this part, students are allowed to implement the following simplifications in their table and data design. o Availability for the beauty therapists don't have to be considere

Implementation of multiple queues, Thus far, we have seen the demonstration...

Thus far, we have seen the demonstration of a single queue, but several practical applications in computer science needs several queues. Multi queue is data structure in which mult

Accept a file and form a binary tree - huffman encoding, Huffman Encoding i...

Huffman Encoding is one of the very simple algorithms to compress data. Even though it is very old and simple , it is still widely used (eg : in few stages of JPEG, MPEG etc). In t

Efficiency of binary search, Each of the comparison in the binary search de...

Each of the comparison in the binary search decrease the number of possible candidates where the key value can be searched by a factor of 2 as the array is divided into two halves

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