Dds
Dds
**
- **Regular Queue:** Has a fixed size and becomes full when the rear
reaches the last position.
- **Circular Queue:** The last position is connected to the first position,
making it a circular buffer, allowing efficient utilization of space by reusing
vacated spaces.
A linked list is a collection of nodes where each node contains data and a
reference (or link) to the next node in the sequence. Unlike arrays, linked lists
do not have a fixed size and elements can be easily inserted or removed
without shifting elements, offering dynamic memory allocation.
The primary operations of a stack are push, pop, peek/top, and isEmpty, as
explained in question 3.
10. **Describe the algorithm for evaluating postfix expressions using a stack.**
11. **Explain the concept of a singly linked list and provide an example.**
A singly linked list is a collection of nodes where each node contains data and
a pointer to the next node in the sequence. Example:
```
Head -> [Data|Next] -> [Data|Next] -> [Data|Next] -> NULL
```
12. **How does a doubly linked list differ from a singly linked list?**
A doubly linked list has nodes with two pointers: one pointing to the next
node and another pointing to the previous node, allowing traversal in both
directions.
A circular linked list is a linked list where the last node points back to the first
node, creating a loop. It can be implemented by setting the `next` pointer of
the last node to the head node.
15. **Explain binary search. How does it improve search efficiency compared
to linear search?**
20. **Describe sparse matrix. Find the address of A [2][1] if base address is
1024 for an integer array A[5][4] in row-major order and word size is 2 bytes.**
A sparse matrix is a matrix in which most of the elements are zero. To find
the address of `A[2][1]`:
21. **Given a two dimensional array A1(1:8, 7:14) stored in row-major order
with base address 100 and size of each element is 4 bytes, find address of the
element A1(4, 12).**
25. **A m*n matrix which contains very few non-zero elements. A matrix
contains more number of ZERO values than NON-ZERO values. Such matrix is
known as ?**
1. **(A + B) / C – D * E**
- Postfix: `AB+C/DE*-`
- Prefix: `- / + A B C * D E`
2. **P ^ Q ^ R + S / T**
- Postfix: `PQR^^ST/+`
- Prefix: `+ ^^PQR / ST`
**Applications of Stack:**
- Expression evaluation and conversion (infix to postfix/prefix)
- Syntax parsing
- Backtracking (e.g., navigating back in a
browser)
- Function call management (call stack in programming languages)
Infix: `2 * 3 / (2 - 1) + 5 * 3`
Postfix: `23*21-/53*+`
**Postfix Evaluation:**
Evaluate `23*21-/53*+`:
1. Push 2, 3: `2 3`
2. *: `6`
3. Push 2, 1: `6 2 1`
4. -: `6 1`
5. /: `6`
6. Push 5, 3: `6 5 3`
7. *: `6 15`
8. +: `21`
Postfix: `AB+CD*E/-FG*IJ+/+`
`A=1,B=2,C=3,D=4,E=6,F=6,G=1,I=3,J=3`
- Postfix: `12+34*6/-61*33+/+`
- Evaluation: `3 12 24 / 2.4 6 1 3 3 3 1.8 3 + 3.6 + 2.4 = 3`
- **LIFO (Last In, First Out):** The last element added is the first to be
removed. Used in stacks.
- **FIFO (First In, First Out):** The first element added is the first to be
removed. Used in queues.
30. **How linked list is better compared to stack, queue, and array? Explain
with concept of dynamic memory allocation.**
A linear queue is better when the total number of elements processed is less
than the queue's capacity, avoiding the complexity of circular implementation.
It is also simpler when there is no need for reusing spaces vacated by
dequeued elements.
33. **What will be the value of Front and Rear pointers when Queue is
empty?**
- **Front Pointer:** Points to the position before the first element (or -1 in
some implementations).
- **Rear Pointer:** Points to the same position as the Front or -1.
34. **Apply selection sort algorithm on following input. 12, 29, 25, 8, 32, 17,
40. Explain step by step.**
35. **Write an algorithm for bubble sort. Apply it on random 8 input data.**
1. Start from the first element, compare the current element with the next
element.
2. If the current element is greater than the next element, swap them.
3. Move to the next element and repeat step 1 until the end of the list.
4. Repeat steps 1-3 for the number of elements minus one times.
**Example Application on Random Data:**
36. **Write Merge Sort algorithm. Apply the algorithm to the following
elements: 10,5,28,7,39,310,55,15,1**
1. Divide the unsorted list into n sublists, each containing one element.
2. Repeatedly merge sublists to produce new sorted sublists until there is
only one sublist remaining.
Input: `10,5,28,7,39,310,55,15,1`
- Divide: `[10], [5], [28], [7], [39], [310], [55], [15], [1]`
- Merge Step 1: `[5,10], [7,28], [39,310], [15,55], [1]`
- Merge Step 2: `[5,7,10,28], [15,39,55,310], [1]`
- Merge Step 3: `[5,7,10,15,28,39,55,310], [1]`
- Final Merge: `[1,5,7,10,15,28,39,55,310]`
If you have any specific questions or need further elaboration on any of the
topics, feel free to ask!