| Subject Title | Introduction to Programming and Algorithm |
|---|---|
| Subject Code | PRO501AC |
| Assessment | 3 - Practical and Written |
| Individual/Group | Individual |
| Length | Code + Report |
| Learning Outcomes | 1,2,3,4,5,6 |
| Submission | TBA |
| Weighting | 40% |
| Total Marks | 40 |
Context
You are tasked with measuring and implementing an efficient sorting and searching algorithm to sort and search a large dataset of integers. The goal is to evaluate your understanding of various data structures and algorithms, as well as your ability to choose and implement an appropriate solution based on metrics.
Instructions
Assessment Tasks
This assessment has 2 Tasks:
Task 1: Python Program
Choose a sorting and a search algorithm that you believe is well-suited for the given problem. Consider factors such as time complexity, space complexity, and the characteristics of the dataset. Implement the chosen algorithms in Python and measure their performance in terms of time it takes to perform the searching and sorting tasks across datasets of 1000, 50000, 10000 and 100000 records.
Task 2: Report
You will submit a report that summarizes your choice of algorithm and data structure for searching and sorting in your application, the process you used to develop your solution, the test data sets used, along with specified metrics for the development. Run a selection of at least two search algorithms and 4 sorting algorithms, 3 from in-place sorting (such as bubble, selection and insertion) and 1 from either merge or quick sort. Document the following in your Report:
Testing:
Create 4 datasets with varying sizes (examples: 1000, 5000, 10000, 100000) to test the efficiency of your algorithms. Include the datasets used for testing along with your submission.
NOTE – You can use ChatGPT to produce the datasets of unsorted random integers. Searching and Sorting algorithms can be generated using ChatGPT along with code to generate the comparative Bar Graphs.
IMPORTANT: Document all the prompts you used in your Report.
You are to submit the following:
Online submissions via subject Study Hub/Open Learning site.
| Total number of marks – 40 | |
|---|---|
| Code in general | |
| Code adheres to the guidelines outlined in the PEP 8 Style Guide for Python code | 1 |
| Sorting algorithm | |
| Correctness and efficiency of the implemented sorting algorithm across 4 different size data sets | 2 |
| Time complexity between 4 sorting algorithms measured and displayed in a Bar Graph | 4 |
| Number of comparisons and swaps performed by the 4 selected sort algorithms and results displayed as a Bar Graph | 4 |
| Overview of the chosen sorting algorithm | 1 |
| Explanation of how the algorithm works. | 1 |
| Discussion of why you chose this algorithm over other alternatives. based on the measures data | 4 |
| Searching Algorithm | |
| Correctness and efficiency of the implemented searching algorithm | 2 |
| Time complexity analysis of the three search algorithms across all datasets | 4 |
| Overview of the chosen searching algorithm. | 1 |
| Explanation of how the algorithm works. | 1 |
| Bar Graphs generated across all datasets and a discussion of why you chose this algorithm over other alternatives. | 4 |
| General | |
| Correct files submitted including types and names (zip and Word) | 2 |
| Reflection Report | |
| Report presentation and comments including how long the programs took to create and any problems encountered | 2 |
| Details of the process they used to develop their solution is provided | 2 |
| The test data sets used, along with specified metrics for the development | 1 |
| Screen shots of testing and annotations | 2 |
| Reflection on the development process, including what you learned and how you would improve the implementation in the future. | 2 |
Note: This report is provided as a sample for reference purposes only. For further guidance, detailed solutions, or personalized assignment support, please contact us directly.
Sample Solution for PRO501AC – Assessment 3
Computer Science Introduction to Programming and Algorithm
This sample solution includes:
Task 1 – Python Program
Selected Sorting Algorithms
In-Place Sorting Algorithms
Efficient Sorting Algorithm
Selected Searching Algorithms
Why These Algorithms?
| Algorithm | Reason |
|---|---|
| Bubble Sort | Simple comparison-based algorithm |
| Selection Sort | Performs fewer swaps |
| Insertion Sort | Efficient for partially sorted data |
| Quick Sort | Very fast for large datasets |
| Linear Search | Works on unsorted data |
| Binary Search | Extremely fast on sorted data |
Sample Python Code
import random
import time
import matplotlib.pyplot as plt
# -----------------------------------
# DATASET GENERATION
# -----------------------------------
sizes = [1000, 5000, 10000, 100000]
datasets = {}
for size in sizes:
datasets[size] = random.sample(range(1, size * 10), size)
# -----------------------------------
# SORTING ALGORITHMS
# -----------------------------------
def bubble_sort(arr):
arr = arr.copy()
n = len(arr)
swaps = 0
comparisons = 0
start = time.time()
for i in range(n):
for j in range(0, n - i - 1):
comparisons += 1
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
swaps += 1
end = time.time()
return end - start, swaps, comparisons
def selection_sort(arr):
arr = arr.copy()
n = len(arr)
swaps = 0
comparisons = 0
start = time.time()
for i in range(n):
min_idx = i
for j in range(i + 1, n):
comparisons += 1
if arr[j] < arr[min_idx]:
min_idx = j
arr[i], arr[min_idx] = arr[min_idx], arr[i]
swaps += 1
end = time.time()
return end - start, swaps, comparisons
def insertion_sort(arr):
arr = arr.copy()
swaps = 0
comparisons = 0
start = time.time()
for i in range(1, len(arr)):
key = arr[i]
j = i - 1
while j >= 0 and key < arr[j]:
comparisons += 1
arr[j + 1] = arr[j]
swaps += 1
j -= 1
arr[j + 1] = key
end = time.time()
return end - start, swaps, comparisons
def quick_sort(arr):
comparisons = [0]
def _quick_sort(items):
if len(items) <= 1:
return items
pivot = items[len(items) // 2]
left = []
middle = []
right = []
for x in items:
comparisons[0] += 1
if x < pivot:
left.append(x)
elif x == pivot:
middle.append(x)
else:
right.append(x)
return _quick_sort(left) + middle + _quick_sort(right)
start = time.time()
sorted_arr = _quick_sort(arr.copy())
end = time.time()
swaps = 0
return end - start, swaps, comparisons[0]
# -----------------------------------
# SEARCHING ALGORITHMS
# -----------------------------------
def linear_search(arr, target):
start = time.time()
for i in range(len(arr)):
if arr[i] == target:
end = time.time()
return end - start
end = time.time()
return end - start
def binary_search(arr, target):
start = time.time()
low = 0
high = len(arr) - 1
while low <= high:
mid = (low + high) // 2
if arr[mid] == target:
end = time.time()
return end - start
elif arr[mid] < target:
low = mid + 1
else:
high = mid - 1
end = time.time()
return end - start
# -----------------------------------
# TESTING
# -----------------------------------
sorting_results = {}
for size in sizes:
data = datasets[size]
sorting_results[size] = {}
sorting_results[size]["Bubble"] = bubble_sort(data)
sorting_results[size]["Selection"] = selection_sort(data)
sorting_results[size]["Insertion"] = insertion_sort(data)
sorting_results[size]["Quick"] = quick_sort(data)
print(f"\nDataset Size: {size}")
for algo, result in sorting_results[size].items():
print(algo, result)
# -----------------------------------
# SEARCH TESTING
# -----------------------------------
search_results = {}
for size in sizes:
data = sorted(datasets[size])
target = data[len(data) // 2]
linear_time = linear_search(data, target)
binary_time = binary_search(data, target)
search_results[size] = {
"Linear": linear_time,
"Binary": binary_time
}
# -----------------------------------
# BAR GRAPH
# -----------------------------------
quick_times = []
bubble_times = []
for size in sizes:
bubble_times.append(sorting_results[size]["Bubble"][0])
quick_times.append(sorting_results[size]["Quick"][0])
plt.bar([str(s) for s in sizes], bubble_times, label='Bubble')
plt.bar([str(s) for s in sizes], quick_times, label='Quick')
plt.xlabel("Dataset Size")
plt.ylabel("Time Taken")
plt.title("Sorting Algorithm Comparison")
plt.legend()
plt.show()
Sample Dataset Generation
You must also submit datasets.
Example:
import random
data_1000 = random.sample(range(1, 10000), 1000)
with open("dataset_1000.txt", "w") as file:
for item in data_1000:
file.write(str(item) + "\n")
Repeat for:
Task 2 – Sample Report Structure
Title Page
Table of Contents
1. Introduction
This report evaluates the performance of various sorting and searching algorithms using Python programming. The algorithms were tested on datasets of different sizes to compare efficiency based on execution time, comparisons, and swaps.
2. Sorting Algorithms Overview
Bubble Sort
Bubble Sort repeatedly compares adjacent elements and swaps them if they are in the wrong order.
Advantages
Disadvantages
Selection Sort
Selection Sort finds the minimum value and places it in the correct position.
Advantages
Disadvantages
Insertion Sort
Insertion Sort inserts elements into the correct position one by one.
Advantages
Disadvantages
Quick Sort
Quick Sort uses divide-and-conquer strategy.
Advantages
Disadvantages
3. Searching Algorithms Overview
Linear Search
Checks every element one by one.
Binary Search
Repeatedly divides the sorted dataset into halves.
4. Testing Datasets
| Dataset | Number of Records |
|---|---|
| Dataset 1 | 1000 |
| Dataset 2 | 5000 |
| Dataset 3 | 10000 |
| Dataset 4 | 100000 |
5. Results and Analysis
Sorting Time Comparison
(Add Bar Graph Screenshot)
Discussion
Quick Sort produced the fastest results because its average time complexity is:
O(nlogn)O(n\log n)O(nlogn)
Bubble Sort showed the slowest performance due to:
O(n2)O(n^2)O(n2)
6. Comparison of Swaps and Comparisons
| Algorithm | Swaps | Comparisons |
|---|---|---|
| Bubble Sort | High | High |
| Selection Sort | Low | High |
| Insertion Sort | Medium | Medium |
| Quick Sort | Very Low | Low |
7. Best Algorithm Selection
Quick Sort was selected as the best sorting algorithm because it had:
Binary Search was selected as the best searching algorithm because it performs much faster on sorted datasets.
8. Problems Encountered
9. Reflection
This assessment improved my understanding of algorithms, time complexity, and performance analysis. I learned how different algorithms behave with large datasets and how to measure their efficiency using Python. In the future, I would improve the implementation by using advanced algorithms such as Merge Sort and Hash Searching.
10. ChatGPT Prompts Used
Example:
Files to Submit
Python Files
Dataset Files
Report File
Final Submission
Recommended Folder Structure
PRO501AC_Assessment3/
│
├── datasets/
├── graphs/
├── python_code/
├── screenshots/
└── report/
Get original papers written according to your instructions and save time for what matters most.