Skip to content

Analysis & Comparison of Bottom- up and Top-down Build Heap Approaches

Notifications You must be signed in to change notification settings

AbanoubYossef/Bottom--up-and-Top-down-Build-Heap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

Heap Sort and Heap Construction Analysis

This repository contains Python code for analyzing and comparing the performance of heap construction methods, both in the average and worst-case scenarios, using the Heap Sort algorithm.

Table of Contents

Introduction

Heap Sort is a comparison-based sorting algorithm that makes use of a binary heap data structure. This repository includes Python code for performing an analysis of the heap construction methods in two scenarios: average-case and worst-case.

The heap construction methods analyzed include:

  • Bottom-Up Build Heap
  • Top-Down Build Heap

Usage

To run the code and perform the analysis, follow these steps:

  1. Clone this repository to your local machine:

    git clone https://github.com/yourusername/heap-sort-analysis.git
    
  2. Ensure you have Python installed on your system.

  3. Install the required libraries using pip:

    pip install matplotlib
    
  4. Run the analysis by executing the analysis.py script:

    python analysis.py
    
  5. The analysis results will be displayed in the form of plots for both average and worst-case scenarios.

Functions

The code includes several functions, each serving a specific purpose:

  • heapify: Maintains the heap property in a max-heap.
  • build_heap_bottom_up: Creates a max-heap using the bottom-up approach.
  • insert_top_down: Inserts an element into a max-heap using the top-down approach.
  • build_heap_top_down: Creates a max-heap using the top-down approach.
  • heap_sort: Sorts a list using the heap sort algorithm.
  • generate_random_data: Generates a list of random data.
  • average_case_analysis: Analyzes the average case performance of the heap construction methods and plots the results.
  • worst_case_analysis: Analyzes the worst case performance of the heap construction methods and plots the results.

Average Case Analysis

The average_case_analysis function generates random data and measures the average case performance of both heap construction methods. It produces plots illustrating comparisons, assignments, and total operations.

Worst Case Analysis

The worst_case_analysis function analyzes the worst case performance of the heap construction methods. It generates data that represents the worst-case scenario and produces plots for comparisons and assignments in the worst case.

You should replace "https://github.com/yourusername/heap-sort-analysis.git" with the actual URL of your repository. Make sure to provide a detailed explanation of how to use the code and describe the functions used in your analysis. Additionally, include a section about the license to make it clear how others can use your code.

About

Analysis & Comparison of Bottom- up and Top-down Build Heap Approaches

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages