You are on page 1of 30

PART-A

Q1. What is data structure? Give an example.


Ans.
Q2. What is recursion? Explain with an example
Ans.
Q3. Write a function to find string length by using pointers.
Ans.
1.6.2 String Length

The length of the string is the number of characters in the string, which includes spaces, and all
ASCII characters. As the array index starts at zero, we can say the position occupied by \0
indicates the length of that string. Let us write these functions in two different ways mentioned
earlier.
Q4. What are dynamic arrays?
Ans.
An array is a powerful and easy-to-use data structure provided in the C
language. We know that arrays provide easy access to their elements and
entire arrays can be manipulated easily using loops. However, there are some
drawbacks/limitations of arrays:
1. Inability to resize an array at run-time: As the memory for arrays is allocated
at compile time, it is not possible to change the array size during program
execution. Thus, if the declared array size is insufficient in some situation, the
executable program is almost useless. In such situations, we need to modify
the source code suitably and recompile the program. This is either impossible
(if the source code is not available) or very difficult Also, it is not possible to
reduce the array size to save memory in situations where fewer array elements
are required.
2. Memory wastage: As array size cannot be increased at run-time, a
programmer tends to declare arrays much larger than usually required to cater
to some unforeseen situations. This leads to wastage of memory in most of the
executions.
To overcome these limitations, we can implement the dynamic arrays using
the dynamic memory allocation feature of the C language. This allows a
programmer to allocate only the required memory for arrays. For example, if a
class has only 35 students, an array to store names of the students in that class
will be allocated to hold only 35 elements. On the other hand, while using
static memory allocation, we might use much larger arrays, say having
100elements, leading to large wastage of memory.

Q5. What is stack? What are the operations performed on stack?


Ans.
PART-B

Q1. What is pointer? Discuss the advantages and disadvantages of pointer


Ans.
Q2. Discuss the dynamic allocation and de allocation of memory.
Ans.
Q3. Write a C-program to accepts data of a student from the keyboard and
that data is transferred to the file Student.txt.
Ans.
Q4. What is random access file? Explain
Ans.
Q5.Design an algorithm/pseudo code for the following.
i) Adding two Sparse Matrices.
ii) Multiplication of two Sparse Matrices.
Ans. 1) Adding two Sparse Matrices

Algorithm Sparse_Matrix_Addition(A, B, AROW, BROW, ACOL, BCOL, m, n)


* m,n are number of rows and columns in the matrix
* A is the array containing non-zero elements of first matrix
* B is the array containing non-zero elements of second matrix
* C is the array containing non-zero elements of resultant matrix
* AROW is the row array of first sparse matrix
* BROW is the row array of second sparse matrix
* CROW is the row array of resultant sparse matrix
* ACOL is the column array of first sparse matrix
* BCOL is the column array of second sparse matrix
* CCOL is the column array of resultant sparse matrix

2) Multiplication of two Sparse Matrices


Algorithm SMP(A;B)
Input: Two n n matrices A and B.
Output: The product AB.
1. Let ak be the number of non-zero elements in Ak, the k-th column of A, for 1 k n.
2. Let bk be the number of non-zero elements in Bk, the k-th row of B, for 1 k n.
3. Let be a permutation for which a(1)b(1) a(2)b(2) : : : a(n)b(n).
4. Find an 0 ` n that minimizes M(n; `; n) + P k>` a(k)b(k).
5. Let I = f(1); : : : ; (`)g and J = f(` + 1); : : : ; (n)g.
6. Compute C1 AIBI using the fast dense rectangular matrix multiplication algorithm.
7. Compute C2 AJBJ using the naive sparse matrix multiplication algorithm.
8. Output C1 + C2.
Q6. What are the liner and binary search methods? Explain linear search
method in detail. What is its time complexity?
Ans.
Q7. What is tree? Explain the types and different operations performed on
trees.
Ans.

Types
Tree
Rooted Tree
Binary Tree
Operations
Q8. Explain how queue is Implemented using array. Write a C-program for
the same.
Ans.
This C Program implements a queue using array. Queue is a is a particular kind of abstract
data type or collection in which the entities in the collection are kept in order and the
principal (or only) operations on the collection are the addition of entities to the rear
terminal position and removal of entities from the front terminal position. This makes the
queue a First-In-First-Out (FIFO) data structure. Here is source code of the C Program to
implement a queue using array. The C program is successfully compiled and run on a Linux
system. The program output is also shown below

1. /*
2. * C Program to Implement a Queue using an Array
3. */
4. #include <stdio.h>
5.
6. #define MAX 50
7. int queue_array[MAX];
8. int rear = - 1;
9. int front = - 1;
10. main()
11. {
12. int choice;
13. while (1)
14. {
15. printf("1.Insert element to queue \n");
16. printf("2.Delete element from queue \n");
17. printf("3.Display all elements of queue \n");
18. printf("4.Quit \n");
19. printf("Enter your choice : ");
20. scanf("%d", &choice);
21. switch (choice)
22. {
23. case 1:
24. insert();
25. break;
26. case 2:
27. delete();
28. break;
29. case 3:
30. display();
31. break;
32. case 4:
33. exit(1);
34. default:
35. printf("Wrong choice \n");
36. } /*End of switch*/
37. } /*End of while*/
38. } /*End of main()*/
39. insert()
40. {
41. int add_item;
42. if (rear == MAX - 1)
43. printf("Queue Overflow \n");
44. else
45. {
46. if (front == - 1)
47. /*If queue is initially empty */
48. front = 0;
49. printf("Inset the element in queue : ");
50. scanf("%d", &add_item);
51. rear = rear + 1;
52. queue_array[rear] = add_item;
53. }
54. } /*End of insert()*/
55.
56. delete()
57. {
58. if (front == - 1 || front > rear)
59. {
60. printf("Queue Underflow \n");
61. return ;
62. }
63. else
64. {
65. printf("Element deleted from queue is : %d\n", queue_array[front]
);
66. front = front + 1;
67. }
68. } /*End of delete() */
69. display()
70. {
71. int i;
72. if (front == - 1)
73. printf("Queue is empty \n");
74. else
75. {
76. printf("Queue is : \n");
77. for (i = front; i <= rear; i++)
78. printf("%d ", queue_array[i]);
79. printf("\n");
80. }
81. } /*End of display() */
Q9. What is linked list? Discuss the components of linked list.
Ans.
Q10. Compare and contrast between single linked list and double linked list.
Ans.
Q11. Write a C-program to implement queue data structure using single
linked list
Ans.
Q12. Develop an algorithm to convert infix expression to its equivalent
postfix expression
Ans.
Q13. What is queue? What are the basic operations performed on queue
Ans.

You might also like