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
for (i = 0; i sequence of statements } Here, the loop executes n times. Thus, the sequence of statements also executes n times. Since we suppose the time complexity of th

Loops There are 3 common ways of performing a looping function: for ... to ... next, while ... endwhile and repeat ... until The below example input 100 numbers and find

how to implement prims algorithm dynamically

Which data structure is required to change infix notation to postfix notation?    Stack function is used to change infix notation to postfix notatio n

Queue is a linear data structure utilized in several applications of computer science. Such as people stand in a queue to get a specific service, several processes will wait in a q

Suppose we have a set of N agents and a set of N tasks.Each agent can only perform exactly one task and there is a cost associated with each assignment. We would like to find out a

Question 1 . Give the structure of PL/SQL Blocks and explain Question 2 . Differentiate between PL/SQL functions and procedures Question 3 . Explain the following Par

Worst Case: For running time, Worst case running time is an upper bound with any input. This guarantees that, irrespective of the type of input, the algorithm will not take any lo

application of threaded binary treee

pls i want a psuedo code for hotel reservation system.