This repository provides a straightforward Java implementation of the Merge Sort and Binary Search algorithms. The project is designed to demonstrate how these fundamental algorithms work with integer arrays. The Main
class initializes a random array, sorts it using Merge Sort, and then performs a Binary Search to find a specific element.
- Merge Sort: A highly efficient, stable, comparison-based sorting algorithm. It follows the divide-and-conquer paradigm by recursively dividing the array into halves, sorting them, and then merging them back together.
- Binary Search: An efficient algorithm for finding an item from a sorted array. It works by repeatedly dividing the search interval in half.
To compile and run this project from the command line, follow these steps:
-
Clone the repository:
git clone https://github.com/usernamedudh/19.1.-implementation-of-sorting-and-searching-algorithms-using-arrays.git cd 19.1.-implementation-of-sorting-and-searching-algorithms-using-arrays
-
Navigate to the
src
directory:cd src
-
Compile the Java source files:
javac app/Main.java app/ArrayUtils.java
-
Execute the main program:
java app.Main
The program generates a random array of 10 integers, sorts it, and then searches for one of its elements. The output will look similar to this (the actual numbers will vary on each run):
Початковий масив: [83, 12, 9, 45, 77, 62, 34, 58, 21, 99]
Відсортований масив: [9, 12, 21, 34, 45, 58, 62, 77, 83, 99]
Елемент 58 знайдено на позиції 5
src/app/ArrayUtils.java
: A utility class containing the static methodsmergeSort()
andbinarySearch()
. This class encapsulates the core algorithm logic.src/app/Main.java
: The main driver class. It initializes data, calls the sorting and searching methods fromArrayUtils
, and prints the results to the console to demonstrate their functionality.