<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[CS502 Assignment No. 02 Solution and Discussion]]></title><description><![CDATA[<p dir="auto">Assignment No. 02<br />
SEMESTER Fall 2019<br />
CS502- Fundamentals of Algorithms	<br />
Total Marks: 20</p>
<p dir="auto">Due Date: 27/11/2019<br />
Instructions<br />
Please read the following instructions carefully before solving &amp; submitting assignment:<br />
It should be clear that your assignment will not get any credit  if:<br />
•	The assignment is submitted after due date.<br />
•	The submitted assignment does not open or file corrupt.<br />
•	The assignment is full or partially copied from (other student or ditto copy from handouts or internet).<br />
•	Student ID is not mentioned in the assignment File or name of file is other than student ID.<br />
•	The assignment is not submitted in .doc or .docx format.<br />
Uploading instructions<br />
Your submission must include:</p>
<p dir="auto">•	Assignment should be in .doc or .docx format.<br />
•	Save your assignment with your ID (e.g. bx180200786.doc).<br />
Assignment submission through email is NOT acceptable<br />
Objective<br />
The objective of this assignment is<br />
•	To give basic knowledge and understanding of Algorithms.<br />
•	To be able to design sorting algorithms.<br />
•	To be able to understand and calculate the complexity of algorithms.</p>
<p dir="auto">Note:<br />
Your answer must follow the below given specifications.<br />
•	 Font style: “Times New Roman”<br />
•	 Font color: “Black”<br />
•	 Font size: “12”<br />
•	 Bold for heading only.<br />
•	 Font in Italic is not allowed at all.<br />
•	 No formatting or bullets are allowed to use.<br />
•	Your answer should be precise and to the point, avoid irrelevant detail.</p>
<p dir="auto">Lectures Covered: This assignment covers Lecture # 09 - 14<br />
Deadline<br />
Your assignment must be uploaded/submitted at or before 27/11/2019.</p>
<p dir="auto">Assignment diagram:</p>
<p dir="auto"><img src="https://i.imgur.com/ISyleYl.png" alt="0e4a496c-d936-4a99-ac0c-2e198ae8fc43-image.png" class=" img-fluid img-markdown" /><br />
Consider the given diagram having an unsorted array and its sorting procedure through dry run. You are required to answer the following questions.</p>
<p dir="auto">Question No  01:   (Marks:  5)<br />
You are required to determine (write down the name) the algorithm being used while sorting the above given array.</p>
<p dir="auto">Question No  02:   (Marks:  7)<br />
You are required to design (write) the algorithm (Only Pseudo code) determined in Question 1.</p>
<p dir="auto">Question No  03:   (Marks:  8)<br />
You are required to calculate (Step by Step) the worst case time complexity T(n) of the algorithm designed in Question No. 02.</p>
<p dir="auto">=====================================Ended=======================================</p>
<p dir="auto">For any query about the assignment, contact at <a href="mailto:CS502@vu.edu.pk" target="_blank" rel="noopener noreferrer nofollow ugc">CS502@vu.edu.pk</a></p>
<p dir="auto">GOOD LUCK</p>
]]></description><link>https://community.secnto.com//topic/650/cs502-assignment-no-02-solution-and-discussion</link><generator>RSS for Node</generator><lastBuildDate>Mon, 08 Jun 2026 19:59:55 GMT</lastBuildDate><atom:link href="https://community.secnto.com//topic/650.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 21 Nov 2019 11:58:45 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to CS502 Assignment No. 02 Solution and Discussion on Wed, 15 Jan 2020 09:12:19 GMT]]></title><description><![CDATA[<p dir="auto"><strong>Solution:</strong><br />
Question No. 01: The name of the algorithm being used for sorting the given array has given below.<br />
Selection sort<br />
Question No. 02: The Pseudo code for the algorithm used for sorting the given array has given below.</p>
<p dir="auto">Pseudo code:<br />
1 Selection sort (A)<br />
{<br />
2 For i 1 to A.lenght-1<br />
{<br />
3 imin i<br />
4 for j i+1 to A.length<br />
{<br />
5 If (A[j] &lt; A[imin])<br />
Imin j<br />
}<br />
6 Temp A[i]<br />
7 A[i] A[imin]<br />
8 A[imin] Temp<br />
}<br />
}</p>
<p dir="auto">Question No. 03: The step by stem analysis of the algorithm designed in question 2 is as follow,</p>
<p dir="auto">The time taken by each statement (step) is given as follows,</p>
<p dir="auto">Selection sort (A) Cost Times<br />
{<br />
For i 1 to A.length-1 c1 n<br />
{<br />
imin i-------------------- c2 n-1<br />
for j i+1 to A.length<br />
{ c3 n+n-1+…1=n(n+1)/2<br />
If (A[j] &lt; A[imin])<br />
imin j<br />
}<br />
Temp A[i] c4 n-1<br />
A[i] A[imin] c5 n-1<br />
A[imin] Temp c6 n-1<br />
}<br />
}</p>
<p dir="auto">Total time T(n) can be calculated as follows,</p>
<p dir="auto">T(n)= c1n+c2(n-1)+c3(n(n+1)/2)+c4(n-1)+c5(n-1)+c6(n-1)<br />
c1n+c2n-c2+c3 (n2+n/2) +c4n-c4+c5n-c5+c6n-c6 collect the like terms<br />
c3n2/2+ (c1+c2+c3/2+c4+c5+c6) n + (-c2-c4-c5-c6)</p>
<p dir="auto">This is equivalent to a polynomial an2+bn+c<br />
Therefore T (n) = Big O (n2) by taking the highest order term of the equation.<br />
Note: a, b, c in polynomial represents constants<br />
//   Ignoring constant terms</p>
<p dir="auto">T(n) = O (n2)</p>
]]></description><link>https://community.secnto.com//post/1980</link><guid isPermaLink="true">https://community.secnto.com//post/1980</guid><dc:creator><![CDATA[zareen]]></dc:creator><pubDate>Wed, 15 Jan 2020 09:12:19 GMT</pubDate></item><item><title><![CDATA[Reply to CS502 Assignment No. 02 Solution and Discussion on Thu, 09 Jan 2020 12:13:29 GMT]]></title><description><![CDATA[<p dir="auto"><strong>Solution:</strong><br />
Question No. 01:   The name of the algorithm being used for sorting the given array has given below.<br />
Selection sort<br />
Question No. 02:  The Pseudo code for the algorithm used for sorting the given array has given below.</p>
<p dir="auto">Pseudo code:<br />
1    Selection sort (A)<br />
{<br />
2         For i	1 to A.lenght-1<br />
{<br />
3            imin	 i<br />
4            for j 	  i+1 to A.length<br />
{<br />
5                  If (A[j] &lt; A[imin])<br />
Imin        j<br />
}<br />
6        Temp         A[i]<br />
7        A[i]         A[imin]<br />
8        A[imin]       Temp<br />
}<br />
}</p>
<p dir="auto">Question No. 03: The step by stem analysis of the algorithm designed in question 2 is as follow,</p>
<p dir="auto">The time taken by each statement (step) is given as follows,</p>
<p dir="auto"><img src="https://i.imgur.com/PetMmcY.png" alt="b8c2d4d9-76e3-4841-94a7-e8c1a8202f51-image.png" class=" img-fluid img-markdown" /></p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Selection sort (A)</th>
<th>Cost</th>
<th>Times</th>
</tr>
</thead>
</table>
<p dir="auto">{	<br />
For i	1 to A.length-1                            |c1                                                | n<br />
{<br />
imin	 i--------------------&gt;                    c2	n-1<br />
for j 	i+1 to A.length	<br />
{                                                                 c3                                                  n+n-1+…1=n(n+1)/2<br />
If (A[j] &lt; A[imin])	<br />
imin	j<br />
}<br />
Temp          A[i]			        c4		n-1<br />
A[i]           A[imin] 	              c5				            n-1	<br />
A[imin]         Temp	     c6				            n-1	<br />
}<br />
}</p>
<p dir="auto">Total time T(n) can be calculated as follows,</p>
<p dir="auto">T(n)= c1n+c2(n-1)+c3(n(n+1)/2)+c4(n-1)+c5(n-1)+c6(n-1)<br />
c1n+c2n-c2+c3 (n2+n/2) +c4n-c4+c5n-c5+c6n-c6                collect the like terms<br />
c3n2/2+ (c1+c2+c3/2+c4+c5+c6) n + (-c2-c4-c5-c6)</p>
<p dir="auto">This is equivalent to a polynomial an2+bn+c<br />
Therefore T (n) = Big O (n2)    by taking the highest order term of the equation.<br />
Note: a, b, c in polynomial represents constants</p>
<p dir="auto">//   Ignoring constant terms</p>
<p dir="auto">T(n)   =  O (n2)</p>
]]></description><link>https://community.secnto.com//post/2570</link><guid isPermaLink="true">https://community.secnto.com//post/2570</guid><dc:creator><![CDATA[zareen]]></dc:creator><pubDate>Thu, 09 Jan 2020 12:13:29 GMT</pubDate></item><item><title><![CDATA[Reply to CS502 Assignment No. 02 Solution and Discussion on Thu, 28 Nov 2019 12:45:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/zareen" aria-label="Profile: zareen">@<bdi>zareen</bdi></a> said in <a href="/post/1828">CS502 Assignment No. 02 Solution and Discussion</a>:</p>
<blockquote>
<p dir="auto">You are required to calculate (Step by Step) the worst case time complexity T(n) of the algorithm designed in Question No. 02.</p>
</blockquote>
<pre><code>ANS:
C1 =  (n-1)
C2 = (n-1)+(n-2)+…+1
   =  
