Data Structure Practice Questions

advertisement
QUESTION BANK
DATA STRUCTURE
1.
Write a user defined function in C++ to find and display the sum of diagonal
elements of a two dimensional array MAT[7][7].
Write a function in C++ to find the sum of both left and right diagonal
elements from a two dimensional array (matrix).
Evaluate the following postfix expression using a stack and show the contents
of stack after execution of each operation:
25 8 3 - / 6 * 10 +
Evaluate the following postfix notation of expression (Show status of stack
after execution of each operation) :
120 , 45 , 20 , + , 25 , 15 , - , + , *
2
Convert the following infix expression to its equivalent postfix expression
Showing stack contents for the conversion:
(A+B)*(C^(D-E)+F)-G
6. Write a function in C++ which accepts a 2D array of integers and its size as
arguments and displays the
elements of the middle row and the elements of middle column.
Example if the array content is
354
769
218
Output through the function should be:
Middle row: 769 Middle column: 5 6 1
7. A one-dimensional array SCORE is containing long data type arranged in
ascending order. Write a user defined function in C++ to search for a number
from SCORE with the help of binary search method. The function should
return an integer -1 to show absence of the number and integer 1 to show
presence of the number in the array. The function should have three
parameters as (1) an array SCORE, (2) the number SDATA to be searched,
(3) number of elements N
8. An array A [20][20] is stored in the memory along the column with each of
the Element require 4 bytes. Find the address of A[10][12], if A[1][1] is
stored in
location 1000.
9. Write a C++ function to merge the contents of two sorted arrays A and B into
third array C. Assume that array A is sorted in descending order, array B is
sorted in Ascending order, the resultant array C is required to be in
descending order.
10. A two dimensional array ARR[8][7] having real numbers(double), is stored in
the memory along the row, find out the memory location for the element
ARR[2][4], if an element ARR[1][5] is stored at the memory location 1000.
11. An array S[40][30] is stored in the memory along the row with each of the
element occupying 4 bytes, find out the memory location for the element
2
2.
3.
4.
5.
2
2
2
2
3
3
3
3
3
S[15][5], if an element s[20][10] is stored at memory location 5700.
12. Write UDF in C++ which accepts an integer array and its size as arguments/
parameters and assign the elements into a 2 D array of integers in the
following format:
If the array is 1,2,3,4,5.
The resultant 2D array is given below
10000
12000
12300
12340
12345
13. Write UDF in C++ to print the row sum and column sum of a matrix.
14. Write a function in C++ to combine the contents of two equi-sized arrays A
and B by computing their corresponding elements with the formula
2*A[i]+3*B[i]; where value i varies from 0 to N-1 and transfer the resultant
content in the third same sized array
15. An array P[20][30] is stored in the memory along the column with each of the
element occupying 4 bytes, find out the memory location for the element
P[5][15], if an element P[2][20] is stored at the memory location 5000
16. Write a function in C++ which accepts a integer array and its size as an
arguments and prints the output (using nested loops) in following format :
Example : if the array is having
12459
3
3
3
3
3
Then the output should be
1
22
4444
55555
999999
17. An array A[10][20] is stored in the memory with each element occupying 2
bytes of storage. If the Base address of array in the memory is 800 , determine
the location of A[9][10] when the array is stored as (i) Row Major (ii) column
major.
18. An array S[40][30] is stored in the memory along the row with each of the
element occupying 2 bytes, find out the memory location for the element
S[20][10], if an element S[15][5] is stored at the memory location 5500.
19. Write a function in C++ which accepts an integer array and its size as
arguments and change all the even number with twice and odd with thrice.
Example: if an array of five elements initially contains the element as
2,4,1,5,7
then the function should rearrange the array as
4,8,3,15,21
3
20. W rite a function in C++ which accepts an integer array and its size as
3
3
3
arguments/parameters and assign the elements into a two dimensional array of
integer in the following format:
if the array is 1,2,3,4,5,6
if the array is
1,2,3
the resultant 2D array is given below
the resultant 2D
array is given below
123456
123
123450
120
123400
100
123000
120000
100000
21. Write a function in C++ which accepts an integer array and its size as
arguments/ parameters and then assigns the elements into a two dimensional
array of integers in the following format:
If the array is 1, 2, 3
The resultant 2 D array is
given below
If the array is 1, 2, 3, 4, 5, 6
The resultant 2 D array is given below
0
0
0
0
0
6
0
0
0
0
5
5
0
0
0
4
4
4
0
0
3
3
3
3
0
2
2
2
2
2
3
1
1
1
1
1
1
0
0
3
0
2
2
1
1
1
22. Write a function in C++ to delete a node containing names of student, from a
dynamically allocated stack of names implemented with the help of following
structure :
struct student
{
char name[20];
student *next;
};
23. Write a user defined function in C++ to insert an element from a dynamically
allocated Queue where each node contains the long integer (schoolno) as data
Assume the following definition of SCHOOL for the same.
struct SCHOOL
{
long scno;
SCHOOL * link;
};
24. Write a function in C++ to delete an element into a dynamically allocated
Queue where each node contains a name (of type string) as data.
4
4
4
25. Write a function SORTSCORE() in C++ to sort an array of structure
Examinee in descending order of Score using Bubble Sort.
Note : Assume the following definition of structure Examinee.
struct Examinee
{ long RollNo;
char Name[20];
float Score;
};
26. Write a function FindMeritStudents( ) in C++ to find & display the record of
a Merit students(Percentage should be more than or equal to 75) from a
dynamically allocated Queue implemented with the help of following
structure. The function will receive the Front, Rear and the StudentID to be
search from Queue as arguments. (Assume the queue is already created with
some elements.)
struct Marks
{ intStudentID; // StudentID
char SName[20]; // StudentName Name
float Per; // Percentage
Marks *next;
}*Front, *Rear;
4
4
Download