Professional Documents
Culture Documents
Rev DSA
Rev DSA
8. How many swappings are required to sort the following array in descending
order?
1. Bubble Sort:
Total swaps = 3
2. Insertion Sort:
Total swaps = 4
3. Selection Sort:
Select 22: [22, 8, 7, 0, 5, 13] - 0 swaps (22 is already in the correct position)
Total swaps = 3
9.. How many swappings are required to sort the following array in ascending
order? int arr [6] = {8, 22, 7, 0, 5, 13}; 1- Bubble Sort; 2- Insertion Sort; 3- Selection
Sort
1. Bubble Sort:
Total swaps = 5
2. Insertion Sort:
Insert 22: [8, 22, 7, 0, 5, 13] - 0 swaps (22 is already in the correct position)
Total swaps = 5
3. Selection Sort:
Select 0: [0, 22, 7, 8, 5, 13] - 1 swap
Total swaps = 3
10.
11.
12.
A graph data structure is a collection of nodes and edges between them, representing
relationships or connections.
1. Vertices (or Nodes): These are the fundamental units of a graph, representing
entities or points.
3. Weight (or Cost): Edges can have weights or costs associated with them,
representing the magnitude or cost of the relationship between vertices.
4. Degree of a Vertex: The degree of a vertex is the number of edges incident to it.
6. Cycle: is a path where the first and last vertices are the same.
15
16
17
18
19
20
21
22
23
24. Which ADT uses FILO? What does FILO mean? What about FIFO? Which ADT
uses it?
FILO (First In, Last Out):An ADT that follows FILO is the stack.
(FIFO):(First In, First Out) An ADT that follows FIFO is A queue
25. What is a merge Sort? Explain with an example sorting values in an array
Merge Sort is a sorting algorithm that works by dividing an array into smaller subarrays,
sorting each subarray, and then merging the sorted subarrays back together to produce
a final sorted array.
1. Divide: Split the array into two halves: and .[2, 4][1, 3]
2. Recursive Calls:
Left half: Since [2, 4] has only two elements, sorted already.
Right half: Since [1, 3] has only two elements, sorted already.
3. Merge:
To merge the [2, 4] and [1, 3]: we compare the first elements of each sublist: 2
and 1. Since 1 is smaller, we add it to the merged list. Next, we compare 2 from
the first sublist with 3 from the second list. Again, 2 is smaller, so we add it to the
merged list. The final merged list becomes [1, 2, 3, 4].
26. What is an ordered linear search? Explain with an example sorting values in
an array and a key
27.a. What is a stack data structure? What are the main operations found in a
stack implementation? Explain with an example.
a. Stack Data Structure:is a linear data structure that follows the Last In, First Out
(LIFO) principle.
Example A pile of plates piled on top of each other
b. What is a queue data structure? What are the main operations found in a queue
implementation? Explain with an example.
b.A queue is another linear data structure that follows the First-In-First-Out (FIFO)
principle.
Example A line of cars on a one way road
28. What are the differences between singly, doubly and circular linked lists?
Function Contains element and link Contains element The last element is
to the next node and link to the linked back to the first
next and previous element, forming a
node circular loop.
30. What would be the asymptotic time complexity to find an element in the linked
list?