Questions tagged [comparison]
69 questions
22
votes
12 answers
Data structure or algorithm for quickly finding differences between strings
I have an array of 100,000 strings, all of length $k$. I want to compare each string to every other string to see if any two strings differ by 1 character. Right now, as I add each string to the array, I'm checking it against every string already…
JGut
- 331
- 1
- 2
- 6
19
votes
7 answers
Why do we use the number of compares to measure the time complexity when compare is quite cheap?
I think one reason a compare is regarded as quite costly is due to the historical research as remarked by Knuth, that it came from tennis match trying to find the second or third best tennis player correctly, assuming the tennis players are not a…
nonopolarity
- 413
- 3
- 11
7
votes
2 answers
More efficient algorithm for determining if one list is a sublist of another list
I'm trying to build an algorithm which takes two lists of natural numbers and finds if every element of the first list is displayed at least once in the second list.
What if the list is sorted?
An algorithm that can do this is by comparing every…
Student
- 275
- 1
- 5
5
votes
3 answers
How do I find the max and min value of an array in 3n/2−2 comparisons?
So I'm using this method to find the min and max value of an array simultaneously where I split the array into n/2 and n/2 parts. I then keep splitting each part until I have either a pair of numbers or a single number.
What I'm trying to do now is…
David
- 51
- 1
- 1
- 2
4
votes
1 answer
Median-of-medians in O(log n) memory
Is there a way to use median-of-medians to find a median in,
simultaneously, O(log n) memory and O(n) comparisons?
The user orlp on this site seems to claim that there is.
Getting O(log n) auxiliary memory seems to be…
user12859
4
votes
2 answers
Is there a metric for the similarity of two image filters?
Definitions
An image filter is a matrix $m \in \mathbb{R}^{k_1 \times k_2 \times k_3}$ which gets applied to an image $I \in \mathbb{R}^{l_1 \times l_2 \times l_3}$ as a discrete convolution
$$I'(n_1, n_2, n_3) = \sum_{i=0}^{k_1} \sum_{j=0}^{k_2}…
Martin Thoma
- 2,360
- 1
- 22
- 41
4
votes
0 answers
Comparison-based computation: percentage of current software development?
Vol. III of The Art of Computer Programming, chapter 5 (Sorting, intro) mentions:
Computer manufacturers of the 1960s estimated that more than 25
percent of the running time on their computers was spent on sorting,
when all their customers were…
ExpressionCoder
- 622
- 3
- 15
4
votes
3 answers
What is a sorting algorithm that is robust to a faulty comparison?
I want to sort a list of n items with a comparison sort. However, one of the comparisons made by the algorithm will be flipped from what it's supposed to be. Specifically, there is one pair of items for which the comparator function consistently…
chausies
- 562
- 3
- 10
4
votes
3 answers
Sorting array of strings (with repetitions) according to a given ordering
We get two arrays:
ordering = ["one", "two", "three"]
and
input = ["zero", "one", "two", "two", "three", "three", "three", "four"];
We want to find the array output so that
output = ["one", "two", "two", "three", "three", "three", "zero",…
Pe Wu
- 143
- 5
4
votes
1 answer
Are comparison sort algos appropriate for SUBJECTIVE sorting?
I've been tasked with creating an online feature that ranks 50 fantasy characters from a variety of domains based on combat acumen and polls users one which one is the most powerful based on their votes on a series of face-to-face matchups.…
Chris Wilson
- 143
- 4
3
votes
2 answers
sort n numbers in the range [0,1] without multiplying or dividing
Given an array with n real numbers, each in the range [0,1], I need to sort them. Moreover, the only operations that are allowed are comparisons or copying.
It means I cannot multiply or divide the numbers, which prohibits me from using bucket…
Gabi G
- 325
- 1
- 11
3
votes
0 answers
How to determine the fewest number of comparisons for Heapsort?
I'm currently doing an exercise that asks to prove that Standard-Heapsort requires at fewest $\frac{1}{8} n \log(n) - O(n)$ comparisons, in its best case.
In its average case, Heapsort only requires $2n\log(n) - O(n)$ comparisons, although I don't…
roughosing
- 31
- 3
3
votes
2 answers
Proving at least $n-1$ comparisons are needed to test if an array is sorted
so I need to prove the following:
Prove that $n-1$ comparisons are sometimes necessary to test whether an array with $n$ distinct elements is sorted in increasing order, for any $n \geq 1$.
The problem comes with the following hint:
Assume an…
P. Jhon
- 31
- 1
- 4
3
votes
0 answers
Text data comparison
Okay lets say i have two data structures . two phone data for example containing their Name and spec ( cpu , ram , display etc ) . I want to check if these two phones are the same or not . Their names can be different as their other features . For…
user43652
- 31
- 1
3
votes
1 answer
Cost of partitioning in quicksort
I'm reading "Algorithms Fourth Edition" by Sedgewick & Wayne and am wondering if I have spotted an error in the book or if I just can't wrap my head around something so simple.
When talking about the complexity of quicksort, the book says that the…
Levi Botelho
- 133
- 6