This Python script implements a D-Array Max Heap, a variant of a max heap where each node has 'd' children. The implementation includes basic operations such as insertion, extraction of the maximum value, heapifying up and down, printing the heap, increasing the key of an index, and deleting an element from the heap.
-
Run the script using the command:
python d-array-heap.py file_name.txt
Replace
file_name.txtwith the name of the file containing integers separated by whitespace or commas. -
The script will prompt you to enter the value of 'd' for the D-Array Max Heap.
-
The script will read numbers from the specified file and insert them into the heap.
-
The heap will be printed, and various operations (extracting max value, increasing key, deleting key) will be performed.
The file specified should contain integers separated by whitespaces or commas.
insert(value): Inserts a value into the heap.extract_max(): Extracts the maximum value from the heap.increase_key(current_key, value): Increases the key of an index if the provided value is greater.delete_key(current_key): Deletes an element from the heap.
read_numbers(heap_, filename): Reads integers from a file and inserts them into a heap.get_d_array(): Gets the 'd' value from the user.
