Sorting is the process of applying some order to a collection of items.

learn more… | top users | synonyms (1)

2
votes
2answers
22 views

Implementation of insertion sort in JavaScript

I have written an insertion sort algorithm in JavaScript: ...
3
votes
2answers
94 views

Quick Sort in Java

I recently started learning about algorithms and data structure's. I decided that for every algorithm I learn about I'll implement it without looking at any pseudo code or actual code. I have ...
-3
votes
0answers
17 views

Merge sorting 10000 random elements [on hold]

0 down vote favorite I am having an issue with my merge sort, when I print out my sortedArray it only returns [ 0.0, 0.0.....] Im not sure if there is an error in my sort code or in my print line or ...
1
vote
3answers
347 views

Bubble sort examination

I solved bubble sort in an exam, but the examiner wasn't satisfied with the solution. Please tell me why my solution is unsatisfactory. ...
8
votes
3answers
873 views

Word-counting script in C#

My goal is to read from standard input, break up the input into words (Unicode letters and apostrophes), case-insensitively, and produce a report to standard output, where each line is a word followed ...
6
votes
3answers
498 views

Sort a binary file without loading it into memory or using a temporary file

I had a silly assignment: You are given a binary file FLOATS.DAT of unknown length, type float data has been written in it. Write a program which sorts the ...
2
votes
0answers
36 views

Shell Sort code

I have a working shell sort code. I had already written a code for insertion sort, which I have used as underlying algorithm for doing shell sort on sub lists. So if you pass value of ...
2
votes
2answers
82 views

Implementing a Sort for an Array

Yesterday, I gave an interview after a long time, and I was asked a question which I couldn't solve on the spot. I had to implement a sort function for a Array of strings in JavaScript, with the ...
3
votes
1answer
502 views

Sorting seems to be slower with 2 threads instead of 1

I'm implementing a simple merge sort to practice with Python's Threads. I've tried to split the job into two threads, that sort normally, then I can join them and merge the result. However, it takes ...
2
votes
1answer
62 views

Algorithm for two languages that merges and sorts two arrays without mutating one

This algorithm, which I have included its flowchart as well, takes an array of A[n], which is unsorted and unmutatable and an array of ...
3
votes
2answers
69 views

Distinct unordered pairs of an array which satisfy a condition

I came across the below problem in a coding challenge: Let's define 2 functions, \$F(i)\$ and \$Val(i,j)\$, for an array \$A\$ of size \$N\$ as follows: $$ \begin{align} F(i) =& \sum_{j=i+1}^{N} ...
3
votes
2answers
63 views

Finding median of 3 elements in array, and sorting them

The method medianOfThree returns the median of the first, center and last element in array sorts the first, center, and last element of the array, so they are in ...
2
votes
0answers
30 views

SPOJ GENERAL: sorting by swaps of distance k

I have been trying to solve this simple problem on SPOJ for quite some time now, but I keep on getting TLE (Time limit exceeded) for some reason. Since the problem is in Portuguese, a brief ...
2
votes
1answer
25 views

sort group item by attribute

I have a repository method which retrieve a list of items, for example: ...
1
vote
1answer
62 views

Sorting and update 2D Dimension

Question: Compare and update the inventory stored in a 2D array against a second 2D array of a fresh delivery. Update the current existing inventory item quantities (in arr1). If an item cannot be ...
-1
votes
1answer
52 views

Searching into a contact list

I am performing search in a contact list using linear search with complexity \$O(n)\$. Please suggest me how to improve search strategy in my code. ...
2
votes
3answers
58 views

Sorting a list by the modulus of 3

The input is an unsorted array of integers. The output should be an array of integers sorted based on the modulus of 3 (or any other number). It begins with all integers conforming to Integer % 3 == ...
3
votes
3answers
88 views

Checking if numbers in array are sorted or reverse sorted

I would like to determine is an array of numbers, is always increasing (for all x, x+1 >= x) or always decreasing (for all x, x+1 =< x). If so return true. Another way to state the problem is, ...
1
vote
1answer
29 views

A simple Insertion Sort implementation in Java

I've written a InsertionSort algorithm in Java and I want a review on these: Performance improvements. Code conventions. Algorithm design improvements. Cleaner approaches. I would highly ...
3
votes
3answers
54 views

A simple bubble sort implementation in Java

I've written a Bubble Sort algorithm in Java and I want a review on these: Performance improvements. Code conventions. Algorithm design improvements. Cleaner approaches. I would highly appreciate ...
1
vote
0answers
25 views

Sorting Timestamped Messages (iOS)

An app I'm building professionally includes rudimentary text messaging. It allows users to send from the phone, and it polls for new messages (I know, yikes. Push notifications are a future task) with ...
3
votes
3answers
154 views

Sorting and eliminating duplicates

From Hacker Earth: Problem Statement: Chotu's father is the owner of a Vada Pav shop. One Sunday, his father takes him to the shop. Father tells him that at the end of the day, Chotu has to ...
4
votes
2answers
65 views

Processing trip route table in C

In fact, this is a group assignment for our C programming lesson, but seeking help from others is not considered cheating. The goal of the following code is to: Sort the data in ...
2
votes
1answer
51 views

Sorting the array of strings on their lengths in Java , Using Maps, ascending order…

