Question number 3  Data Structures   Arrays & Stacks , Queues

ARRAYS

Row major method
Address A[I][J] = Base + S* [ (I-Lr)*N+(J-Lc) ]  ( N is no of columns)

Column major method
Address A[I][J] = Base + S* [ (I-Lr)+(J-Lc)*N ]  (N is no of rows)

1) Write a function in C++, which accepts an integer array and its size as parameters and rearranges the array in reverse.
Example:If an array of 9 elements initially contains the elements as 4, 2, 5, 1, 6,7, 8, 12, 10
Then the function should rearrange the array as 10,12, 8, 7, 6, 1, 5, 2, 4

2)An array Arr[40][10] is store in the memory along the column with each element
occupying 4 bytes. Find out the base address of the location Arr[3][6] if the location
Arr[30][10] is stored at the address 9000.

3)Write a function in C++ to print the product of each column of a two dimensional
array passed as the arguments of the function.
Example : If the two dimensional array contains
Then the output should appear as:
Product of Column 1 = 24
Product of Column 2 = 30
Product of Column 3 =240

4)Write a function in C++, which accepts an integer array and its size as arguments
and swap the elements of every even location with its following odd location.
Example : If an array of nine elements initially contains the elements as
2,4,1,6,5,7,9,23,10
then the function should rearrange the array as
4,2,6,1,7,5,23,9,10

5) An array Arr[50][10] is store in the memory along the row with each element
occupying 2 bytes. Find out the Base address of the location Arr[20][50], if the
location Arr[10][25] is stored at the address 10000.

6)Write a function in C++ to print the product of each row of a two dimensional
array passed as the arguments of the function
Example: if the two imensional array contains then the output should appear as:
Product of Row 1 = 8000
Product of Row 2 = 6000
Product of Row 3 =3600
Product of Row 4 = 2400

7)Write function in C++ which accepts an integer array and size as arguments and
replaces elements having odd values with thrice its value and elements having even
values with twice its value.

8)An array Array[20][15] is stored in the memory along the column with each
element occupying 8 bytes. Find out the base address of the element Array[2][3] if the
element Array[4][5] is stored at the address 1000.

9) Write a function in C++ which accepts a 2D array of integers and its size as
arguments and displays the elements which lie on diagonals. [Assuming the 2D Array
to be a square matrix with odd dimension i.e., 3x3, 5x5 ,7x7 etc.]
Example : if the array content is
5 4 3
6 7 8
1 2 9
Out put through the function should be :
Diagonal One : 5 7 9
Diagonal Two : 3 7 1

10)Write a function in C++ which accepts an integer array and its size as arguments
and replaces elements having even values with its half and elements having odd
values with twice its value .
Example : If an array of five elements initially contains the elements as 3, 4, 5, 16, 9
then the function should rearrange content of the array as 6, 2, 10, 8, 18

11)An array Arr[15][20] is stored in the memory along the row with each element
occupying 4 bytes. Find out the Base address of the location Arr[3][2], if the location
Arr[5][2] is stored at the address 1500.

12)Write a function in C++ which accepts a 2D array of integers and its size as
arguments and displays the elements of middle row and the elements of middle
column. [Assuming the 2D Array to be a square matrix with odd dimension i.e., 3x3,
5x5, 7x7 etc.]

13)Write function in C++ which accepts an integer array and size as arguments and
assign values into a 2D array of integers in the following format :
If the array is 1, 2, 3, 4, 5, 6
The resultant 2D array is given below
1 2 3 4 5 6
1 2 3 4 5 0
1 2 3 4 0 0
1 2 3 0 0 0
1 2 0 0 0 0
1 0 0 0 0 0
If the array is 1, 2, 3
The resultant 2D array is given :
1 2 3
1 2 0
1 0 0

14)An array MAT[30][10] is stored in the memory along column wise with each
element occupying 8 bytes of the memory. Find out the Base address and the address
of element MAT[20][5] , if the location MAT[3][7] is stored at the address 1000.

15)Write function in C++ which accepts an integer array and size as arguments and
assign values into a 2D array of integers in the following format :
If the array is 1, 2, 3, 4, 5, 6
The resultant 2D array is given below :
1 0 0 0 0 0
1 2 0 0 0 0
1 2 3 0 0 0
1 2 3 4 0 0
1 2 3 4 5 0
1 2 3 4 5 6
If the array is 1, 2, 3
The resultant 2D array is given :
1 0 0
1 2 0
1 2 3

16)An array MAT[20][10] is stored in the memory along the row with each element
occupying 4 bytes of the memory. Find out the Base address and the address of
element MAT[10][5] , if the location MAT[3][7] is stored at the address 1000.

17)Write a function in C++ which accepts an integer array and its size as arguments
and exchanges the values of first half side elements with the second half side elements
of the array.
Example :
If an array of 8 elements initial content as 2, 4, 1, 6, 7, 9, 23, 10
The function should rearrange array as 7, 9, 23, 10, 2, 4, 1, 6

18)An array Arr[15][35] is stored in the memory along the row with each of its
element occupying 4 bytes . Find out the Base address and the address of element
Arr[2][5] , if the location Arr[5][10] is stored at the address 4000.

19)Write a function in C++ to print sum of all values which either are divisible by 2
or divisible by 3 present in a 2D array passed as the argument of the function.

20)Write a function in C++ which accepts an integer array and its size as arguments
and exchanges the values of first half side elements with the second half side elements
of the array.
Example :
If an array of 8 elements initial content as 8, 10, 1, 3, 17, 90, 13, 60
The function should rearrange array as 17, 90, 13, 60, 8, 10, 1, 3

21)An array Arr[35][15] is stored in the memory along the row with each of its
element occupying 4 bytes . Find out the Base address and the address of element
Arr[20][5] , if the location Arr[2][2] is stored at the address 3000.

22) Write a function in C++ to print sum of all values which either are divisible by 3
or divisible by 5 present in a 2D array passed as the argument of the function.

23) Define the function SwapArray(int[ ], int),that would expect a 1D integer array
NUMBERS and its size N. the function should rearrange the array in such a way that
the values of that locations of the array are exchanged. (Assume the size of the array
to be even).
Example :
If the array initially contains {2, 5, 9, 14, 17, 8, 19, 16}
Then after rearrangement the array should contain {5, 2, 14, 9, 8, 17, 16, 19}

24) An array ARR[5][5] is stored in the memory with each element occupying 3
bytes of space. Assuming the base address of ARR to be 1500, compute the address of
ARR[2][4], when the array is stored :

25) Write a function in C++ to find the sum of diagonal elements from a 2D array of
type float. Use the array and its size as parameters with float as its return type.

26)Assume a array E containing elements of structure Employee is required to be
arranged in descending order of Salary. Write a C++ function to arrange same with
the help of bubble sort, the array and its size is required to be passed as parameters to
the function. Definition of structrure Employee is as follows:
Struct Employee
{
int Eno;
char name[25];
float Salary;
};
27)An array X[30][10] is stored in the memory with each element requiring 4 bytes
storage. Find out the Base address of X is 4500, find out memory locations of
X[12][8] and X[2][14], if the content is stored along the row.

28) Write a user-defined function in C++ to display those elements of 2D array
T[4][4] which are divisible by 100. Assume the content of the array is already present
and the function prototype is as follows: void showhundred( int T[4][4]);

29) Define array and pointer.

30) The array A[20][10] is stored in the memory with each element requiring one
byte of storage if the base address of a is 0, determine the location of A[10][5] when
the array A is stored by column major.

31) Considering the following key set: 42,29,74,11,65,58, use insertion sort to sort
the data in ascending order and indicate the sequences of steps required.

32) Given two arrays of integers X and Y of sizes m and n respectively. Write a
function named MERGE() which will third array named Z, such that the following
sequence is followed.
(i) All odd numbers of X from left to right are copied into Z from left to right.
(ii) All even numbers of X from left to right are copied into Z from right to left.
(iii) All odd numbers of Y from left to right are copied into Z from left to right.
(iv) All even numbers of Y from left to right are copied into Z from right to left.
X, Y and Z are passed as arguments to MERGE().
Eg. X is {3, 2, 1, 7, 6, 3} and {9, 3, 5, 6, 2, 8, 10}
the resultant array Z is {3, 1, 7, 3, 9, 3, 5, 10, 8, 2, 6, 6, 2}

33) An array X[10][20] is stored in the memory with each element requiring 4 bytes
of storage. If the Base address of the array is 1000, calculate location of X[5][15]
when the array X is stored using column major order.
NOTE: X[10][20] means valid row indices are 0 and 9 and valid column indices are 0
and 19

34)Write a user-defined function named Lower_half() which takes 2D array A, with
size N rows and N columns as argument and prints the lower half of the array.

35) Suppose A, B, C are arrays of integers of size M, N and M+N respectively. The
numbers in array A appear in ascending order while numbers in array in descending
order. Write user defined function in C++ to produce third array C by merging array
A by B in ascending order. Use A, B and C as arguments in the function.

36) An array VAL[1.15][1.10] is stored in the memory with each element
requiring 4 bytes of storage. If the base address of the array VAL is 1500, determine
the location of VAL[12][9] when the array VAL is stored (i) Row wise (ii) Column wise.

37) Write a user-defined function in C++ to find and display the sum of diagonal
elements from a 2D array MATRIX[6][6] containing integers.

38) Suppose a 1D array AR containing integers is arranged in ascending order. Write
a user defined function in C++ to search for one integer from AR with the help of
binary search method, to show presence of the number in the array. The function
should have three parameters: (1) an array AR (2) the number to be searched and (3)
the number of elements N in the array.

39) An array A[10][20] is stored in the memory with each element requiring 4 bytes
of storage. If the base address of the array in the memory is 400, determine the
location of A[8][13] when the array VAL is stored (i) Row major (ii) Column major.

40) Write a user-defined function in C++ to find and display the multiplication of row
elements of two dimensional array A[4][6] containing integers.

41) Suppose an array P containing float is arranged in ascending order. Write a user
defined function in C++ to search for one float from p with the help of binary search
method. The function should return an integer 0 to show absence of the number in the
array. The function should have the parameters as (1) an array P (2) the number
DATA to be searched (3) number of elements N.

42) An array T[15][10] is stored in the memory with each element requiring 2 bytes
of storage. If the base address of T is 2000, determine the location of T[7][8] when the
array VAL is stored (i) Row major (ii) Column major.
43)          Linear Search &   Binary search
44)          Bubble sort    , Selection sort   , Insertion sort  &  Merge sort ( asc / desc)





Comments