I came across the following question.
Given an array of n elements and an integer k where k < n. Elements {a0...ak} and
{ak+1...an} are already sorted. Give an algorithm to sort in O(n) time and O(1) space.
It does not seem to me like it can be done in O(n) time and O(1) space. The problem really seems to be asking how to do the merge ...
I have written a java program that tests the speed of a couple of multi-threading algorithms on different machines with various numbers of processors.
On some machines, merge sort* fails because it requires a sizable heap space to work on very large arrays. I can easily change the java heap space myself before running the program, but ...
So I was writing a mergesort in C# as an exercise and although it worked, looking back at the code, there was room for improvement.
Basically, the second part of the algorithm requires a routine to merge two sorted lists.
Here is my way too long implementation that could use some refactoring:
private static List<int> MergeSortedList...
Hi,
Can someone please give me a link or provide me with java code of a multithreaded merge sort?
Preferable one that uses an executor!
Thank you very much!
...
Good afternoon ladies and gents. So, it is not my day for errors. Implementing Mergesort (not in-place) in C++, and I'm having real trouble with the code, with no idea why. The second-to-last line of the mergeSort() function assigns the result of the merge() to a vector of ints, result. This line (the actual allocation, not the function)...
Hi,
I am refactoring an external merge sort in C#. The current implementation uses a fixed chunk size of 50mb. I'd like to query the performance counters and dynamically calculate a good chunk size. I'm just not sure which counters to use? Do I get the total available memory and use a percentage of that or can I find how much is availab...
Hi I am trying to implement the merge sort algorithm in a very dirty manner since it was told by our teacher to do so.
This program takes the input integer array from the user and prints the value of the array each time the sort is call (just for testing. Ill correct it later). It is entirely dependent on stack . I was told to first imp...
void merge(vector<int> dst,vector<int> first,vector<int> second)
{
int i=0,j=0;
while(i<first.size()&&j<second.size())
{
if(first[i]<second[j])
{
dst.push_back(first[i]);
i++;
}
else
{
dst.push_back(second[j]);
j++;
}
}
wh...
Intel Core2Duo, for example is supposed to have a single die but two cores.
So, it should be possible to control what is processed on which core, which means that it is possible to instruct my algorithm to use the two cores in parallel.
The question is how?
Do I need to go down at the kernel level to do this, or is there a simpler wa...
Imagine we have a query:
SELECT * FROM somewhere WHERE `id` IN(1,5,18,25) ORDER BY `name`;
and an array of IDs to fetch: $ids = array(1,5,18,25)
With prepared statements it's adviced to prepare one statement and call it multiple times:
$stmt = $mysqli->prepare('SELECT * FROM somewhere WHERE `id`=?;');
foreach ($ids as $id){
$stm...
I've two files of 1 GB each containing only numbers in sorted order. Now I know how to read the contents of the files and sort them using merge sort algorithm and output it into an another file but what I'm interested is to how to do this only using 100MB buffer size (I do not worry about the scratch space). For example one way is to rea...
Hi to all,
due to Internet communication i could have two (or more) ASCII files in RINEX format (GPS ASCII format) of the same data period, which i would like to merge to one file.
Each data set (epoch) contain more then one line (in this example 19 lines). I would like to merge those files, where it could be that they in some parts ov...
I am having problems with bottoms-up mergesort. I have problems sorting/merging. Current code includes:
public void mergeSort(long[] a, int len) {
long[] temp = new long[a.length];
int length = 1;
while (length < len) {
mergepass(a, temp, length, len);
length *= 2;
}
}
...
Hi all:
i am reviewing my data structures and algorithm analysis lesson,and i get a question that how to determine to the space complexity of merge sort and quick sort
algorithms ?
The depth of recursion is only O(lgn) for linked list merge-sort
The amount of extra storage space needed for contiguous quick sort is O(n).
My th...
Can anyone point me to a good reference on External Memory Mergesort? I've read the wiki page but am having trouble understanding it exactly. An animation might help but I can't seem to find one.
Basically, I know that you have a certain number of blocks on disk, and you can fit a certain number of blocks in memory. Lets say you have...
I wrote the entire thing, but i get vague errors. I don't know what's wrong....ugh.Also, you may ask why non-recursive well my teacher has it that way for the test.
void nonrec_mergesort(vector <int> & a, vector <int> & b, int s, int r)
{
int m = 1;
while (m <= r)
{
int i = 0;
while(s < (r-m))
{
...
I am trying to do merge sort using void*. If I keep numbers I want to sort to 1-byte it works perfectly. However if the number is located in more than 1 byte it doesn't work well. I believe it takes it as 2 numbers. I tested it with number 500 and at the end I have 256 and 244 not sorted ....
#include "msort.h"
#include <iostream>
usi...
Anyone have a recursive code example for the Merge Hull algorithm? Im struggling to understand how to implement it.
...
Snape’s “Unfriendly Algorithms for Wizards” textbook claims the running time of merge
sort is O(n^4). Is this claim correct?
Solution: Yes. This claim is technically correct, because O(n^4) only gives an upper
bound for how long the algorithm takes. However, it’s an obnoxiously unhelpful answer,
since the tight bound is Θ(n log n).
I'm...