Questions tagged [mergesort]

The tag has no usage guidance.

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

How to merge sort array of struct while maintaining relations between int array and char array

Does anyone know how I could maintain relations between the char and int in structs while merge sorting the ints in the struct? So if I had nameandnumber[1].buffer assigned a value that used to be at ...
user21380365's user avatar
0 votes
0 answers
13 views

Merge Sort segmentation fault

I am trying to learn how to implement Merge Sort. With the code below, I keep getting a Segmentation Fault. Does anyone know why? Thanks! // 6/30/23: Segmentation fault (core dumped)?!?! #include <...
Joseph J Filoramo's user avatar
0 votes
0 answers
7 views

Sorting an array based on ints within a strut

I'm looking for a way to implement merge sort to sort the pairs[] array in the tideman problem. The problem being the array is made up of the strut pair, not ints. However, I have added an element to ...
Gavin Colonese's user avatar
0 votes
1 answer
43 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 ...
Xia Liu's user avatar
  • 19
0 votes
1 answer
37 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 ...
Mikhail's user avatar
  • 103
0 votes
1 answer
273 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 ...
Ankush Agrawal's user avatar
1 vote
1 answer
416 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 ...
Mazer Rackham's user avatar
0 votes
1 answer
451 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 ...
qwerty's user avatar
  • 64
0 votes
1 answer
102 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];...
Reuben's user avatar
  • 1
0 votes
0 answers
173 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 ...
Arun Kumar's 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 ...
Ujjwal Arora's 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 ...
Y_C's user avatar
  • 115
2 votes
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 ...
Y_C's user avatar
  • 115