Tagged Questions
An algorithm is a sequence of well-defined steps that defines an abstract solution to a problem. Use this tag when your issue is related to algorithm design.
0
votes
0answers
23 views
Optimizing Javascript code for finding prime numbers
I'm attempting a codewars.com challenge and I'm having some issues with making my code more efficient. The instructions for the challenge are to find all the primes in a range, then I have to find two ...
0
votes
2answers
18 views
what is the most efficient way to keep (or sort) top 10 best seller products?
What is a good algorithm to use when you want to keep top ten best sellers and keep adjusting it as products are sold? I just got curious while studying for the interview.
A good example is how ...
-4
votes
0answers
25 views
C# Generate series of numbers than add up to n but each value cant be less than set minimum value [on hold]
Okay pretty simple what I want to do.
I want a create 5 individual values (count) that add up to 40 million (total) but each value can not be less than 500,000 (minimumValue).
The variables count, ...
0
votes
0answers
10 views
Caching time series aggregates of diffs
Is it possible to precalculate (cache) aggregates (min/max/avg) of values which are a difference of two signals?
I have several channels (e.g. 50), with one or more measurements each second, and I ...
0
votes
0answers
18 views
Python - Blowfish decryption issue
I'm currently trying to recreate the Blowfish algorithm of Bruce Schneier on Python 3.5. I ended the ciphering pretty well I guess (I check the result that I should get on website which allow an ...
0
votes
0answers
19 views
Understanding Recursion using flow of control through recursion calls for Merge Sort
I am studying the flow of control using recursion in Merge Sort.
The particular algorithm I used is:
MergeS(ar, p, r){
1. if p<r{
2. k = floor[(p+r)/2]
3. MergeS(ar, p , k)
4. ...
-1
votes
1answer
36 views
Implementing a constructor with two methods that prints all values inferior to zero in java
I would like to know why I cannot compile the following code when I do: javac Testing.java in the terminal.
public class Testing {
private static int InfThanZero(int[] elems) {
i = 0;
...
1
vote
0answers
45 views
Is this index algorithm worth anything?
I have theorised a indexing algorithm (like a B-tree).
However, there's a mental block stopping me actually implementing it.
The algorithm comes in to forms:
form 1:
A look up time of O(1) - O(log2(...
1
vote
0answers
22 views
How to calculate maximum flow in a directed graph that contains cycles
I'm trying to find maximum flow in a network using Ford Fulkerson algorithm, it works great for acyclic graphs however if there's a cycle it'd loop forever. Here's the code I'm using to find the max ...
-2
votes
0answers
10 views
What is the solution to the recursive formula
What is the solution to the recursive formula
T(1) = 1 and T(n) = T( 𝑛/2 ) + T( 𝑛/2 ) ? Explain why?
i. T(n) = Θ(log(n)). ii. T(n) = Θ(log2 (n)). iii. T(n) = Θ(n).
0
votes
0answers
16 views
At any point we need to tell the top k products based on quantity
There is a stream of data coming.
Data contains Product Id and Quantity.
At any point we need to tell the top k products based on quantity.
My Approach :
Maintain one minHeap of size k
Maintain one ...
0
votes
1answer
35 views
Using for_each with std::unique_ptr
I'm having the following error when I try to use for_each algorithm with std::unique_ptr. I zoomed in on it under profile.h section below.
It's odd that I was able to compile if I changed it to std::...
-5
votes
0answers
24 views
Writing sorting array to a text file in dev-c++ [on hold]
I develop a code that use sorting algorithm to sort a random array given the size by user.
The question is how to write the sorted array to a text file??
0
votes
0answers
15 views
Real time mark recognition on Android
I'm building an Android app that has to identify, in realtime, a mark/pattern which will be on the four corners of a visiting card. I'm using a preview stream of the rear camera of the phone as input.
...
-1
votes
1answer
23 views
What are the blocks in the subsystem in this simulink car counting algorithm model?
I'm using this link http://www.mathworks.com/matlabcentral/fileexchange/52456-counting-cars-and-analyzing-traffic-using-a-webcam--a-raspberry-pi-and-thingspeak
as reference for making my car counting ...
0
votes
0answers
25 views
Reference for algorithm to compute next larger elements
Given an array of unsorted numbers, there is a very simple O(n) algorithm to calculate, for each position, the distance (or absolute position) of the next larger element to its right. This algo pops ...
0
votes
0answers
27 views
Which linear time Suffix Array Algorithm [on hold]
I read,understand and implemented O(n log n) prefix doubling algorithm.
But on wikipedia and elsewhere it was suggested that an O(n) algorithm also exist.
and there are bunch of it
SA-IS algorithm,
KA ...
2
votes
1answer
23 views
Steganography Algorithm using Python PIL
I am trying to code basic steganography algorithms for B&W images using Python PIL.
Using an example image I can successfully extract the hidden image within it, and hide other images to ...
-1
votes
1answer
23 views
Choosing the best matching item from set according to some metric
I face with following problem:
I have list of p items (n-dimensional vectors) A and other set of q items B with metric which describes how "good matching" is that set B (it's some value). Now, I ...
2
votes
1answer
37 views
LIS for coordinate values in O(NlogN) or O(Nlog^2N)
This is a standard Dynamic programming Question LIS PROBLEM
I want a longest increasing subsequence for points in 2D coordinates
that is, 2 points A(x1,y1) at index i in array , B(x2,y2) at index j ...
1
vote
0answers
16 views
Reconstituting deconstructed objects values into an object again
As it is hard to articulate what I am trying to do an example is probably the best thing to show. This is the output I have from an API
a[0].b[0].d.e=0
a[0].b[0].d.f='1,2'
a[0].b[0].d.h='x,y'
a[0].b[...
-3
votes
0answers
25 views
The cheapest path between two elements of an MxN matrix containing nonnegative real numbers [on hold]
The cheapest path between two elements of an MxN matrix
-1
votes
0answers
6 views
for weighted graph represented as adjacency matrix, why use “infinity” instead of 0?
apologies first, english is not my first language.
so I'm learning about graph and it's representations such as adjacency matrix, adjacency list, adjacency multilist, etc.
My book says for weighted ...
0
votes
1answer
20 views
Ilustrate the left-most derivation on a token stream
I am trying to understand the left-most derivation in the context of LL parsing algorithm. This link explains it from the generative perspective. i.e. It shows how to follow left-most derivation to ...
4
votes
0answers
78 views
Alternate way to compute product of pairwise sums mod 10^9+7 faster than O(N^2)
Given an array A of size N, I want to compute [equation editor]:
This was a problem in a past inter-college programming competition. We had to write a program that would solve up to 5 instance of ...
0
votes
1answer
45 views
Trying to create a Planning algorithm
I have a list representing the year which is filled with a sub-list for each day of the year.
year = []
for i in range(0,52*7):
day = [i,0] #[day number, 0 = empty, 1 = something is planned]
...
-4
votes
0answers
25 views
Single Linked List
I have a single linked list defined below, and I have below questions:
While printing elements we are using "Node- head" and iterates through all elements. But, when we use deleteEnd() operation we ...
1
vote
1answer
31 views
Lagrange's four-square Implementation
I am learning about Lagrange theorem , According to which every number can be represent a sum of square , But how do i implement this algorithm , i have search the web but i could not find any ...
1
vote
1answer
39 views
Seperating Axis thereom: Calculating the MTV for Polygon & Line Segment
I've been attempting, for months now, to write a function to return the minimum translation needed to be applied to a line segment in order to separate it from an polygon in which intersects. I'm ...
1
vote
1answer
22 views
Computing the Bounding Sphere for a 3D Mesh in Python
As part of writing a 3D game library, I am trying to implement frustum culling in order to avoid rendering objects that are outside of the camera perspective frustum. To do this, I first need to ...
-1
votes
0answers
32 views
Maze solving algorithm fails on certain test cases
I am on the first challenge of level 3 on Google's Foobar challenges.
Here is the problem:
Pepare the Bunnies' Escape
You're awfully close to destroying the LAMBCHOP doomsday device and ...
0
votes
0answers
28 views
Actual path in maximum path sum in binary tree
I'm trying to store and print the actual path in the problem of finding maximum path sum in a binary tree. I already know how to find the maximum path sum (below), but how can we add a snippet to ...
-1
votes
0answers
23 views
algorithm to get -2 based binary bits [on hold]
What is the correct algorithm to get the -2 based binary bits (each bit can be just either 1 or 0) for a given value?
(Please assume that the value surely has -2 based binary bits.)
For example, when ...
2
votes
1answer
33 views
re-arrange task for minimal execution time
Working on below task re-arrange problem, post problem and my code in Python 2.7. My specific questions,
Any better ideas to optimize for algorithm time complexity (or space complexity)?
When we find ...
1
vote
1answer
27 views
Tarjan's strong connected component wrong or my code is wrong?
I am trying to implement Tarjan's strongly connected graph algorithm (https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm), here is my code and I am confused why vertex 4 ...
6
votes
1answer
104 views
Can I abuse a predicate to perform operations on the elements before remove_if removes them?
I have a std::list of objects. The list is sorted and must stay that way. I need to find those objects that satisfy a certain criterion (I have a predicate for this), pass them to a function, and then ...
-1
votes
1answer
29 views
How to align rectangles(textbox) in an area with fixed width
problem:
given that a list of Textbox and maximum page width, how to lay out these Textboxes. If a textbox is unable to be placed at the end of one row, it will be placed in the next row.
Note: you ...
1
vote
1answer
40 views
Array manipulation (Minimum deletions required)
Given a array on positive integers, I can decrease any element by any amount such that all the remaining non zero elements are equal.
I have to find min value which is sum of all the decrease ...
0
votes
1answer
20 views
Check value of array in Construct 2
In my mind I want to do this:
If (my button is clicked)
{
if(q_shuffled_arr_easy[0][5]) == 0)
// do X
else
// do Y
}
For that reason I have structured my event sheet like ...
0
votes
0answers
15 views
Are there neural network supervised learning algorithms that figure out the arragement of nodes and connections by themselves?
The most popular choice for neural network supervised learning algorithms is probably packpropagation, but it requires the user to define the arrangement of hidden nodes before beginning with the ...
2
votes
1answer
41 views
How can I build a weighted random list?
I'm writing a ranking algorithm and I would like to add randomness factor .
I'm generating a list of 10 items where each item has a value from 1 to 10 :
l = [random.randint(1,10) for num in range(1,...
1
vote
1answer
20 views
Deleteing alarms in alarm manager
For example, i have a calendar, which allows user to set every day alarm. For this function i took alarm manager's method setRepeating(). But my problem comes when user wants to delete alarm from ...
-2
votes
0answers
16 views
How can we deal with Multiple table based on key of HashMap?
I have a HashMap and for each key, I have to insert records of HashMap into different table number keys could vary on iteration.
Ex. myMap has keys like 1,2,3 (iteration 1) and for each key, I have ...
3
votes
1answer
39 views
Binary tree - not able to add values
In the below program, I am trying to populate a BST with the values present in an array arr. The program seems to run in a loop for a long time and then I get a segmentation fault. Can somebody ...
-3
votes
0answers
29 views
BFS Algoritm - Pseudo Code [on hold]
There are two types of professional wrestlers: “babyfaces” (“good guys”) and
“heels” (“bad guys”). Between any pair of professional wrestlers, there may or
may not be a rivalry. Suppose we have n ...
0
votes
0answers
104 views
String manipulation | Competitive Programming
I have a String (lowercase letters) of size N with 1 based index.
Now I am given Q queries and each query consists of two integers x,y.
For every query I have to print min number of deletion from ...
0
votes
3answers
30 views
Sum of all the sub-sequences of a number strored as a string
Find the sum of all the sub-sequences of a number stored as a string modulo (10^9)+7. The number can have up to N=2*(10^5) digits.
Example - If the string is 123, its sub-sequences are 1, 2, 3, 12, ...
1
vote
3answers
53 views
Algorithm to Divide the number into 4 square part
I am having a number N i want to divide this number into sum of square contains upto 4 numbers.
For Ex:
120 = 8^2 + 6^2 + 4^2 + 2^2
6 = 0^2 + 1^2 + 1^2 + 2^2
20 = 4^2 + 2^2+ 0^2+ 0^2
My approach
...
1
vote
1answer
31 views
Dijkstra's Algorithm with Topological Sort
I came across this passage in a textbook:
"If the graph is acyclic, we can improve Dijkstra’s algorithm. Vertices may be selected in topological order since when a vertex is selected, its distance ...
1
vote
2answers
21 views
Count percentages on poll with PHP/Mysql
I am working on poll system and i want to count percentages of how many time this variant has been chosen.
For example i have got 4 available variants
Poll name | Vote number
Java | 250
...