10.09.2013 Views

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

LECTURE NOTES OF ADVANCED DATA STRUCTURE (MT-CSE 110)<br />

(remember that array indices always begin by zero).<br />

Multidimensional arrays are not limited to two indices (i.e., two dimensions).<br />

They can contain as many indices as needed. But be careful! The amount of<br />

memory needed for an array rapidly increases with each dimension.<br />

For example:<br />

char century [100][365][24][60][60];<br />

declares an array with a char element for each second in a century, that is more<br />

than 3 billion chars. So this declaration would consume more than 3 gigabytes<br />

of memory!<br />

Address Calculations in One‐dimensional arrays<br />

The one dimensional arrays are also known as Single dimension array and is a<br />

type of Linear Array. In the one dimension array the data type is followed by the<br />

variable name which is further followed by the single subscript i.e. the array can<br />

be represented in the row or column wise. It contains a single subscript that is<br />

why it is known as one dimensional array because one subscript can either<br />

represent a row or a column.<br />

The address of a particular element in a one‐dimensional array is given by the<br />

relation:<br />

Address of element a[k] = B+W*K<br />

Where B is the base address of the array, W is the size of each element of array<br />

, and k is the number of required element in the array (index of element) which<br />

should be a integer quantity. For example:<br />

Let the base address of the first element of the array is 2000( i. e, base address B<br />

is =2000), and each element of the array occupies four bytes in the memory,<br />

then address of fifth element of a one dimensional array a[10] will be given as:<br />

Address of element a [5] =2000+4*5=2000+20=2020<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

Assist Prof., CSE, H.C.T.M (Kaithal) Page ‐ 35 ‐

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!