New answers tagged algorithm
0
votes
Closest Pair of Points - Optimizing Code for big sets of points
What do you want to optimise it for - what are your bottlenecks right now?
You could profile the code to identify improvement areas, but if you truly are concerned with speed or memory footprint here ...
0
votes
Calculating square roots using binary search
You're not using binarysearch here, but a form of Newton's Method. This will work, and is the appropriate algorithm for floating point numbers, but unlike binarysearch, it takes no advantage of the ...
0
votes
Calculating square roots using binary search
Not familiar with rust but there are a few improvements.
when writing the code usually we go for the happy scenario, in the case of enterprise applications users may enter parameters which are not in ...
1
vote
Printing the first n numbers of the Fibonacci sequence
n--;
}while(n >= 1);
You don't need to consume the input argument. You already have an up-to-date value.
...
1
vote
Printing the first n numbers of the Fibonacci sequence
JavaScript number primitives and Number objects use IEEE 754 Floating-Point Arithmetic. The Number.MAX_SAFE_INTEGER constant represents the maximum safe integer in JavaScript (2^53 - 1). Use ...
1
vote
Printing the first n numbers of the Fibonacci sequence
For readability, I prefer the (pythonesque?!) destructuring assignment
(and array over, say, BigUint64Array[n]).
I do not find value added by the name suffix ...
1
vote
Accepted
Solution to arithmetic arranger from freecodecamp
Use PEP484 type hints.
The too-many-problems and too-many-digits constraints are not good ones, but whatever: we'll keep them because the problem asks so.
You call ...
1
vote
Accepted
Number of paths in a randomly labeled complete graph
Prefer struct over std::tuple where possible
std::tuple has several drawbacks over declaring ...
1
vote
Calculate the value of PI in JS
There's no need to recalculate the factorials and powers from scratch each time around the loop. Remember the last values and just multiply to get the next value.
Approximate idea (untested, and by a ...
1
vote
Case-insensitive sort in C
Bug: String handling is unsigned
For all functions in this subclause, each character shall be interpreted as if it had the type unsigned char (and therefore every possible object representation is ...
0
votes
Find all pairs of natural numbers whose sum is 12
The spec is wrong, at least in its example data. There's one too many [6,6] and one too few [5,7].
The spec asks you to think ...
2
votes
Find all pairs of natural numbers whose sum is 12
Reading the input. The format of the input file is not clarified in great
detail, but it looks like the same format one would get from printing a Python
list of integers. Which means that its format ...
2
votes
Deepest pit of an array
function deepest_pit(B) {
The JavaScript style guide here indicates that camelCase is recommended for functions. JavaScript is ...
6
votes
Deepest pit of an array
Overall, reading this code, my reaction is "huh?". It looks like a bunch of gibberish at first (and second) glance. There are no english words. I would not want to maintain this code after ...
3
votes
Topological Sort C++
We use std::unordered_map but haven't included the corresponding header. Perhaps that works on your implementation, but it's not portable to depend on that.
...
1
vote
3
votes
Accepted
С++: Find max element from section in matrix
Create a class Matrix
Instead of passing around vectors of vectors, consider creating a class Matrix. That makes the code much ...
0
votes
1
vote
Estimating the total production count from a few random serial numbers
The review comments are inline after ///. A summary of the review follows the code
...
0
votes
Duplicate Binary Search Improvements
First, I want to say thank you to everyone who offered their critiques and advice.
Not only did I learn a lot about binary search, I learned a lot about how to write better Python code.
...
2
votes
Duplicate Binary Search Improvements
Style issue
There is a style guide for Python called PEP 8 which is definitly worth reading.
Among other things:
Avoid trailing whitespace anywhere
Comparisons to singletons like None should always ...
1
vote
Reading 12-bit words from 32-bit stream
It took me a while to figure out what is really going on here, because the explanation is either incomplete, incorrect, or both.
In fact, the 12-bit values are not being read in the order shown, are ...
2
votes
Accepted
isPalindrom-function in TypeScript
I have used the double-equals operator, because the values can't be something else then strings. Is it still necessary to use the triple-equals operator in TypeScript?
This is backwards. Necessary? ...
2
votes
Reading 12-bit words from 32-bit stream
Overview:
I can't see anything wrong with this code on a read through it (I did not compile it).
All my comments are minor and just nit picky.
So the below is just a few things I would do differently (...
1
vote
Accepted
Subset Product Algorithm
Reasons to put code in functions (and classes):
Code on module level is evaluated right away:
I can't try it out using copy&paste if there is an input() ...
1
vote
Algorithm for twoSum
You can see that your solution is indeed O(N2), because:
The outer loop goes through N elements.
For each iteration of the outer loop, the inner loop goes through, on average, N/2 elements.
...
0
votes
Accepted
Algorithm for twoSum
Hopefully it's obvious that the "worst case" runtime will happen when there is no matching pair in $nums.* **
In that situation, every (unordered) pair of ...
Top 50 recent answers are included
Related Tags
algorithm × 4922java × 1269
python × 1147
performance × 965
c++ × 797
programming-challenge × 657
javascript × 480
c# × 399
strings × 348
sorting × 315
python-3.x × 309
c × 301
beginner × 300
graph × 251
time-limit-exceeded × 238
array × 236
tree × 213
recursion × 169
python-2.x × 166
interview-questions × 165
complexity × 129
combinatorics × 126
c++11 × 101
mathematics × 97
object-oriented × 94