Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIGGLE SORT #1972

Open
Fatema110 opened this issue May 23, 2021 · 0 comments
Open

WIGGLE SORT #1972

Fatema110 opened this issue May 23, 2021 · 0 comments

Comments

@Fatema110
Copy link

This program accepts an array of unsorted numbers and
sorts the array such that arr[0]<arr[1]>arr[2]<arr[3]...

arr is sorted and stored in second array res
res is partitioned into two such that left sub-array 
contains elements less than the elements in right sub-array
Elements in the left sub-array  are added to the even indices of arr
Elements in the right sub-array are added to the odd indices of arr
  1. Sample input:1 3 2 2 3 1
    Sample output: [2,3,1,3,1,2]

  2. Sample input:1 4 6 2 3 7 9 2 1 0
    Sample Output: [2, 9, 2, 7, 1, 6, 1, 4, 0, 3]

Time Complexity: O(N log N) (Sorting takes O(N logN) and traversal takes O(N))
Space Complexity: O(N) (New array to store the wiggle sorted elements)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant