Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

Questions tagged [sorting]

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

Filter by
Sorted by
Tagged with
0
votes
0answers
4 views

Timsort implementation in Python

I wanted to implement a Timsort in python. Here's what I've come up with: ...
1
vote
1answer
44 views

Finding sequential recurrences in a list of numbers

I have a list like this: seq = [-2,3,-2,3,5,3,7,1,4,-5,1,4,-5,1,4,-5] I want to get all the sequential recurrences and where it happens, I feel the way I'm doing ...
6
votes
2answers
72 views

Bubble Sort Implementation in Python 3

I have implemented a Bubble Sort. It works well. But if you think something needs to be improved, say it. This code was tested in Python 3.7.4. ...
0
votes
1answer
52 views

Complexity of bubble sort

I have a simple integer sorting problem at hand and to solve it, I am planning to write a variation of bubble sort. It seems to be working fine but I am not sure about it's complexity in big-O. What ...
6
votes
2answers
2k views

Minimum swaps algorithm terminated due to timeout

I have been trying to solve this question. Given an unordered array consisting of consecutive integers [1, 2, 3, …, n], find the minimum number of two-element swaps to sort the array. I was able ...
2
votes
2answers
7k views

Minimum number of swaps required to sort the array in ascending order

Here is my problem statement. An excerpt: You are given an unordered array consisting of consecutive integers ∈ [1, 2, 3, ..., n] without any duplicates. You are ...
3
votes
2answers
918 views

Implement bubble sort in Python

I have written the following code for bubble sort. How can it be optimised? ...
3
votes
2answers
101 views

Simple BubbleSort in GoLang

I'm just starting in Go. Please review the below code, and let me know what I can improve in this code. ...
3
votes
2answers
870 views

New Year Chaos JavaScript, needs to be sped up

Similar to this question but this is for Python Original problem with description on hacker rank I am currently trying to iterate through a large number of arrays and count how many times numbers ...
4
votes
1answer
46 views

Merge Sort from Scratch in Python

I built a merge sort in python just to have a more thorough understanding of how the algorithm works. What I have written works fine, but I assume there is room for improvement and ways to make my ...
7
votes
3answers
519 views

Checking an array is sorted in either order efficiently

Here is my code, it works fine, just wondering if there any anything to make it even better. ...
2
votes
1answer
53 views

In-Place Merging of Two Bubble Sorted Linked Lists (Python)

I'm following a tutorial on merging two bubble-sorted Single Linked Lists in Python. merge1 does the merging by creating a new list with maybe \$O(N+M)\$ memory ...
1
vote
1answer
84 views

Single Linked List (Python)

I'm following a tutorial on Single Linked List (SLL). There are so many methods in the code, if you had time please feel free to review any part of it and I can work on it and repost it. I'm ...
1
vote
0answers
66 views

Python Bubble sort

...
0
votes
0answers
45 views

Bubble sort optimization

This bubble sort code is very slow compared to the original. ...
5
votes
1answer
81 views

Timeout Error in Fraudulent Activity Notification HackerRank

I am solving this problem: Fraudulent Activity Notifications on HackerRank. I am done with my code and is working, but it is inefficient as well for very large inputs. I don't know but after all ...
7
votes
2answers
93 views

Quick Sort Implementation with iterators

Most quicksort examples online use C-style arrays and indexes. I have written below quicksort implementation with STL style iterators. It looks fine to me, but I feel like I may be making more than ...
4
votes
2answers
101 views

Heap Sort and Binary Tree Sort Algorithms (Python)

Heap Sort A Binary Heap is a Complete Binary Tree where the items are stored in a special order such that the value in a parent node is greater or smaller than the two values in the children nodes. ...
3
votes
1answer
40 views

Quick Sort implementation in python

Implemented the quick sort algorithm in python, It was just for learning it, now I want to port it to C. Thoughts on the quality of my python implementation? ...
3
votes
2answers
123 views

Binary Tree Sort Algorithm (Python)

A Binary Tree Sort is an algorithm that builds a binary search tree from the elements to be sorted, and then traverses the tree (in-order) so that the elements come out in sorted order. Average Case ...
5
votes
2answers
328 views

Selection Sort Algorithm (Node.js)

I wanted to implement a selection sort and wanted to make sure that I'm doing it correctly. I wanted to do it in a way that's efficient and use recursion. Please let me know if I am doing this ...
0
votes
1answer
131 views

Shell Sort, Insertion Sort, Bubble Sort, Selection Sort Algorithms

There are seven sorting algorithms in the code copied below. The first five algorithms have been previously reviewed in this link. Selection Sort The Selection Sort algorithm sorts a list by ...
3
votes
1answer
52 views

Quick Sort Algorithm (Python)

QuickSort is a Divide and Conquer algorithm, which picks an element as "pivot" and partitions a given list around the pivot. There are many different versions of Quick Sort, as to how to pick a pivot ...
3
votes
1answer
49 views

Recursive Merge Sort Algorithm (Python)

Merge Sort Merge Sort algorithm is a general-purpose comparison-based sorting algorithm. Most implementations produce a stable sort, in which the order of equal elements is preserved. Just for ...
3
votes
1answer
61 views

Iterative Merge Sort Algorithm (Python)

Merge Sort Merge Sort algorithm is a general-purpose comparison-based sorting algorithm. Most implementations produce a stable sort, in which the order of equal elements is preserved. Here, our ...
3
votes
0answers
49 views

DataManager Class: Sorts Array by 1 or More Dynamically Added Columns in Ascending or Descending Order

I've been struggling to write a QuickSort algorithm to sort multiple columns of an Array for weeks. Finally, I decided to write a class that Implements mscorlib.IComparer and it has exceeded my ...
12
votes
4answers
2k views

Shell Sort, Insertion Sort, Bubble Sort, Selection Sort Algorithms (Python)

There is a follow-up question available: shell-sort-insertion-sort-bubble-sort-selection-sort-algorithms-python. Selection Sort The selection sort algorithm sorts a list (array) by finding the ...
2
votes
1answer
61 views

LeetCode: Queue Reconstruction by Height C#

https://leetcode.com/problems/queue-reconstruction-by-height/ Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers \$(h, k)\$, where \$h\$ ...
8
votes
2answers
818 views

Selection Sort Algorithm (Python)

Selection Sort The selection sort algorithm sorts a list by finding the minimum element from the right unsorted part of the list and putting it at the left sorted part of the list. The ...
2
votes
1answer
68 views

Sorting Algorithms (Python)

Selection Sort The selection sort algorithm sorts a list (array) by finding the minimum element from the right (unsorted part) of the list and putting it at the left (sorted part) of the list. The ...
15
votes
4answers
31k views

Sort three numbers using only if-statements

Beginner here, trying to make a small program that sorts three numbers from smallest to largest only by using ifs. Any thoughts on how to improve this? ...
5
votes
1answer
61 views

An alternative algorithm for sorting a stack using only one additional stack

From "Cracking the Coding Interview": Write a program to sort a stack in ascending order (with biggest items on top). You may use at most one additional stack to hold items, but you may not copy ...
6
votes
3answers
1k views

LeetCode: Top K Frequent Elements C#

https://leetcode.com/explore/interview/card/top-interview-questions-medium/110/sorting-and-searching/799 Given a non-empty array of integers, return the k most frequent elements. Example 1: ...
6
votes
3answers
3k views

python (optimizing) bubble sort

I saw in Wikipedia (the first under Optimizing bubble sort) a pseudo-code to bubble sort and I implemented it in Python. I am posting my implementation here because I'm new to Python, and I'm looking ...
6
votes
3answers
95 views

Quicksort for ints

I have written the following quicksort without using online help. It seems to be fine, but is there anything to improve? ...
4
votes
1answer
239 views

Bubble sort algorithms and unittest in Python

I am quite new in Python and I am starting my journey with sorting algorithms, PEP8 and the Zen of Python. So far i wrote a post BubbleSort and I drew conclusions and followed the advices. I ...
1
vote
1answer
275 views

Bubble sort in Python

I am quite new in Python and I am starting my journey with sorting algorithms, PEP8 and the Zen of Python. I would like to get some feedback about my BubbleSort algorithm which I wrote. Also, is there ...
3
votes
1answer
78 views

Python: Quick Sort

How to improve this code? In C++ we use templates to write function for all data types. How to write such code in python? ...
6
votes
2answers
118 views

Quicksort with Insertion Sort and Improved Pivot Selection

Here's a Quicksort I had fun writing and improving, so I thought I'd post it here. In my (brief) testing it's about 15% to 20% faster than Java's Arrays.sort(). ...
1
vote
1answer
95 views

Sorting a list of IComparables

I have a DateTime class (my own, not System.DateTime) which implements the IComparable ...
3
votes
1answer
66 views

LINQ for extracting N bottom items (async streams)

source.Bottom(n, x => x) should be the same as well known LINQ source.OrderBy(x => x).Take(n) but is more memory/run-time ...
5
votes
1answer
75 views

Sorting software version list using Python 2.7 (no modules)

I am participating in a challenge and one of the challenges was to write a script to sort a list of software versions (ex: 1.0, 1.3.2, 12, 1.3.0). Here is the my solution: ...
5
votes
2answers
130 views

Quick Sort in C

I'd like to know if there's any issues with this implementation of qsort_r (which is not available in all implementations, so I'm trying to provide one that allows ...
4
votes
1answer
53 views

Sorting email address according to occurrences of each domain

My code: ...
2
votes
1answer
144 views

Sorting function from a React app to display JSON data in a sortable table

I created this simple react application for a coding challenge, which is described in the linked README file. Basically, I created the components and helper logic to display dynamic JSON data in a ...
1
vote
1answer
56 views
5
votes
2answers
268 views

Hackerrank “Almost Equal” solution

I've spent the best part of a day on this question. It is marked as Expert level. There are about fifteen submission test cases and my solution manages to satisfy the first four. However, from there ...
2
votes
1answer
35 views

Naive implementation of sort inplace

I had the following assignment for the Python 101 course I'm taking in my university. ...
4
votes
4answers
94 views

MergeSort in Javascript

I implemented the following mergesort algorithm in JavaScript, but I want to know your opinion about if is possible to do better than this. ...
2
votes
1answer
61 views

Bubble Sort: Time and Space Complexities

Algorithm Bubble sort, also known as sinking sort, is a sorting algorithm that repeatedly steps through a list, compares adjacent pairs and swaps them if they are not in the right order. The pass ...