NAME: VICTOR ANUOLUWAPO
DEPARTMENT: COMPUTER SCIENCE GROUP B
MATRIC NO: 21/1773
COURSE: COSC 302- DATA STRUCTURES AND ALGORITHM
ASSIGNMENT
1. Write and explain all the different examples of external sorting algorithms
1. Merge Sort : is the most widely used algorithm for external sorting. It is an adaptation of
the classic merge sort for handling large datasets.
Steps: Divide: Split the data into chunks that fit into memory. Sort each chunk using an
internal sorting algorithm (e.g., quicksort or heapsort) and write the sorted chunks
back to disk.
Merge: Merge the sorted chunks using a multi-way merge. This involves reading
parts of each chunk into memory, merging them, and writing the sorted output to
disk.
Example: For a large dataset, split it into smaller chunks, sort each chunk in memory, and
then merge these sorted chunks until the entire dataset is sorted.
2. Polyphase Merge Sort : is an optimized version of merge sort that reduces merge passes
and uses available tapes or disk drives efficiently.
Steps: Divide: Divide the data into initial runs.
Distribute: Distribute the runs across multiple tapes or files.
Merge: Merge runs from multiple sources in a staggered fashion, using a Fibonacci-
like distribution to minimize merge passes.
Example: With three tapes (A, B, and C), distribute initial runs across these tapes, then use
two tapes to merge runs and output to the third tape, repeating until sorted.
3. Balanced Multiway Merge Sort :splits data into multiple segments and merges them in
parallel.
Steps: Divide: Divide data into N sorted runs that fit into memory.
Merge: Use N-way merging, where N is the number of runs. Read one block from
each run into memory, merge these blocks, and write the merged output to disk.
Example: If you have a dataset split into 10 sorted runs, merge them by reading from all 10
simultaneously, merging the blocks, and writing the sorted data to disk.
4. K-way Merge Sort :merges more than two runs at a time, optimizing disk I/O operations.
Steps: Divide: Divide data into K sorted runs.
Merge: Perform a K-way merge where K is based on available memory. Use a
priority queue (min-heap) to merge the smallest elements from each run.
2. Write a program either Java/C++/python to implement linear search, binary search, and all
the various types of sorting (internal, external…..and the rest)
Using java:
Linear search:
Result:
Binary search:
Result:
Bubble Sort:
Result:
Insertion Sort:
Result:
Quick Sort:
Result: