Skip to main content
-7 votes
1 answer
163 views

Merge sort for Linked List

The merge sort code on Leetcode giving stack-overflow error. ListNode *findMiddle(ListNode *head){ if (!head) return nullptr; ListNode *slow=head; ListNode *fast=head; while (fast!=...
Amit Kumar's user avatar
1 vote
1 answer
112 views

Mergesort for singly-linked lists gives correct results but leaks memory

I'm working on an assignment to implement mergesort for singly-linked lists in C++. The merge function needs to merge two sorted lists in-place without creating new nodes. The mergesort function ...
Milad Khazani's user avatar
1 vote
1 answer
42 views

What I have done wrong in this merge sort algorithm in java

class FirstClass { public static void divide(int[] arr) { if(arr.length == 1) { return; } int mid = arr.length/2; int[] leftHalf = new int[mid]; ...
Mohd. Saad Haider's user avatar
-1 votes
1 answer
80 views

Segmentation fault in my code SLL Natural Merge Sort in C++

This is my code SLL Natural Merge Sort in C++: #include <stdio.h> #include <stdlib.h> typedef struct Node{ int data; Node* link; }NODE; typedef struct List{ NODE* first; ...
Huy Trần Ngọc's user avatar
0 votes
1 answer
64 views

Merge sorting algorithm works for small list but crashes with bigger ones

I'm trying to recreate the merge sorting algorithm and while my code works for lists with length 4 or less when the length gets bigger it crushes. As you'll see the error says that on some point ...
Nico Mcrae's user avatar
0 votes
1 answer
89 views

Merge sort algorithm parallelization speed-up

I am doing a theoretical exercise for a class about a theoretical study of parallelizing the mergesort algorithm and the speed-up obtained for different amounts of cores. I am using the following ...
tiredStudent's user avatar
2 votes
2 answers
60 views

MergeSort implementation doesn't work correctly

I've been trying to implement MergeSort in Python from the book Introduction to Algorithms and I don't know why this version is not working correctly (it does compile but the list isn't sorted ...
KrzysiekYESS's user avatar
1 vote
1 answer
95 views

How do I express the speedup of the merge sort algorithm when I parallelize the divide step?

I am trying to solve the following exercise: Consider the following recursive mergesort algorithm (another classic divide and conquer algorithm). Mergesort was first described by John Von Neumann in ...
tiredStudent's user avatar
0 votes
1 answer
116 views

Compare Runtime of Merge Sort, Natural Merge Sort and Quick Sort. Elements=1000000

When I enter more than 250 elements When I run the program without inserting Natural Merge Sort code, my program can run with 1000000 elements, but after I inserted Natural Merge Sort, my program can ...
Hoàng Anh Trần's user avatar
0 votes
1 answer
25 views

fundamental differences between in-place merging and in-place mergesort

I have been pondering the basic big O performance of the functions, in isolation or in collaboration with each other. So IPM(S) is a function that does an in-place merge of S, and IPMS(S) is a ...
Fuzzy Coder's user avatar
2 votes
1 answer
60 views

Simple Merge sort code behaving strangely by working 50% of the time for the same input

I wrote the following simple code for Merge sort: It is behaving strangely because the array: {38, 27, 43, 3, 9, 82, 10} gets sorted as: {3 9 10 27 38 43 82 } and sometimes as: {-1707474943 3 9 10 27 ...
ar moosa's user avatar
1 vote
0 answers
44 views

For loop inside an omp task

I have this code, parallel odd-even merge sort. I am now trying to optimize it more, and I think a good idea is to parallelize the for loop that is commented, as those comparisons are independent. But,...
Marcos Alonso's user avatar
0 votes
0 answers
43 views

Best approach for recursion using OpenMP

I am parallelizing odd-even Merge Sort. But I only get worst results with the parallel approach than the sequential one. void oddEvenMergeSort(int *arr, int n) { if (n > 1) { int m = n /...
Marcos Alonso's user avatar
0 votes
0 answers
23 views

Why is my sorting algorithm not showing the desired output?

My question is with the counting. In my problem the number of the operations after sorting is not giving the same amount as it should. I am using the general logic for the selection sort, insertion ...
mehrab.4's user avatar
0 votes
3 answers
69 views

Purpose of last 2 while loops in the merge algorithm of merge sort sorting technique

The code below was taught in my Data Structures and Algorithms class. I am currently reviewing it in preparation for exams. The code, by the lecturer, works well. #include<iostream> #define size ...
Margret Mauno's user avatar

15 30 50 per page
1
2 3 4 5
186