Dsa Lab 04

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

ZIAUDDIN UNIVERSITY

Faculty Of Engineering Science & Technology


(ZUFEST)
Department of Software Engineering

Course Code/ Title: ASSESSMENT ACTIVITY: Semester:


Data Structure and Algorithm-Lab DSA LAB Task: 03 SE 2022 (Semester- III)

Dated: 23/01/2024 OBE Target: Weight of Marks:


CLO- 2, PLO- 3, P- 3 02
Teacher: Score:
Student Name:Mennam Fatima
Dr.Syed Atif &
Student ID:4-38-2023/035
Abdul Basit Naveed

Instructions:

Take snapshots of both input and output and provide a brief summary explaining what you
have learned in this lab.

Lab Tasks:

1) Write a program to show your understanding of sorting


by implementing bubble sort
● Ask the user to enter the max size of array then take
input of array elements.
● Sort the array using bubble sort algorithm in
ascending order.
2) Modify the task 1 code and print out the number of
iteration.
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering

3) Implement the Bubble Sort algorithm to sort the array in


ascending order using a separate function for swapping.

4) Take a worst case scenario array and apply bubble


sorting technique to sort it.

Worst case scenario example:


7,5,4,3,2,1

5) Make change in your previous algorithm. This time perform


sorting in descending Order.
6) Count the number of Swap in bubble sort.
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering

1) Write a program to show your understanding of sorting by implementing bubble sort


● Ask the user to enter the max size of array then take input of array elements.

● Sort the array using bubble sort algorithm in ascending order.

Code:

Output:
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering

2) Modify the task 1 code and print out the number of iteration.
Code:

Output:
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering

3) Implement the Bubble Sort algorithm to sort the array in ascending order using a separate function for
swapping.
Code:
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering

Output:
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering
4) Take a worst case scenario array and apply bubble sorting technique to sort it.
Code:

Output:

5) Make change in your previous algorithm. This time perform sorting in descending Order.
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering
Code:

Output:

6) Count the number of Swap in bubble sort.


Code:
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering

Output:

Summary:
In this lab we have learnt bubble sorting algorithm grasping the bubble sort algorithm by solving and analyzing various
problems like making function of swapping, doing ascending, and descending of swapping etc.

Examiner Signature: Student Score:

You might also like