Questions tagged [algorithm-analysis]
Analyzing an algorithm to determine its time and space performance.
112 questions
9
votes
9
answers
3k
views
How to choose between brute force and efficient solution that has overhead?
Using Big O notation, it is clear that I should go with the more efficient approach, but I know that there is a significant cost in terms of initialization for more efficient solutions.
The Problem:
...
2
votes
7
answers
4k
views
Why is big O notation an asymptotic notation/analysis?
An asymptote in mathematics represents a value (line) to which the observed function constantly approaches. In other words, as the value of X increases towards infinity, i.e. decreases towards minus ...
1
vote
1
answer
130
views
Some questions about shortest-path algorithms
I'm trying to understand why anyone would prefer Floyd-Warshal over Dijkstra:
Dijkstra gives a correct result, using an understandable system, combined with backtracking.
Floyd-Warshal makes an ...
0
votes
2
answers
395
views
fastest way to find number of smaller elements to the right of an array
In Daily Coding Problem, Miller&Wu have the following problem :
Given an array of integers, return a new array where each element in the new array is number of smaller elements to the right of ...
0
votes
1
answer
1k
views
Counting primitive operations on recursive functions
I'm reading Algorithm Design and Applications, by Michael T. Goodrich and Roberto Tamassia, published by Wiley. They teach the concept of primitive operations and how to count then in a given ...
5
votes
4
answers
684
views
Processing a 2D matrix - need to speed up my O(n^4) algorithm
I have an n x n matrix which I need to convert into a list sorted by value. Starting with the maximum value cell at (row x1, col y1), I must immediately exclude all cells where (x >= x1, y <= y1)...
3
votes
1
answer
436
views
Why the names Omega and Theta in Big Omega and Big Theta?
There was a question asking what the "O" stands for in "Big O", the answer to which seems to be "Ordnung von"/"order of".
I wonder what's the origin of the ...
21
votes
6
answers
5k
views
Using a different algorithm depending on the size of the input
I recently finished a course on advanced algorithms, and another on complexity & computability theory, and in the past few days my mind has been somewhat preoccupied by this question.
Why don't we ...
1
vote
0
answers
223
views
Rectangle packing / Bin packing with multiple frames
I have multiple rectangular frames, with different fixed heights. The width should be minimized and there is a maximum width. Then there are many different smaller rectangles. These should be packed ...
3
votes
3
answers
3k
views
Are there any programs or IDEs that calculate Big-O notation on functions? Is this something that is possible to program into an IDE?
Is there anything that can calculate the Big-O notation of a function?
While learning about Big-O, it is implied that it is pretty trivial to do in your head once you know the basic rules, however if ...
0
votes
1
answer
153
views
Do I have do use HashTables/Maps/Hashmaps in this algorithm?
I am doing the Ransom Note algorithm in Hackerrank. The thing is I am not using maps and all the tests pass except for three which execution time takes a lot more. (Kotlin language)
I have two ...
-1
votes
1
answer
161
views
static, dynamic analysis - what mistakes were made in the code?
A software company develops software packages for commercial animal
farming. A special function in C calculates the daily amount of feed
for different kind of animals dependent on their bodyweight....
-3
votes
1
answer
224
views
Questions around calculation of time complexity of an algorithm [duplicate]
I am a newbie to algorithms. One thing that i always get confused is about calculation of algorithm runtimes.
For example: The following piece of code in Python
for i in range(n):
#O(?)
i*=k
...
0
votes
1
answer
904
views
Battery level prediction model
I have the idea of develop a model that predicts the battery charge level of my system for now until the following 5 days. The battery is charged using a solar panel. I am writing my code in Python 2....
2
votes
1
answer
416
views
Algorithm: Binary Search / Tree / Partitioning on unsortable data?
First, this question is not really about binary search as I neither have sorted data, nor any sortable data at all. :-)
W.r.t the "unsortable" claim see below; but I think the title term "unsortable"...
1
vote
1
answer
2k
views
Reverse engineering a checksum or CRC
I am trying to reverse engineer a checksum or CRC wherein an 8 bit number* gets converted to a 5 bit number for error checking. I have an incomplete list of data values and checksums, and need to ...
1
vote
1
answer
8k
views
Why is the optimal choice for a pivot in quicksort algorithm the median element?
Lately i have been taking an course at brilliant.org, i was exploring a lesson on QuickSort algorithm, found a question.
Which of the following would provide the optimal pivot selection at each step ...
-1
votes
2
answers
335
views
Why in Tournament Sorting do we neglect the number of comparisons to find the Minimum?
Here the professor said that, Tournament sort needs (n-1) + 2(n-1)logn comparisons.
{Where (n-1) for calculating Maximum or say creating Tournament structure
and
2(n-1)logn for other elements to sort}...
1
vote
2
answers
6k
views
Loop invariant of Selection Sort
Selection Sort(A[1,2..n]:array of integers)
1.for i=1 to n-1
2.for j=i+1 to n
3.if A[j]<A[i]
4 swap(A[i],A[j])
I am trying to prove the correctness of this algorithm,I read from my book ...
5
votes
2
answers
1k
views
Algorithm to find Minimum bounding rectangle of fixed area [closed]
I have set of spatial points defined by coordinates (x,y) . I want to find the bounding rectangle of given area that maximizes the number of point inside the rectangle. The obtained rectangle should ...
2
votes
3
answers
2k
views
Is the Time complexity of this function o(n) ? Can it be optimized any further?
This is a very simple function to find if a string is composed of unique characters. I believe that this is a O(n) time complexity as it loops once and has a single if condition. Am I correct? Is ...
3
votes
1
answer
553
views
Algorithms comparison and complexity
I want to sole this problem:
Write a method to return all valid combinations of n-pairs of
parentheses.
The method should return an ArrayList of strings, in which each string
represents a ...
2
votes
4
answers
3k
views
How does the dividing Step in Merge Sort have Constant Time Complexity?
I am highly confuse while calculating time complexity of Merge Sort Algorithm.
Specifically on the Dividing Step.
In the dividing step we have to calculate the mid point of "n" i.e. "q = n/2".
How ...
-1
votes
3
answers
535
views
Time complexity of an algorithm [closed]
What is the complexity of the following loop?
for(i=1;i<n;i=2^i)
sum+=i;
2
votes
1
answer
329
views
Optimizing the exponential smoothing of a big array
I have a large set of values (let's say 1M entries) where I need to apply an exponential smoothing algorithm, but only incrementing one value at a time (all others decay to zero). The trivial ...