diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..f5c1c98 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,14 @@ +# These are supported funding model platforms + +github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] +patreon: # Replace with a single Patreon username +open_collective: # Replace with a single Open Collective username +ko_fi: # Replace with a single Ko-fi username +tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel +community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry +liberapay: # Replace with a single Liberapay username +issuehunt: # Replace with a single IssueHunt username +otechie: # Replace with a single Otechie username +lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry +custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] +QWEQWEEWQ diff --git a/README.md b/README.md index e4aa1ee..245fc52 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# GITA-Masala (: +# algorithms .GITA-Masala (: # Ketgan Vaqt wakatime - +#LeetCode bajarishdan oldin bu masalalarni yechish tavsiya beriladi # Foydalanilgan Manba GITA diff --git a/src/MergeSortApp.java b/src/MergeSortApp.java new file mode 100644 index 0000000..733fd6e --- /dev/null +++ b/src/MergeSortApp.java @@ -0,0 +1,64 @@ +package sorting; + +import java.util.Arrays; + +public class MergeSortApp { + + //Time complexity: O(N * logN) + //Space complexity: O(N) + private static class MergeSort { + private int[] array; + + public void mergeSort(int[] arr) { + array = arr; + int len = array.length; + int[] workspace = new int[len]; + recursiveMergeSort(workspace, 0, len - 1); + } + + private void recursiveMergeSort(int[] workSpace, int lowerBound, + int upperBound) { + if (lowerBound == upperBound) { + return; + } else { + int mid = (lowerBound + upperBound) / 2; + recursiveMergeSort(workSpace, lowerBound, mid); + recursiveMergeSort(workSpace, mid + 1, upperBound); + merge(workSpace, lowerBound, mid + 1, upperBound); + } + } + + private void merge(int[] workspace, int lowPointer, + int highPointer, int upperBound) { + int i = 0; + int lowerBound = lowPointer; + int mid = highPointer - 1; + int numberOfItems = upperBound - lowerBound + 1; + + while (lowPointer <= mid && highPointer <= upperBound) { + if (array[lowPointer] < array[highPointer]) { + workspace[i++] = array[lowPointer++]; + } else { + workspace[i++] = array[highPointer++]; + } + } + + while (lowPointer <= mid) + workspace[i++] = array[lowPointer++]; + + while (highPointer <= upperBound) + workspace[i++] = array[highPointer++]; + + for (i = 0; i < numberOfItems; i++) + array[lowerBound + i] = workspace[i]; + } + } + + public static void main(String[] args) { + MergeSort mergeSort = new MergeSort(); + int[] arr = new int[]{6, 5, 3, 1, 8, 7, 2, 4}; + System.out.println("Before: " + Arrays.toString(arr)); + mergeSort.mergeSort(arr); + System.out.println("After: " + Arrays.toString(arr)); + } +} pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy