0% found this document useful (0 votes)
4 views

algorithms lab2

The document outlines a course assignment for Algorithms Lab (CSE 232) at Bangladesh University of Business & Technology, submitted by Mehrab Hossain Alvy. It includes three tasks: sorting a list of integers using Heap Sort, finding the k-th largest element in an array, and sorting a list of strings based on their length with a custom comparator. Each task provides input data and expected output results.

Uploaded by

neonmann814
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

algorithms lab2

The document outlines a course assignment for Algorithms Lab (CSE 232) at Bangladesh University of Business & Technology, submitted by Mehrab Hossain Alvy. It includes three tasks: sorting a list of integers using Heap Sort, finding the k-th largest element in an array, and sorting a list of strings based on their length with a custom comparator. Each task provides input data and expected output results.

Uploaded by

neonmann814
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Bangladesh University of Business & Technology

Course name:Algorithms Lab


Course code:CSE 232

Submitted by:Mehrab Hossain Alvy


Id:20234103039
Intake:52
Section:01

Submitted to:Sajid Ahmed Chowdhury


(Lecturer)
Dept. of CSE
Task 01:Sorting a Small List
You are given a small list of integers: [10, 3, 15, 7, 8, 23, 74, 18]. Use the Heap Sort algorithm to
sort the list in descending order.
• Input: [10, 3, 15, 7, 8, 23, 74, 18]
• Expected Output: [74, 23, 18, 15, 10, 8, 7, 3]
Code:

Output:

Task 02:Kth Largest Element in an Array


Given an unsorted list of integers: [5, 12, 7, 1, 3, 10, 9, 8], and an integer k = 2, find the
k-th largest element in the list using Heap Sort. Instead of sorting the entire list, adjust
the algorithm to find the k-th largest element efficiently.
Test Case:
• Input: [5, 12, 7, 1, 3, 10, 9, 8], k = 2
• Expected Output: 10
Code:

Output:

Task 03:Heap Sort with Custom Comparator


Given a list of strings: [”apple”, ”banana”, ”cherry”, ”date”, ”f ig”, ”grape”], sort the list
in descending order of string length using Heap Sort. If two strings have the same length,
maintain their original relative order (stable sorting).
Test Case:
• Input: [”apple”, ”banana”, ”cherry”, ”date”, ”f ig”, ”grape”]
• Expected Output: [”banana”, ”cherry”, ”apple”, ”grape”, ”date”, ”fig”]

Code:

Output:

You might also like