Array vs. ordinary variable, Data Structure & Algorithms

Q. Describe what do you understand by the term array? How does an array vary from an ordinary variable? How are the arrays represented in the specific memory?                                    

Ans.

Array Vs. Ordinary Variable is explained as follows

Array is made from the similar data structure that exists in any language. Array is the set of similar or alike data types. Array is the collection of similar or alike elements. These similar or alike elements could be all int or all float or all char etc. Array of char is called as string. All elements of the given array should be of same type. An array is finite ordered set of the homogeneous elements. The number of elements in the array is pre- determined.

For example.  Ordinary variable: - int a

Array:      -      int a[10]

An ordinary variable of a simple data type can save a single element only

Representation of Array in memory is shown below

Assume a be a 2 dimensional m x n array

 

 

Col 0

Col 1

Col 2

 

Row 0

 

a00

 

a01

 

a02

 

Row 1

 

a10

 

a11

 

a12

 

Row 2

 

a20

 

a21

 

a22

 

Though  a  is  pictured  as  a  rectangular pattern  with  in  row  and  n  column  it  is represented in memory or a particular location by a row of m x n  elements. Sequential memory locations the element can be saved in row major order.

Column major order is explained as follows:- the elements are saved column by column i.e. m elements of the 1st column is saved in first m locations, elements of the 2nd column are saved in next m location and so on..

1545_column major.png

Row major order is shown below:-

The elements are saved row by row ie. N elements of the 1st row are saved in 1st n location, elements of 2nd row are saved in next n location, and so on

1808_row major.png

Posted Date: 7/13/2012 2:03:12 AM | Location : United States







Related Discussions:- Array vs. ordinary variable, Assignment Help, Ask Question on Array vs. ordinary variable, Get Answer, Expert's Help, Array vs. ordinary variable Discussions

Write discussion on Array vs. ordinary variable
Your posts are moderated
Related Questions
Here is a diagram showing similarities between documents; this is an actual set of physics lab assignments from a large university. Each node (square) in the graph is a doc

what is hashing? what are diffrent method of hashing?

AVL tree An AVL tree is a binary search tree in which the height of the left and right subtree of the root vary by at most 1 and in which the left and right subtrees are again

CMY Model  The cyan, magenta, yellow (CMY) colour model is a subtractive model based on the colour absorption properties of paints and inks. As such it has become the standard

Compare zero-address, one-address, two-address, and three-address machines by writing programs to compute: Y = (A – B X C) / (D + E X F) for each of the four machines. The inst

Game trees An interesting application of trees is the playing of games such as tie-tac-toe, chess, nim, kalam, chess, go etc. We can picture the sequence of possible moves by m

Varieties of Arrays In some languages, size of an array should be established once and for all at program design time and can't change during execution. Such arrays are known a

1) preorder, postorder and inorder 2) The main feature of a Binary Search Tree is that all of the elements whose values is less than the root reside into the nodes of left subtr

Binary Space Partition A binary space-partitioning (BSP) tree is an efficient method for determining object visibility by painting surfaces onto the screen from back to front,

Explain the bubble sort algorithm. Answer This algorithm is used for sorting a list. It makes use of a temporary variable for swapping. It compares two numbers at an insta