×

Close

- Data Structure using C - DS
- Note
**Visvesvaraya Technological University Regional Center - VTU**- 6 Topics
**27344 Views**- 699 Offline Downloads
- Uploaded 2 years ago

Touch here to read

Page-2

Topic:

Data Structures Operations: 1. Traversing 2. Searching 3. Inserting 4. Deleting 5. Sorting 6. Merging 1. Traversing- It is used to access each data item exactly once so that it can be processed. 2. Searching- It is used to find out the location of the data item if it exists in the given collection of data items. 3. Inserting- It is used to add a new data item in the given collection of data items. 4. Deleting- It is used to delete an existing data item from the given collection of data items. 5. Sorting- It is used to arrange the data items in some order i.e. in ascending or descending order in case of numerical data and in dictionary order in case of alphanumeric data. 6. Merging- It is used to combine the data items of two sorted files into single file in the sorted form. Review of Arrays The simplest type of data structure is a linear array. This is also called one dimensional array. Definition: Array is a data structure that can store a fixed-size sequential collection of elements of the same type. An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type. An array holds several values of the same kind. Accessing the elements is very fast. It may not be possible to add more values than defined at the start, without copying all values into a new array. An array is stored so that the position of each element can be computed from its index. For example, an array of 10 integer variables, with indices 0 through 9, may be stored as 10 words at memory addresses 2000, 2004, 2008, 2036, so that the element with index i has the address 2000 + 4 × i. Prepared by Prof Pankaja K. & Prof Geetha P.

Address Calculation in single (one) Dimension Array: Array of an element of an array say “A[ I ]” is calculated using the following formula: Address of A [ I ] = B + W * ( I – LB ) Where, B = Base address W = Storage Size of one element stored in the array (in byte) I = Subscript of element whose address is to be found LB = Lower limit / Lower Bound of subscript, if not specified assume 0 (zero) Example: Given the base address of an array B[1300…..1900] as 1020 and size of each element is 2 bytes in the memory. Find the address of B[1700]. Solution: The given values are: B = 1020, LB = 1300, W = 2, I = 1700 Address of A [ I ] = B + W * ( I – LB ) = 1020 + 2 * (1700 – 1300) = 1020 + 2 * 400 = 1020 + 800 = 1820 [Ans] Address Calculation in Double (Two) Dimensional Array: While storing the elements of a 2-D array in memory, these are allocated contiguous memory locations. Therefore, a 2-D array must be linearized so as to enable their storage. There are two alternatives to achieve linearization: Row-Major and Column-Major. Prepared by Prof Pankaja K. & Prof Geetha P.

C allows for arrays of two or more dimensions. A two-dimensional (2D) array is an array of arrays. A three-dimensional (3D) array is an array of arrays of arrays. In C programming an array can have two, three, or even ten or more dimensions. The maximum dimensions a C program can have depends on which compiler is being used. More dimensions in an array means more data be held, but also means greater difficulty in managing and understanding arrays. How to Declare a Multidimensional Array in C A multidimensional array is declared using the following syntax: type array_name[d1][d2][d3][d4]………[dn]; Where each d is a dimension, and dn is the size of final dimension. Prepared by Prof Pankaja K. & Prof Geetha P.

Examples: 1. int table[5][5][20]; 2. float arr[5][6][5][6][5]; In Example 1: int designates the array type integer. table is the name of our 3D array. Our array can hold 500 integer-type elements. This number is reached by multiplying the value of each dimension. In this case: 5x5x20=500. In Example 2: Array arr is a five-dimensional array. It can hold 4500 floating-point elements (5x6x5x6x5=4500). When it comes to holding multiple values, we would need to declare several variables. But a single array can hold thousands of values. Explanation of a 3D Array A 3D array is essentially an array of arrays of arrays: it's an array or collection of 2D arrays, and a 2D array is an array of 1D array. The diagram below shows a 3D array representation: 3D Array Conceptual View 3D array memory map. Prepared by Prof Pankaja K. & Prof Geetha P.

## Leave your Comments

## Subham Mondol

3 months ago00## saurabh mishra

1 year ago00## Ankur tyagi

1 year ago00