Using as few resources (e.g. time, space) as possible while solving a problem. Use this tag if your question is specifically about resource usage, not for generic algorithm questions that happen to mention running times.
Questions tagged [efficiency]
292 questions
193
votes
10 answers
How can a language whose compiler is written in C ever be faster than C?
Taking a look at Julia's webpage, you can see some benchmarks of several languages across several algorithms (timings shown below). How can a language with a compiler originally written in C, outperform C code?
Figure: benchmark times relative to…
StrugglingProgrammer
- 1,973
- 3
- 12
- 10
60
votes
5 answers
Factorial algorithm more efficient than naive multiplication
I know how to code for factorials using both iterative and recursive (e.g. n * factorial(n-1) for e.g.). I read in a textbook (without been given any further explanations) that there is an even more efficient way of coding for factorials by dividing…
user65165
- 745
- 1
- 7
- 7
57
votes
4 answers
Why polynomial time is called "efficient"?
Why in computer science any complexity which is at most polynomial is considered efficient?
For any practical application(a), algorithms with complexity $n^{\log n}$ are way faster than algorithms that run in time, say, $n^{80}$, but the first is…
Ran G.
- 20,884
- 3
- 61
- 117
52
votes
6 answers
Dealing with intractability: NP-complete problems
Assume that I am a programmer and I have an NP-complete problem that I need to solve it. What methods are available to deal with NPC problems? Is there a survey or something similar on this topic?
Anonymous
- 621
- 7
- 5
36
votes
7 answers
Why is selection sort faster than bubble sort?
It is written on Wikipedia that "... selection sort almost always outperforms bubble sort and gnome sort." Can anybody please explain to me why is selection sort considered faster than bubble sort even though both of them have:
Worst case time…
RYO
- 501
- 1
- 5
- 8
34
votes
5 answers
Adding elements to a sorted array
What would be the fastest way of doing this (from an algorithmic perspective, as well as a practical matter)?
I was thinking something along the following lines.
I could add to the end of an array and then use bubblesort as it has a best case…
soandos
- 1,143
- 2
- 10
- 23
31
votes
3 answers
When is the AKS primality test actually faster than other tests?
I am trying to get an idea of how the AKS primality test should be interpreted as I learn about it, e.g. a corollary for proving that PRIMES ⊆ P, or an actually practical algorithm for primality testing on computers.
The test has polynomial runtime…
Vortico
- 411
- 1
- 4
- 5
31
votes
7 answers
Are algorithms (and efficiency in general) getting less important?
Since buying computation power is much affordable than in the past, are the knowledge of algorithms and being efficient getting less important? It's clear that you would want to avoid an infinite loop, so, not everything goes. But if you have better…
Quora Feans
- 883
- 1
- 9
- 15
29
votes
3 answers
Retrieving the shortest path of a dynamic graph
I'm studying shortest paths in directed graphs currently. There are many efficient algorithms for finding the shortest path in a network, like dijkstra's or bellman-ford's. But what if the graph is dynamic? By saying dynamic I mean that we can…
Rontogiannis Aristofanis
- 837
- 3
- 9
- 17
27
votes
2 answers
Efficient map data structure supporting approximate lookup
I'm looking for a data structure that supports efficient approximate lookups of keys (e.g., Levenshtein distance for strings), returning the closest possible match for the input key. The best suited data structure I've found so far are…
merijn
- 409
- 4
- 6
23
votes
7 answers
One element that differs in two arrays. How to find it efficiently?
I am preparing for a coding interview and I can't really figure out the most efficient way to solve this problem.
Let's say we have two arrays consisting of numbers that are unsorted. Array 2 contains a number that Array 1 does not. Both arrays have…
Konstantino Sparakis
- 333
- 3
- 9
21
votes
3 answers
What is the most efficient way to compute factorials modulo a prime?
Do you know any algorithm that calculates the factorial after modulus efficiently?
For example, I want to program:
for(i=0; i<5; i++)
sum += factorial(p-i) % p;
But, p is a big number (prime) for applying factorial directly $(p \leq 10^ 8)$.
In…
Jonathan Prieto-Cubides
- 2,229
- 3
- 18
- 26
16
votes
2 answers
Problems that feel exponential but are P
I'm trying to build a list of algorithms/problems that are "exceptionally useful", as in, solving problems that 'seem' very exponential in nature, but have some particularly clever algorithm that ultimately solves them. Examples of what I…
Alex Meiburg
- 955
- 4
- 18
15
votes
7 answers
Can we say DFA is more efficient than NFA?
I just started reading about theory of computation. If we compare which is more powerful (in accepting strings), both are same. But what about efficiency ? DFA will be fast compared to NFA, since it has only one outgoing edge & there will be no…
avi
- 1,473
- 4
- 24
- 39
14
votes
2 answers
Are all context-free and regular languages efficiently decidable?
I came across this figure which shows that context-free and regular languages are (proper) subsets of efficient problems (supposedly $\mathrm{P}$). I perfectly understand that efficient problems are a subset of all decidable problems because we can…
Gigili
- 2,213
- 3
- 22
- 31