Skip to content

abhay-2003/Multithreading-in-Python

Repository files navigation

πŸš€ Multithreading in Python – Assignment Project

Welcome to my multithreaded programming project for the Advanced Programming course. This project demonstrates how Python's threading module can be used to parallelize common algorithms and tasks, improving performance through concurrency.


πŸ“‚ Project Structure

File Name Description
01_multithreaded_merge_sort.py Multi-threaded implementation of Merge Sort
02_multithreaded_quicksort.py Multi-threaded implementation of Quick Sort
03_concurrent_file_downloader.py Downloads multiple files concurrently using threads

Each script includes both single-threaded and multi-threaded implementations, along with performance comparisons.


🧡 Task 1: Multi-threaded Merge Sort

This script parallelizes the classic merge sort algorithm using Python’s threading module.

  • Recursively splits the array and sorts sub-arrays in separate threads.
  • Merges sorted results.
  • Compares execution time with the single-threaded version.

πŸ“Œ Run with:

python 01_multithreaded_merge_sort.py

⚑ Task 2: Multi-threaded Quicksort

This script introduces concurrency into the quicksort algorithm.

  • Sub-arrays are sorted in parallel threads after partitioning.
  • Thread count is managed to prevent system overload.
  • Execution time of threaded vs non-threaded versions is compared.

πŸ“Œ Run with:

python 02_multithreaded_quicksort.py

🌐 Task 3: Concurrent File Downloader

This program downloads multiple files from the internet using threads.

βœ… Features:

  • Accepts URLs from the user, a text file, or a built-in sample list.
  • Downloads files both sequentially and concurrently using Python threads.
  • Prints time taken for both approaches and calculates the speedup.

πŸ“Œ Run with:

python 03_concurrent_file_downloader.py

πŸ”— Sample Test URLs (Safe to Download):

These files are publicly available and used only for testing download speed.


πŸ§ͺ Performance Overview

Each script includes time tracking to showcase the benefit of multithreading for both I/O-bound and divide-and-conquer problems.

πŸ“Š Expected Outcome:

  • Merge Sort: ~2–3x faster with threads on large arrays.
  • Quicksort: Performance gains vary based on thread limits and input size.
  • File Downloader: Threads dramatically reduce total download time.

πŸ› οΈ Requirements

  • Python 3.x
  • No external libraries required (uses only built-in modules like threading, time, urllib, etc.)

πŸ‘¨β€πŸŽ“ Author

Abhay Singh
BTech – Computing & Data Science
Sai University, Chennai

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages