How to sort odd number list using only merge sort algorithm? and also even number separately? - mergesort

How to sort odd number list using only merge sort algorithm? and also even number separately?

Related

How to make indexes in MongoDB when there are a huge number of filters?

There are over 30 different filters
It can be an exact value, a selection from values, or ranges of values.
Various combinations are possible, i.e. there are more than several hundred possible combinations of filters
How, then, should the indexes be composed correctly?
Does it make sense to make an index on each field?
Count works insanely slow in this case.

Does Quicksort preserve the original order if the array is already sorted?

I have an array that is sorted in most of the cases, but not always. So I still need to use an sorting algorithm to guarantee that the elements are in ascending order.
I know that QuickSort is not stable, so the relative order of elements with the same value may change. But I need to know if it preserves the original order of the elements in an array that is ALREADY sorted.
I'm using C++, so I can simply use std::stable_sort (MergeSort) instead of std::sort (QuickSort). But this is more a matter of curiosity than efficiency, as I couldn't find an answer to my question.

Guidance on Merge Sort Algorithm

Currently working on a class assignment to create a merge sort algorithm using MIPS assembly language. Ill paste the instructions to said assignment to make sure my interpretation of what I'm supposed to do is correct.
The Instructions:
Convert "merge" in Assignment 3 (Assignment 3 is a merge algorithm that takes two ordered lists merges all elements of that list into one long ordered list, I've already completed this) into a subroutine. Write a "main" program to perform merge-sorting of a list of integers by calling "merge" repeatedly ( ** Im assuming this means calling my previous Assignment 3**). For example, if the sorting program takes (6,5,9,1,7,0,-3,2) as input, it will produce a sorted list (-3,0,1,2,4,6,7,9).
The original unsorted list of integers should be received from the keyboard input. Your program should first ask for the user to input the number of integers in the original list, and then ask for inputting all the integers. The total number of integers to be sorted by this program should be a power of 2. This means, the program should work with a list of 2, 4, 8, 16, or 32 (...) integers (but your program needs only to handle up to 32 integers).
Now, my merge algorithm takes two ordered lists but this assignment takes only 1 list. However, the link bellow explains merge sort in a way where the original unsorted list is progressively divided up into individual elements and then it works backwards and puts the elements in order. (Since my assignment 3 (the merge algorithm that i already have) takes two ordered lists would it be possible for me to simply do one iteration of my merge algorithm right after dividing the unsorted list into two unsorted lists??)
Basically, calling my merge algorithm at the second step in the bellow link.
https://www.tutorialspoint.com/data_structures_algorithms/merge_sort_algorithm.htm
Thank you so much!

Hash a Sequence of positive/negative integers

I have a file with millions of lines (actually it's an online stream of data, which means we are receiving it line by line) , each line consists of an array of integers which is not sorted (positive and negative) there's no limit for the each number and the lengths are different and we might have duplicate values in one line,
I want to remove the duplicate lines (if 2 lines have same values regardless of how they are ordered we consider them duplicate), is there any good hashing function ?
We want to do this in O(n) while n is number of lines (we can assume that the maximum possibele number of elements in each line is constant, e.g. we have maximum of 100 elements in each line)
I've read some of the questions posted here in stackoverflow and I also googled it, most of them were for the cases where the arrays are of the same length or the integers are positive or even or they are sorted, is there any way to solve this in general case ?
My solution:
First we sort each line with the use of O(n) sorting algorithm e.g. Counting sort , then we put them into a string and then we use md5 hashing to put them into a hashset. If it's not in the set we put it into that set, if it's already in the list we check the arrays with the same hash value.
Problem with the solution : sorting using the Counting Sort takes a lot of space as there's no limit for the numbers and the collisions are possible .
The problem with using a hashing algorithm on a set of data this large is that you have a high probability of two different lines hashing to the same value. You want to stay in O(n) but I am not sure that is possible, with the size of the data and accuracy needed. If you use heapsort, which is space efficient and then traverse down the new sorted data removing consecutive lines that are the same you could accomplish this in O(nlogn)

Is there any formula to calculate the no of passes that a Quick Sort algorithm will take?

While working with Quick Sort algorithm I wondered whether any formula or some kind of stuff might be available for finding the no of passes that a particular set of values may take to completely sorted in ascending order.
Is there any formula to calculate the no of passes that a Quick Sort algorithm will take?
Any given set of values will have a different number of operations, based on pivot value selection method, and the actual values being sorted.
So...no, unless the approximations of 'between O(N log(N)) and O(N^2)' is good enough.
That one has to qualify the average versus worst case should be enough to show that the only way to determine the number of operations is to actually run the quicksort.