0% found this document useful (0 votes)
4 views3 pages

Quiz-4

The document outlines the submission guidelines and requirements for Quiz 4, which includes sorting a list of numbers using Insertion Sort and Merge Sort. It details the steps for each sorting method, along with questions regarding their properties such as stability, memory usage, and time complexity. Additionally, it specifies the format for submission as a single PDF file and the time limit for completing the quiz.

Uploaded by

Navpreet Kaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Quiz-4

The document outlines the submission guidelines and requirements for Quiz 4, which includes sorting a list of numbers using Insertion Sort and Merge Sort. It details the steps for each sorting method, along with questions regarding their properties such as stability, memory usage, and time complexity. Additionally, it specifies the format for submission as a single PDF file and the time limit for completing the quiz.

Uploaded by

Navpreet Kaur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Quiz 4

Submission Guideline:

1. Submit a single pdf.


2. To submit your answers, you must upload a single PDF file. You can prepare your
solutions using pen and paper, take pictures of your written work, and then upload those
images to a document file. Afterward, convert the document to a PDF. Alternatively, you
can use Microsoft Word or a similar program to create your solutions and then convert
the file to PDF format.
3. Show the details procedure.
4. 2 hour and 20 Minutes

Question 1[1 *5 = 5 Marks]:

25 12 4 16 10 7 29 25 88 44 33 22 10

Sort the above list intro ascending order by applying “Insertion sort”. Show all the intermediate
states, i.e., Each step. Depending on your demo, answer the following questions:
Steps for Insertion Sort:
Initial list: [25, 12, 4, 16, 10, 7, 29, 25, 88, 44, 33, 22, 10]
Insert 12: [12, 25, 4, 16, 10, 7, 29, 25, 88, 44, 33, 22, 10]
Insert 4: [4, 12, 25, 16, 10, 7, 29, 25, 88, 44, 33, 22, 10]
Insert 16: [4, 12, 16, 25, 10, 7, 29, 25, 88, 44, 33, 22, 10]
Insert 10: [4, 10, 12, 16, 25, 7, 29, 25, 88, 44, 33, 22, 10]
Insert 7: [4, 7, 10, 12, 16, 25, 29, 25, 88, 44, 33, 22, 10]
Insert 29: [4, 7, 10, 12, 16, 25, 29, 25, 88, 44, 33, 22, 10]
Insert 25: [4, 7, 10, 12, 16, 25, 25, 29, 88, 44, 33, 22, 10]
Insert 88: [4, 7, 10, 12, 16, 25, 25, 29, 88, 44, 33, 22, 10]
Insert 44: [4, 7, 10, 12, 16, 25, 25, 29, 44, 88, 33, 22, 10]
Insert 33: [4, 7, 10, 12, 16, 25, 25, 29, 33, 44, 88, 22, 10]
Insert 22: [4, 7, 10, 12, 16, 22, 25, 25, 29, 33, 44, 88, 10]
Insert 10: [4, 7, 10, 10, 12, 16, 22, 25, 25, 29, 33, 44, 88]
1. Is “Insertion sort” in place? Justify your answer.
Ans Yes, it is in place because it sorts the list using only a small, constant amount of extra
memory.
2. Is “Insertion sort” stable? Justify your answer.
Ans Yes, it is stable as it maintains the relative order of equal elements.How many exact
comparisons and how many swaps?
Ans Comparisons: 78 (for n = 13) Swaps: 65
3. What is the best, average and worst-case time complexity (asymptotic notation)?
Ans Best Case: O(n)
Average Case: O(n2)
Worst Case: O(n2)
4. What is the best case, average case, and worst-case scenario? Justify your answer.
Ans Best Case: The array is already sorted.
Quiz 4

Average Case: Elements are in random order.


Worst Case: The array is sorted in reverse order.

Question 2[1 *5 = 5 Marks]:

25 12 4 16 10 7 29 25 88 44 33 22 10

Sort the above list intro ascending order by applying “Merge sort”. Show all the intermediate
states, i.e., Each step. Depending on your demo, answer the following questions:
Steps for Merge Sort:
Initial split:
Left: [25, 12, 4, 16, 10, 7, 29]
Right: [25, 88, 44, 33, 22, 10]
Second split:
Left: [25, 12, 4], [16, 10, 7, 29]
Right: [25, 88, 44], [33, 22, 10]
Third split:
Left: [25, 12], [4], [16, 10], [7, 29]
Right: [25, 88], [44], [33, 22], [10]
Final split:
Left: [25], [12], [4], [16], [10], [7], [29]
Right: [25], [88], [44], [33], [22], [10]
Merge pairs:
Left: [12, 25], [4], [10, 16], [7, 29]
Right: [25, 88], [44], [22, 33], [10]
Merge again:
Left: [4, 12, 25], [7, 10, 16, 29]
Right: [25, 44, 88], [10, 22, 33]
Final merge:
Left: [4, 7, 10, 12, 16, 25, 29]
Right: [10, 22, 25, 33, 44, 88]
Final list: [4, 7, 10, 10, 12, 16, 22, 25, 25, 29, 33, 44, 88]

1. Is “Merge sort” in place? Justify your answer.


Ans No, it requires additional memory for merging.
2. Is “Merge sort” stable? Justify your answer.
Ans Yes, it preserves the relative order of equal elements.
3. What is the total number of comparisons?
Ans Approximately m log n for n = 13 about 40 comparisons.
4. What is the best, average, and worst-case time complexity (asymptotic notation)?
Ans Best Case: O(n log n)
Average Case: O(n log n)
Worst Case: O(n log n)
Quiz 4

5. What is the best case, average case, and worst-case scenario? Justify your answer.
Ans Best Case: Any order since merge sort always divides the array in half and sorts.
Average Case: Elements are in random order.
Worst Case: Any order since merge sort always follows the same process regardless
of initial order.

You might also like