C Sort Algorithm Not Outputting Correct Values?

new to C here. I am making a program that will sort and search a list of random ints for learning purposes, and trying to implement Bubble sort, but am getting odd results in my console during debugging. I have an array like so: arr[0] = 3 arr[1] ...
more »

2017-03-25 16:03 (2) Answers

Sort part of array with heapsort, bug

Here is my code for a introsort. I have trouble getting the heapsort part of the code working. partition() and sort() works like it should, but the heapsort part doesnt sort correctly. I get sorted arrays (size=10) like this: 10 18 26 35 25 39 49 4...
more »

2017-03-25 14:03 (2) Answers

javaFX: Wrong Merge sort animation result

I am implementing a merge sort animation with some rectangles using javaFX. I use some function of animation to do it. However, The translate route is wrong. I check my code over and over again and do not find the problem. The problem might be in the...
more »

2017-03-24 22:03 (0) Answers

Assigning lexical order score to strings

In my current project we have a strange kind of sorting system. As opposed to the usual way of determining the order of elements by comparing them to one another, we first assign a numeric score to each element and then sort by this score. This way...
more »

2017-03-24 11:03 (3) Answers

Fastest way to search in sorted static array

I am looking for the fastest way to search in a sorted, fixed array of 32 bit keys. The array size and data is static and will never change. The size of this array is ~1000-10000 unique elements. The search range is significantly broader (~100000) so...
more »

2017-03-24 01:03 (1) Answers

Understanding of shell sort

I have a couple of questions I couldn't find online regarding Shell sort with Shell's gap. public static void shell(int[] a) { int increment = a.length / 2; while (increment > 0) { for (int i = increment; i < a.length; i++) { ...
more »

2017-03-23 23:03 (0) Answers

Sum Of Two Squares: Where's My Error?

I'm trying to calculate the number of ways to write a natural number as the sum of two squares. I'm working from the definition: So, here is my code. Below where I test it, I find what I think is an error in the result. sumOfSquares :: Integer -&...
more »

2017-03-23 19:03 (1) Answers

What is the fastest way to sort these n^2 numbers?

Given a number 'n', I want to return a sorted array of n^2 numbers containing all the values of k1*k2 where k1 and k2 can range from 1 to n. For example for n=2 it would return : {1,2,2,4}.(the number are basically 1*1,1*2,2*1,2*2). and for n=3 it ...
more »

2017-03-23 12:03 (2) Answers

Getting rank of element upon sorting the array

I am given an array, and I would like to find the position of these elements in the sorted version of the array. So, the input and output would look like as follows Input : {10, 5, 4, 9, 8, 3, 2, 1, 6, 7} Output: {0, 3, 4, 9, 8, 1, 2, 5, 6, 7} Th...
more »

2017-03-23 10:03 (3) Answers

Quickly access sorted subset

Let's say I have an n by d matrix X, with n samples and d features. Let's assume that I can presort X as much as I realistically want (for example, have a matrix of indices for X sorted by each individual feature). The algorithm I am using requires m...
more »

2017-03-23 08:03 (1) Answers

Sorting Squares: How to decimate a plane of quads?

Given a disorderly array of miniature quad polygons on a 2D plane, What are some of the best ways of grouping them into larger quads? Currently i am writing the quads into a boolean array so that i can fast access all neighbor values of a given quad...
more »

2017-03-20 12:03 (0) Answers

Qsort and Comparators weird behaviour. C

So, I am using qsort in my C program from C library. It works as expected so I decided to play around with comparators. Comparator 1 (I use this): int compare (const void * a, const void * b) { if (*(double*)a > *(double*)b) return 1; else ...
more »

2017-03-18 23:03 (1) Answers

Maximum concurrent meetings given participant list

The Problem Following our team check-in, we break off in to co-ordination meetings with (n) participants covering various (uniquely named) Topics. Currently, people stand around trying to self organize and we are not maximizing concurrency of meeti...
more »

2017-03-18 15:03 (1) Answers

Best possible subset of data.frame without NA

I have data.frame of dim: 160560 x 171. There is a lot of data, but almost 90 % of it are NA. The algorithm (lets call it ALG) which I willing to use do not tolerates any NA in data.frame. My idea is to find the best possible subset of this data.f...
more »

2017-03-17 14:03 (1) Answers

Performance of Prime Testing with Haskell

I have two ways of testing for primes. One of them called isPrime and the other is isBigPrime. What I originally wanted is to test "big" primes with "small" primes that I have already computed, so that the testing becomes faster. Here are my implemen...
more »

2017-03-16 20:03 (1) Answers

Merge two sorted arrays into one

Hi I was asked a following question. Given two arrays i.e. array1 and array2. Both of them contain numbers in sorted order. Array1 also contains -1 such as; as many numbers in array2 that many -1's in array1. Example as follows, array1 = [-1,-1,-...
more »

2017-03-15 18:03 (8) Answers

Algorithm for merging lists of words

I am working on a project in which I have to combine multiple data sets, i.e. merge semi-similar lists of words. These are words that fit certain meanings of a word. Here's some real data: home[a]: abode|domicile|dwelling|dwelling place|habitation|h...
more »

2017-03-14 21:03 (0) Answers

Radix sort in singly-linked list C#

I'm trying to do a Radix sort in a Linked list class. I found radix sort algorithm for array and am trying to change it to work with my linked list. However, I'm a bit struggling. The code I'm trying to change is taken from http://www.w3resource.com/...
more »

2017-03-14 10:03 (1) Answers

Algorithm translate a number to String

I need to design an algorithm where each number is encoded to an alphabet, for example: 1=A, 2=B, 3=C...26=Z Given a set of numbers, I have to translate them to a combination of strings. For example: 123 can be translated to - ABC(123), AW(...
more »

2017-03-13 17:03 (4) Answers

How does Top-K sort algorithm work in MongoDB

Based on the answer and from MongoDB Documentation, I understood that MongoDB is able to sort a large data set and provide sorted results when limit() is used. However, when the same data set is queried using sort() results into a memory exception. ...
more »

2017-03-13 16:03 (1) Answers