Algorithm Design and Analysis
SWE · Quiz · Spring 26
Paper 2 of 7By Tonmoy Chandra MudiSwitch
Paper 2 of 7
Read the questions as text
Read off the PDF by AI, so it may have mistakes. The PDF is the original.
Class Test - 1 (Set 2)
Course Code: SE 214; Course Title: Algorithm Design and Analysis
Time: 30 Minutes
Marks: 15
1. [Figure: Code snippet with three nested for loops: for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { sum += (i + j + k); } } }] Analyze time complexity of the above code segment. [5 marks]
2. A teacher is sorting students' roll numbers that are already almost sorted. One version of Bubble Sort always completes all passes, while another version uses a flag variable to stop early if no swapping occurs. Explain which version is more effective in this scenario and why, in terms of number of passes and time complexity. [5 marks]
3. A set of pages in a book are out of order due to a printing error. The current page numbers are: 42, 18, 60, 29, 11. Using bubble sort, sort these page numbers in ascending order. Explain each pass of the algorithm, showing how adjacent elements are compared and swapped where necessary. Derive time complexity of bubble sort. [5 marks]