
Understanding Arrays in Data Structures: Definition and Applications
Table of Content:
Arrays are used to store a set of values in a single variable.

Array is a linear data structure. A data structure is said to be linear, if its elements form a sequence or in other words a linear list. There are two basic Ways of representing such linear structures in memory. One way is to have the linear relationship between the elements represented by means of sequential memory locations. These linear structure are called array. The other way is to have the linear relationship between the elements represented by means of pointers or links. These linear structure are called linked list.
A linear array is a list of a finite number n of homogeneous data elements such that -
- The elements of the array are referenced, respectively by an index set consisting of n consecutive numbers.
- The elements of the array are stored, respectively in successive memory locations. The number n of
elements is called the length or size of array. If not explicitly stated we will assume the index set
consists of the integers 1, 2, ... n. In general, the length or the number of data elements of the array
can be obtained from the index set by the formula
Length = UB - LB + 1
When UB is the largest index, called the upper bound and LB is the smallest index, called lower bound of the array. Representation of linear array in memory Let LA be a linear array in the memory of the computer. Recall that memory of the computer is simply a sequence of addressed locations as pictured in Fig. 2. Let us use the notations.
LOC [LA[K]] = address of the element LA[K] of the array LAAs Previously noted, the elements of LA are stored in successive memory cells. Accordingly, the computer does not need to keep track of the address of every element of LA, but needs to keep track only of the address of the first element of LA denoted by Base(LA). and called the base address of LA. Using this addres base (LA), the computer calculates the address of any element of LA by the following formula,
LOC (LA[K]) = Base (LA) + w(K-lower bound)Where, w is the number of words per memory cell for the array LA. Given, any subscript K, one can locate and access the content of LA[K] without scanning any other element of LA.
e.g., consider the array, which holds the number of automobiles sold each year from 1932 through 1984. Suppose AUTO appears in memory as pictured in Figure. 2.
Given (by figure)
Base[AUTO] =200, w = 4
LOC (Auto[1932]) = 200
LOC (Auto[1933]) = 204
LOC (Auto[1934]) = 208
The address of the array element for the year K = 1965 can be obtained by,
LOC(AUTO[1965]) = Base (AUTO) + w (1965 - lower bound) = 200 + 4(1965 —1932) = 332
A collection A of data elements is said to be indexed, if any element of A, which we shall call can be located and processed in a time that is independent of K The above discussion indicate that linear arrays can be indexed. `Ellis is the very important property of the linear array.
- Question 1: What is an Array?
- Question 2: How to read and write data in an array?
- Question 3: How to insert data in an array at a particular position?
- Question 4: Write code to insert data in an array at a particular position
- Question 5: How to delete an element from a specified position from an array?
- Question 6: Write code to delete data from an array from a particular position?
- Question 7: How to merge two sorted arrays?
- Question 8: Write code to merge two sorted arrays?
- Question 9: How to read and write data in 2-D array?
- Question 10: What is two dimensional array?
- Question 11: Write an algorithm to multiply two 2-Dimensional array?
- Question 12: Wap to Sum of diagonal elements of a matrix in c?
Related Questions
- Assignment 1: Assignment: Using C Language: Add all element in the array.
- Assignment 2: C Program to Delete an element from the specified location from Array
- Assignment 3: C Program to Insert an element in an Array
- Assignment 4: C Program to Copy all elements of an array into Another array
- Assignment 5: C Program to Search an element in Array
- Assignment 6: C Program to Merge Two arrays in C Programming
- Assignment 7: C Program to Reversing an Array Elements in C Programming
- Assignment 8: C Program to Find Largest Element in Array in C Programming
- Assignment 9: C Program to Find Smallest Element in Array in C Programming
- Assignment 10: C Program to Calculate Addition of All Elements in Array
- Assignment 11: C Program to Delete duplicate elements from an array
- Assignment 12: C Program to Read integers into an array and Reversing them using Pointers
- Assignment 13: Array limit value and an array element address are printed in this program
- Assignment 14: Python Two Sum