I wrote the java method to answer this question : Write a Program to sort String on their length in Java? Your method should accept an array of String and return a sorted array based upon the length ...
2
votes
2answers
69 views

Merge sort Python implementation

Is this efficient? ...
1
vote
2answers
29 views

Sorting structures lexicographically

I am swapping structure lexicographically by name. Is there any way to improve the code when the structure entries are heavy. Here is the code ...
3
votes
1answer
57 views

Merging multiple sorted arrays into one sorted array

I would like to merge multiple arrays that are already sorted, into one sorted array. My arrays look like this : ...
2
votes
2answers
86 views

Function to compare objects based on type enums

I'm looking for a better way to implement a huge CompareTo function that relies on an Enum to perform sorting. The data structure is essentially a flattened Multi Level Group. Any ideas and concept to ...
1
vote
0answers
46 views

Graph (adjacency list) and DFS (topological sort)

The vertices on the graph are numbers from 0 to |V| - 1 for convenience. I was thinking later to use a template wrapper for the graph. Graph.h: ...
4
votes
1answer
46 views

Bottom up (iterative) mergesort in C

I have this C implementation of the bottom-up (iterative) mergesort: mergesort.h: ...
5
votes
3answers
137 views

Bubble Sort in Objective-C

Following is Objective-C method implementation I did for one of the most simplest sorting algorithms, Bubble Sort to sort an array of integers. Note:- I have defined it as a static method in the ...
2
votes
1answer
26 views

Sort Facebook Messenger contacts by idle time

I wrote a UserScript that auto-sorts contacts by offline time using the MutationObserver API. I tried to make it as DRY as I could think, and I also tried to make my code as straight-forward as ...
3
votes
1answer
61 views

Printing longest lines

Challenge Write a program which reads a file and outputs a specified number of lines, sorted on length in descending order. Specifications The first argument is a path to a file. The file ...
5
votes
3answers
114 views

Bubble sort class in Java

I have written this class which sorts the array using bubble sort. Please let me know how can I improve it. (I don't like recurrent code in if/else statement) ...
-4
votes
1answer
61 views

Recursive solution for merging two sorted lists [closed]

I came up with a recursive solution for merging two sorted list in Python in interviewbit: Merge two sorted linked lists and return it as a new list. The new list should be made by splicing ...
1
vote
1answer
37 views

Sort by year and day descending, yet time ascending

I recently discovered a hugely inefficient portion of code in my program, and have gone about rewriting it. I am however, not quite sure if the rewritten program actually does exactly what I want, due ...
1
vote
1answer
103 views

Sorting a list by country name

A couple of weeks ago a company sent me this coding challenge: Please write a PHP web application and send it back to me as zip file: Which waits for a user action, like clicking buttons. ...
6
votes
1answer
143 views

Sorting a list and another list inside each item

I have a list of factories. Each factory has an item of its own and a list of other items from competitors. I need to sort the list of factories based on price of their items and also sort list of ...
2
votes
1answer
330 views
3
votes
2answers
71 views

Duplicates in array elements and sorting

I've been given this little test exercise for an interview as php developer, and I'd like to hear from you if my solution is good (enough) or if the problem could have been solved in a better way. ...
5
votes
3answers
90 views

Merging 3 sorted linked lists

I already know how to merge two linked list, but I needed to code a function that'll merge three already sorted linked lists into one. I wrote a code and it is working fine, it takes care of null ...
3
votes
2answers
60 views

Merge and sorting arrays of String and int in more efficient methods

Are there better methods for merge and sorting arrays of int and String in more efficient methods both time-complexity wise and ...
1
vote
0answers
53 views

Parallel integer tree sort algorithm in Java

Introduction In this post, I will present a parallel sorting algorithm for sorting primitive integer arrays. Treesort Treesort is an algorithm which iterates over the input array and constructs a ...
0
votes
1answer
88 views

Radix sort in Java

As homework I had to implement many sorting algorithms including radix sort in Java. The task is to sort doubles in the range [0-1) that are rounded to the 10th ...
3
votes
1answer
53 views

Sort stack using two stacks

My program is supposed to sort a stack such that the smallest item are on the top. I can use a temporary stack, but you may not copy the elements into any other data structure. The program works ...
4
votes
1answer
85 views

Checking to see if array can be sorted using only one operation

I'm doing this HackerRank problem, which asks whether an array of up to 100000 integers can be sorted in ascending order by exactly one of the following: swapping two elements reversing a subarray ...
3
votes
3answers
92 views

Sort array of hashes with nil values last

I wrote a method which sorts an array of hashes by given hash keys. The method should put nil values at the end. ...
5
votes
1answer
66 views

Sort a strings collection by a search term

I'm trying to implement a search bar in which the user sends a search term and the search bar displays the results. I have a naive solution which separates the original list into three sublists: a ...
1
vote
1answer
47 views

Haskell Non-Dominated sorting

This algorithm sorts a list of Individuals, each with two fitness values, into what's called non-dominated fronts. A non-dominated front is a set of individuals where none of the individuals dominate ...
2
votes
1answer
52 views

Optimizations for bubble sort

The code performs bubble sort on the basis if any swaps has been performed in the iteration. I made it sort of independent of number of iterations as in any conventional bubble sorting code. I went ...