Lab7 DSA BSEE20034
Lab7 DSA BSEE20034
Lab7 DSA BSEE20034
Checked on:
Signature:
7.1 Objective
The goal of this handout is to learn about how merge sort and quick sort are used to sort an
integer array and why they are called Divide and Conquer algorithms.
7.2 Equipment and Component
Component Value Quantity
Description
Computer Available in lab 1
#include<iostream>
using namespace std;
}
swap(arr[i+1],arr[r]);
return (i+1);
}
int main()
{
int arr[10]={3,7,9,1,5,2,6,12,13,11};
partion(arr,0,9);
for(int i=0; i<10; i++)
{
cout<<arr[i]<<" ";
}
Q2. a) Write a randomized partition function that chooses randomly the index number for the pivot
on every call.
Use the rand () function for a random number in C++.
The random number must be restricted to the range of the indexes of your array.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
// This program will create same sequence of
// random numbers on every program run
return 0;
}
int i=l-1;
for(int j=l; j<r; j++)
{
if(arr[j]<=pivot)
{
i++;
swap(arr[i],arr[j]);
}
}
swap(arr[i+1],arr[r]);
return (i+1);
}
}*/
void printArray(int arr[], int size)
{
int i;
for (i = 0; i < size; i++)
cout<<arr[i]<<" ";
}
int main()
{
int arr[10]={3,7,9,1,5,2,6,12,13,11};
partion(arr,0,9);
for(int i=0; i<10; i++)
{
cout<<arr[i]<<" ";
}
}
Part(b)
Quick sort is a in place sorting algorithm. Because portion function does give
an array and an element x of array as
pivot, put x at its correct position in sorted array and put all smaller elements (smaller than x) before x,
and put all greater elements (greater than x) after x.
Q3. Write code for the quicksort function, your task is to work out
a) arguments to the Quicksort function
b) base case that will terminate or end recursion
c) arguments to the Partition function [10 Mark]
#include<iostream>
using namespace std;
}
swap(arr[i+1],arr[r]);
return (i+1);
}
}
int main()
{
int arr[10]={3,7,9,1,5,2,6,12,13,11};
quicksort(arr,0,4);
}
Student Name Registration# Batch: EE-2020
Assessment Rubrics
Method: Lab reports and instructor observation during lab sessions.
Outcome assessed:
a. Ability to conduct experiments, as well as to analyze and interpret data (P)
b. Ability to function on multi-disciplinary teams (A)
c. Ability to use the techniques, skills, and modern engineering tools necessary for engineering practice (P)
Performance metric Mapping (task no. Max Exceeds expectation Meets expectation Does not meet expectation Obtained
and description) marks marks
1. Realization of 1 Functionality 40 Executes without errors excellent Executes without errors, user Does not execute due to syntax errors,
experiment (a) user prompts, good use of prompts are understandable, runtime errors, user prompts are
symbols, spacing in output. minimum use of symbols or spacing misleading or non-existent. No testing has
Through testing has been in output. Some testing has been been completed (20-0)
completed (45-41) completed (40-21)
2. Teamwork (b) 1 Group 5 Actively engages and cooperates Cooperates with other group Distracts or discourages other group
Performance with other group member(s) in member(s) in a reasonable manner members from conducting the experiment
effective manner (5-4) but conduct can be improved (3-2) (1-0)
3. Conducting 1 On Spot 10 Able to make changes (5-4) Partially able to make changes (3-2) Unable to make changes (1-0)
experiment (a, c) Changes
2 Viva 10 Answered all questions (5-4) Few incorrect answers (3-2) Unable to answer all questions (1-0)
4. Laboratory safety 1 Code 5 Observes lab safety rules; Generally, observes safety rules and Disregards lab safety and disciplinary rules
and disciplinary rules commenting adheres to the lab disciplinary disciplinary guidelines with minor (1-0)
(a) guidelines aptly (5-4) lapses (3-2)
5. Data collection (c) 1 Code Structure 5 Excellent use of white space, Includes name, and assignment, Poor use of white space (indentation, blank
creatively organized work, white space makes the program lines) making code hard to read,
excellent use of variables and fairly easy to read. Title, organized disorganized and messy (1-0)
constants, correct identifiers for work, good use of variables (3-2)
constants, No line-wrap (5-4)
6. Data analysis (a, c) 1 Algorithm 20 Solution is efficient, easy to A logical solution that is easy to A difficult and inefficient solution (1-0)
understand, and maintain (5-4) follow but it is not the most
efficient (3-2)
7. Computer use (c) 1 Documentation 5 Timely documented (5-4) Late documented (3-2) Not documented (1-0)