Data Structures - C Language Basics
PART-A (S*2=10 Marks)
1. Write the syntax for declaring the array.
Answer: Syntax for declaring an array in C:
```c
data_type array_name[array_size];
```
2. What is Type defined structures?
Answer: A typedef structure in C allows you to define a structure with a new name using the
`typedef` keyword.
```c
typedef struct {
int x;
int y;
} Point;
```
3. What is Sparse matrices?
Answer: Sparse matrices are matrices in which most of the elements are zero. They are stored
using special techniques to save memory.
4. What is garbage collection?
Answer: Garbage collection is the process of automatically freeing memory that is no longer in use
by the program, preventing memory leaks.
5. What is a linked list?
Answer: A linked list is a linear data structure where each element is a separate object (called a
node) linked to the next element.
PART-B (4*10=40 Marks)
_Module-1:_
1. a. Write the ADT of the linear array.
Answer: The Abstract Data Type (ADT) of a linear array defines operations such as retrieval,
update, insertion, and deletion.
2. b. What is searching? Explain the types of searching.
Answer: Searching refers to the process of finding a specific element in a data structure. Types
include:
- Linear Search: Traverse the array sequentially.
- Binary Search: Divide the array and search in a sorted array.
3. Write the binary search algorithm.
Answer: Binary search algorithm for sorted arrays:
```c
int binarySearch(int arr[], int left, int right, int key) {
while (left <= right) {
int mid = left + (right - left) / 2;
if (arr[mid] == key)
return mid;
if (arr[mid] < key)
left = mid + 1;
else
right = mid - 1;
return -1;
```
_Module-2:_
1. a. Explain the applications of stack.
Answer: Stack applications include:
- Expression evaluation (postfix, prefix)
- Backtracking algorithms
- Undo functionality in text editors
2. b. Convert the following Infix expression to postfix.
Answer: Example infix expression: `A + B * (C - D)`
Postfix expression: `A B C D - * +`