Questions tagged [mergesort]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0
votes
0answers
14 views

Creating my own Header file

I am at pset3 and I decided to try creating my own mergeSort header file. This is something that I have never attempted and haven't learned much about yet so I am at a loss. I have created the the ...
0
votes
1answer
28 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 ...
0
votes
1answer
31 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 ...
0
votes
1answer
219 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 ...
1
vote
1answer
352 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 ...
0
votes
1answer
395 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 ...
0
votes
1answer
93 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];...
0
votes
0answers
166 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 ...
0
votes
2answers
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 ...
0
votes
1answer
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 ...
1
vote
1answer
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 ...