# CS502 Assignment 2 Solution Spring 2018

Question # 1:                                                                              10   Marks

Consider the following algorithm for sorting:

The main idea behind this sorting algorithm is as follows:

• Find the smallest element in the array
• Exchange it with the element in the first position
• Find the second smallest element and exchange it with the element in the second position
• Continue until the array is sorted

You are required to Sort the following array using the above sorting algorithm.

 8 4 6 9 2 3 1

You have to strictly follow all the steps.   Marks will not be awarded for partial/incomplete solution.

Question # 2:                                                              Marks: 5 + 5 = 10

Apply Merge Sort to sort the list “X, Y, L, O, M, E, T, E, R, S” in Ascending order.

Note: You need to provide separate tree structure diagram for each phase (i.e. divide phase and combine phase).

<iframe width=”560″ height=”315″ src=”https://www.youtube.com/embed/bk_-szbZw3s?rel=0&amp;controls=0&amp;showinfo=0″ frameborder=”0″ allow=”autoplay; encrypted-media” allowfullscreen></iframe>