C3 = (n-1)
T(n) = (n-1) . C1 +  . C2 +  (n-1)C3
T(n) = an2 + bn + c
Here a,b and c are constants in term of C1, C2 and C3
T(n) = O(n2)

</code></pre>
]]></description><link>https://community.secnto.com//post/1982</link><guid isPermaLink="true">https://community.secnto.com//post/1982</guid><dc:creator><![CDATA[zareen]]></dc:creator><pubDate>Thu, 28 Nov 2019 12:45:50 GMT</pubDate></item><item><title><![CDATA[Reply to CS502 Assignment No. 02 Solution and Discussion on Thu, 28 Nov 2019 12:42:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/zareen" aria-label="Profile: zareen">@<bdi>zareen</bdi></a> said in <a href="/post/1828">CS502 Assignment No. 02 Solution and Discussion</a>:</p>
<blockquote>
<p dir="auto">You are required to design (write) the algorithm (Only Pseudo code) determined in Question 1.</p>
</blockquote>
<pre><code>Selectionsort (A , n)
{
For (i=0 to n-1)                                             
{
min  =  i      C1                         
For (  j = i+1 to n-1)                                         
{                                                             
C2
}
C3
}
}
</code></pre>
]]></description><link>https://community.secnto.com//post/1981</link><guid isPermaLink="true">https://community.secnto.com//post/1981</guid><dc:creator><![CDATA[zareen]]></dc:creator><pubDate>Thu, 28 Nov 2019 12:42:08 GMT</pubDate></item><item><title><![CDATA[Reply to CS502 Assignment No. 02 Solution and Discussion on Wed, 15 Jan 2020 09:12:19 GMT]]></title><description><![CDATA[<p dir="auto"><strong>Solution:</strong><br />
Question No. 01: The name of the algorithm being used for sorting the given array has given below.<br />
Selection sort<br />
Question No. 02: The Pseudo code for the algorithm used for sorting the given array has given below.</p>
<p dir="auto">Pseudo code:<br />
1 Selection sort (A)<br />
{<br />
2 For i 1 to A.lenght-1<br />
{<br />
3 imin i<br />
4 for j i+1 to A.length<br />
{<br />
5 If (A[j] &lt; A[imin])<br />
Imin j<br />
}<br />
6 Temp A[i]<br />
7 A[i] A[imin]<br />
8 A[imin] Temp<br />
}<br />
}</p>
<p dir="auto">Question No. 03: The step by stem analysis of the algorithm designed in question 2 is as follow,</p>
<p dir="auto">The time taken by each statement (step) is given as follows,</p>
<p dir="auto">Selection sort (A) Cost Times<br />
{<br />
For i 1 to A.length-1 c1 n<br />
{<br />
imin i-------------------- c2 n-1<br />
for j i+1 to A.length<br />
{ c3 n+n-1+…1=n(n+1)/2<br />
If (A[j] &lt; A[imin])<br />
imin j<br />
}<br />
Temp A[i] c4 n-1<br />
A[i] A[imin] c5 n-1<br />
A[imin] Temp c6 n-1<br />
}<br />
}</p>
<p dir="auto">Total time T(n) can be calculated as follows,</p>
<p dir="auto">T(n)= c1n+c2(n-1)+c3(n(n+1)/2)+c4(n-1)+c5(n-1)+c6(n-1)<br />
c1n+c2n-c2+c3 (n2+n/2) +c4n-c4+c5n-c5+c6n-c6 collect the like terms<br />
c3n2/2+ (c1+c2+c3/2+c4+c5+c6) n + (-c2-c4-c5-c6)</p>
<p dir="auto">This is equivalent to a polynomial an2+bn+c<br />
Therefore T (n) = Big O (n2) by taking the highest order term of the equation.<br />
Note: a, b, c in polynomial represents constants<br />
//   Ignoring constant terms</p>
<p dir="auto">T(n) = O (n2)</p>
]]></description><link>https://community.secnto.com//post/1980</link><guid isPermaLink="true">https://community.secnto.com//post/1980</guid><dc:creator><![CDATA[zareen]]></dc:creator><pubDate>Wed, 15 Jan 2020 09:12:19 GMT</pubDate></item><item><title><![CDATA[Reply to CS502 Assignment No. 02 Solution and Discussion on Thu, 28 Nov 2019 12:37:57 GMT]]></title><description><![CDATA[<p dir="auto"><a href="https://youtu.be/7T7QTy9z4CM" target="_blank" rel="noopener noreferrer nofollow ugc">https://youtu.be/7T7QTy9z4CM</a></p>
]]></description><link>https://community.secnto.com//post/1979</link><guid isPermaLink="true">https://community.secnto.com//post/1979</guid><dc:creator><![CDATA[zareen]]></dc:creator><pubDate>Thu, 28 Nov 2019 12:37:57 GMT</pubDate></item></channel></rss>