2,786 questions
0
votes
2
answers
291
views
Why does using >= increase merge sort time complexity
I recently solved the Merge Sorted Array question on leetcode
Here is the part of the code I am having doubts on :
while (curr >= 0 && p1 >= 0 && p2 >= 0) {
// more TC if ...
1
vote
1
answer
169
views
How to prove time complexity of an algorithm?
I'm trying to prove time complexity of merge sort algorithm in Isabelle HOL:
theory Merge_Sort_Time
imports Complex_Main "HOL-ex.BigO"
begin
fun merge :: "'a::linorder list ⇒ 'a list ...
0
votes
0
answers
72
views
Tail recursive MergeSort for Tuples in Scala
so im trying to make a mergesort for list with tuples, but no matter what i look at i dont see anything wrong with the implementation im doing. But still @tailrec is not being detected by Scala for ...
0
votes
0
answers
121
views
Using Merge Sort to Sort a Linked List with Inline RISCV ASM
I'm writing a Merge Sort to sort a linked list with inline RISCV asm, everything work fine until I start writing the part of lists merging.
Here is my function:
typedef struct Node {
int data;
...
1
vote
1
answer
103
views
Haskell 3-Way Merge Sort Stack Overflow Exception
I am new to Haskell and functional programming. I am trying to write the 3-way merge sort algorithm in Haskell. Problem is, when I run the code in GHCi it just returns *** Exception: stack overflow. I ...
-1
votes
1
answer
47
views
Why in this mergesort do I get problems with memory?
I've tried to write function for mergesort, but when I try to debug it I get whether 'stack overflow' or 'violation of access rights when writing to the address'. What might be the problem???
void ...
-4
votes
1
answer
98
views
Trying to make a sorted array of the indexes of another array in an extremely limited version of "python"
I'm trying to make a sorting function that will make an array of the indexes of the "input array."
Eg. Array(19,21,15,50,14) would return Array(4,2,0,1,3)
That may sound easy, but the ...
3
votes
2
answers
163
views
Efficiently counting the number of 2D points with higher coordinates in both X and Y axes
I am a university student stuck on an assignment for my Advanced Algorithms class.
The task in simple terms:
I'm given an array of 2D points. For each point, I need to display the number of other ...
-6
votes
1
answer
185
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!=...
1
vote
1
answer
141
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 ...
1
vote
2
answers
75
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];
...
-1
votes
1
answer
110
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;
...
0
votes
1
answer
81
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 ...
0
votes
1
answer
206
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 ...
2
votes
2
answers
73
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 ...