algorithm Questions
3
Solved
I am having trouble understanding how the rolling hash algorithm works after the hash has been reduced to modulus value by dividing by a prime number.
Consider the sequence of 5 digits in the numb...
Myers asked 23/4, 2016 at 17:26
7
Solved
I want to erase some elements in my std::map.
I wrote erase + remove_if technique which I always do with other sequence containers.
But it wasn't compile with map. Why?
And How can I do this job?
...
Vennieveno asked 10/8, 2011 at 8:23
7
Solved
I have an array of points in unknown dimensional space, such as:
data=numpy.array(
[[ 115, 241, 314],
[ 153, 413, 144],
[ 535, 2986, 41445]])
and I would like to find the average euclidean dista...
Phosphorite asked 5/3, 2010 at 0:3
3
Solved
Here's the code I wrote for finding the n-th Fibonacci number:
unsigned long long fib(int n)
{
unsigned long long u = 1, v = 1, t;
for(int i=2; i<=n; i++)
{
t = u + v;
u = v;
v = t;
}
...
6
Solved
I need to write a program to input a number and output its factorial's prime factorization in the form:
4!=(2^3)*(3^1)
5!=(2^3)*(3^1)*(5^1)
The problem is I still can't figure out how to get th...
Valentijn asked 17/1, 2014 at 22:5
3
Solved
I have implemented the design a LRU Cache Problem on LeetCode using the conventional method (Doubly Linked List+Hash Map). For those unfamiliar with the problem, this implementation looks something...
Bilander asked 17/2, 2019 at 6:21
13
I need an efficient way to select 2 largest integers from an array of 4, preserving the order.
E.g. 1,4,3,5 -> 4,5; 1,5,3,4 -> 5,4
What's the efficient way to do it (C/C++)?
I.e., with minimu...
1
Since C++11, the C++ Standard Library (c.f. Section 25.4.1.1 of a draft verion of the standard) requires the std::sort algorithm to have asymptotic worst case execution time O(n log n) instead of a...
Slacks asked 17/3, 2021 at 8:47
24
Solved
Given an array of integers, return indices of the two numbers such that they add up to a specific target.
Example:
Given nums = [3, 2, 4], target = 6,
Because nums[1] + nums[2] = 2 + 4 = 6
return ...
Cogon asked 18/8, 2019 at 12:53
8
Solved
I would like to generate a text file containing all 19,683 Tic-Tac-Toe board layouts in the structure of 0 = Blank, 1 = X, and 2 = O. Unfortunately math is not my strong suit and I cannot seem to f...
Bantamweight asked 19/9, 2011 at 4:23
9
Solved
Is there any fast way to find the largest power of 10 smaller than a given number?
I'm using this algorithm, at the moment, but something inside myself dies anytime I see it:
10**( int( math.log1...
Wistful asked 22/12, 2010 at 21:4
4
Solved
I'm building a website that will randomly display a yelp listing each time the page is refreshed. The yelp search api returns 20 listings in an array. Right now, I am using PHP's function rand(0,19...
8
Solved
How to create a function, which on every call generates a random integer number? This number must be most random as possible (according to uniform distribution). It is only allowed to use one stati...
4
Solved
I am trying to calculate the logarithm of a modified Bessel function of second type in MATLAB, i.e. something like that:
log(besselk(nu, Z))
where e.g.
nu = 750;
Z = 1;
I have a problem beca...
Plump asked 9/9, 2015 at 16:21
7
Solved
So, this is not my home work question, but it is taken from an ungraded homework of the coursera course on algorithms and data structures (which is now complete).
You are given an n by n grid of ...
3
Solved
I came up with the following implementation for the Greedy Set Cover after much discussion regarding my original question here. From the help I received, I encoded the problem into a "Greedy Set Co...
Mesocarp asked 29/10, 2011 at 23:22
6
Solved
I need to sanitize HTML submitted by the user by closing any open tags with correct nesting order. I have been looking for an algorithm or Python code to do this but haven't found anything except s...
20
How would I make a multiplication table that's organized into a neat table? My current code is:
n=int(input('Please enter a positive integer between 1 and 15: '))
for row in range(1,n+1):
for col...
Jacalynjacamar asked 6/12, 2013 at 3:26
14
Solved
Given two strings a and b, where a is lexicographically < b, I'd like to return a string c such that a < c < b. The use case is inserting a node in a database sorted by such keys. You can ...
5
Is there any easy solution? Or has anybody an example of an implementation?
Thanks, Jonas
3
Solved
EDIT: n is the number of persons. k is the kth person being eliminated. So for k=2, every 2nd person is getting eliminated.
int josephus(int n, int k)
{
if (n == 1)
return 1;
else
return (josep...
9
I wonder, can binary search be applied on a 2D array?
What would the conditions on the array be? Sorted on 2D??
What would be the time complexity for it?
How would the algorithm change the bounda...
Tadashi asked 12/12, 2010 at 11:55
4
For a collision algorithm I am developing, I need to find out how to reflect a line over another.
Line 1:
y=ax+b
Line 2:
y=cx+d
Line 3:
(a result of reflecting line 1 over line 2) y=e...
Procto asked 30/6, 2013 at 23:42
7
Solved
I have a list of numbers, e.g.
numbers = [1, 2, 3, 7, 7, 9, 10]
As you can see, numbers may appear more than once in this list.
I need to get all combinations of these numbers that have a given...
Jordison asked 29/12, 2015 at 19:14
7
Solved
Im writting a function to compare 2 versions, and return true if the second is bigger then first version.
but my algorithm have a "hole", and I cant figure out how fix.
function compareversion(ve...
Yenyenisei asked 28/10, 2011 at 16:4
© 2022 - 2024 — McMap. All rights reserved.