Skip to content

Fix naming convention and memory inefficiency in merge_sort.java #775

Description

@Gorlesunilkumar

1.Class name violates Java naming conventions // issue 1

public class merge_sort {

Problem: Java class names must start with a capital letter and follow PascalCase (e.g., MergeSort).
This is a core Java standard and affects readability and style consistency across the project.

Fix:

public class MergeSort {

2.Memory inefficiency due to new array creation in every merge // issue 2

int merge[] = new int[ei - si + 1];

Each recursive call of conquer() allocates a new temporary array, increasing memory usage unnecessarily.
This causes extra space complexity (O(n log n)) instead of O(n).

Fix:
Use a single global or reusable temporary array for all merges to improve efficiency:

int[] temp = new int[arr.length];
mergeSort(arr, temp, si, ei);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions