Questions tagged [mergesort]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
32 views

Week 2 Merge Sort: Why is it assumed that the elements will be in order when they are merged?

When using the Merge Sort algorithm, I feel like everything makes sense until we start "merging" the elements back together. Why is it assumed implicitly that the process of merging will put the ...
user avatar
  • 19
0 votes
1 answer
32 views

Why do I have to declare variables outside of my main function for them to be picked up? (Scope)

If I place my arrays outside of the main function as global variables, my Merge-Sort works. If i declare unsortedArray or tempArray or BOTH inside of the main function, the terminal lights up with ...
user avatar
  • 103
0 votes
1 answer
258 views

Need Help In Merge Sort

From last couple of days I am trying to write code for Merge sort. I have completed Week3 lectures and trying to solve pset3. Need some help in my code for merge sort. The code seems to work fine with ...
user avatar
1 vote
1 answer
402 views

Recommended to use merge sort if less comfortable?

Merge sort seems somewhat difficult to implement, and honestly I feel like I'm out of my depth whenever I try to work on it. Also, I believe that merge sort would require that I have a better ...
user avatar
0 votes
1 answer
409 views

The Merge sort Algorithm

Why does merge sort require o(n) steps to merge the two sorted halves? Assuming this is the last merging step in the algorithm: 1 3 5 7 | 13 19 20 40 Doesn't this require only n/2 steps to compare ...
user avatar
  • 54
0 votes
1 answer
98 views

pset 3 mergesorting in helpers.c is giving me a segmentation fault

I have been trying to implement mergesort for the "sort" part of pset 3 - but it is giving me a segmentation fault every time I try. Help :/ void sort(int haystack[], int n) { int temp[n + 1 / 2];...
user avatar
  • 1
0 votes
0 answers
171 views

Merge sort code giving seg fault after providing array of integers

I was implementing mergesort and I am coming across segmentation fault whenever i provide it an array of integers. I ran gdb but couldn't figure it out. Can anyone pls help me. I am attaching my code ...
user avatar
0 votes
2 answers
1k views

Merge Sort running into infinite loop using recursion

When i try to run my code using using recursion i get stuck in an infinite loop. this is my first time implementing divide and conquer using recursion so i am a bit rusty on the concepts. Please have ...
user avatar
0 votes
1 answer
2k views

Try to sort strings with merge sort

How do I sort a 2D-array(strings) using merge sort? e.g. arr[0] = "foo"; arr[1] = "bar"; and I hope it to be like arr[0] = "bar"; arr[1] = "foo"; after being sorted but it doesn't work Need some ...
user avatar
  • 105
1 vote
1 answer
1k views

How is mergesort a O(n log n)?

After the lecture, I still do not quite understand why the upper bound of mergesort is n log n. I've tried to connect it with the phone book problem, which helped a little, but still don't really get ...
user avatar
  • 105