0% found this document useful (0 votes)
13 views1 page

Sorting Algorithms Tutorial DSA1

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)
13 views1 page

Sorting Algorithms Tutorial DSA1

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

Data Structure & Algorithms 1 (DSA1)

Tutorial (week 12) - Static Data Structure: Sorting Algorithms


2024 - 2025

15 December 2024

OBJECTIVES
Implement sorting algorithms:

Exercise 1:
Write a pseudo-code to perform a sorting operation (using Bubble Sort) on an array of strings based on
their lengths in ascending order. If two strings have the same length, they should be sorted lexicographically
within that length group.
You are allowed to use the predefined functions for string manipulation that have been in the lecture.

Example:
Input Array: arr = [”banana”, ”apple”, ”cherry”, ”date”, ”kiwi”]
Final Sorted Array: arr = [”date”, ”kiwi”, ”apple”, ”banana”, ”cherry”]

Exercise 2:
Write a pseudo-code for an Insertion Sort algorithm to sort an array of tuples, where each tuple represents
a student record. Each student record contains: ID (an integer) Name (a string) Grade (a float) You need
to sort the array of student records first by grade in descending order, and if two students have the same
grade, sort them by name in ascending order.

Example:
Input array: arr = [(101, ”John”, 88.5), (102, ”Alice”, 91.0), (103, ”Bob”, 88.5), (104, ”Carol”, 92.0), (105,
”David”, 91.0)]
Output array: arr = [(104, ”Carol”, 92.0), (102, ”Alice”, 91.0), (105, ”David”, 91.0), (101, ”John”, 88.5),
(103, ”Bob”, 88.5)]

You might also like