CS210 DSA Lab 04
CS210 DSA Lab 04
LAB NO. 04
SORTING ALGORITHMS
Following are the lab objectives:
Objectives
Lab
ABDULLAH
Student ID 2636
Student Name
Obtained
Marks Comments
Marks
Task 1 10
Task 2 10
Task 3 10
Total
30
Marks
Lab Instructor
Date: 04-10-2019
1
CS 210 – Data Structures and Algorithms Lab Manual
CLOs
Lab Objectives
a b C
1
Instructions
This is individual Lab work/task.
Complete this lab work within lab timing.
Discussion with peers is not allowed.
You can consult any book, notes & Internet.
Copy paste from Internet will give you negative marks.
Lab work is divided into small tasks, complete all tasks sequentially.
Show solution of each lab task to your Lab Instructor.
In-Lab Exercises/Tasks
Write your code at provided space after each question
You need to upload code for all tasks at Google Class.
2
CS 210 – Data Structures and Algorithms Lab Manual
LAB TASKS
Task 1 (10 mark)
Write a function for Selection Sort, which uses while loop(s) to complete its procedure. Call the
function in main for demonstration. You can initialize array with random values.
#include<iostream>
#include<time.h>
using namespace std;
3
CS 210 – Data Structures and Algorithms Lab Manual
4
CS 210 – Data Structures and Algorithms Lab Manual
int n;
int data[500000];
//cout << "Enter size of Array:";
//cin >> n;
for (int i = 0;i < 500000;i++)
{
data[i] = rand()%30 + 1;
}
insertionSort(data, 500000);
cout << "Sorted array in ascending order:\n";
printArray(data, 500000);
et = time(0);
cout << endl;
cout << "Time:" << endl;
cout << et - rt << endl;
system("pause");
return 0;
}
Use code written in task 1 & 2 and execute it for different number of sizes. Fill the following
table accordingly.
100 0 0
500 1 0
1,000 0 1
5,000 2 3
10,000 5 5
25,000 12 11
50,000 26 24
1,00,000 67 49
5
CS 210 – Data Structures and Algorithms Lab Manual