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.
-3
votes
0answers
29 views
Round Robin Algorithm implementation check [on hold]
Hi Guys i tried to implement round robin algorithm in java. i need to know is there any other possibilities are there like for example do we consider processes priorities in it or the priorities ...
0
votes
4answers
51 views
I am converting numbers into words as well as showing them on screen also trying to show a word in javascript and html
I am trying to convert a number into word also showing them while i input the number , the same thing with a word where i input a word and it show while i type on screen, but having some trouble as ...
0
votes
0answers
17 views
3D Collision resolution, moving AABB + polyhedron
I have been writing a game engine in my free time, but I've been stuck for a couple weeks trying to get collisions working.
Currently I am representing entities' colliders with AABBs, and the ...
0
votes
0answers
20 views
Quick ways to fill the missing values of a pandas dataframe with complicated rules
In the m*(n+1) pandas dataframe data_df, there is a timestamp column whose values are possibly repeated integers in range(0,p) (which denote time; there are p unique values in total) and no missing ...
0
votes
3answers
32 views
using filter and generator to generator endless prime number in python
Below is a python program I found to find prime numbers using Sieve of Eratosthenes. It uses filter and generator. I'm not able to understand it.
def _odd_iter():
n = 1
while True:
n =...
1
vote
1answer
44 views
Find sequential smallest sums of the multiples of three different numbers, javascript
On this post I found an algorithm to determine the luminance of an RGB color:
Luminance (standard for certain colour spaces): (0.2126*R + 0.7152*G + 0.0722*B)
I want to use this equation, starting ...
-2
votes
1answer
24 views
Method that checks if one word is a rotation of another
Working on the Cracking The Coding Interview problem that asks for a method that checks if one string is a rotation of another. The one caveat to the problem is that it must be solved with a single ...
0
votes
0answers
24 views
character rearrange algorithm implementation correctness
I'm working on the problem below and have posted my code of two different implementation alternatives. My question is, I have two versions of implementation, first version is (1) process most high ...
0
votes
1answer
13 views
Bitmasking--when to use hex vs binary
I'm working on a problem out of Cracking The Coding Interview which requires that I swap odd and even bits in an integer with as few instructions as possible (e.g bit 0 and 1 are swapped, bits 2 and 3 ...
-1
votes
1answer
28 views
How do I generate a list of permutations based on given characters and a length?
For example,
I have a list of characters that I want to generate permutations of e.g. ['*', '+'] and a length that I want the permutations to be generated off e.g. 2. In other words, I want to find ...
0
votes
0answers
28 views
Complete algorithm for most general consisten specialisations of a concept
I'm studying for my course called "Introduction in Data Mining" and I'm following Peter Flach book "Machine Learning". I want to implement in Python the algorithm to find most general consistent ...
0
votes
1answer
22 views
Edge Detection Algorithm with Processing (Java)
i want to code an algorithm, that can do an edge detection for an image.
I already have a part of the code, which detects all edges in horizontal way.
Example picture:
But i need an edge detection in ...
-3
votes
1answer
33 views
Tricky task about geometric progression
Given two numbers l and r. Need to find length of the longest geometric progression which consists of some numbers between l and r — int-numbers in interval [l,r].
Note that the ratio of geometric ...
1
vote
0answers
30 views
Huffman Encoding priority queue
I'm working on an assignment where I should write an encoding and decoding application for the Huffman algorithm, based on a priority queue. We have to read a file, count the frequencies of the ...
1
vote
1answer
57 views
Mergesort implementation is slow
Iam doing a report about different sorting algorithms in C++. What baffles me is that my mergesort seems to be slower than heapsort in both of the languages. What I've seen is that heapsort is ...
0
votes
0answers
97 views
Make palindrome substring finding algorithm O(n)
I recently did an online challenge and was asked to find the number of all consecutive chars, where it is symmetrical.
e.g. 02002 would give the following
3 x 0, 2 x 2 (single digits are symmetrical)...
0
votes
1answer
16 views
Data Structure which allows efficent searching of objects
I have a very large database of Objects (read an array of key/value pairs, like [{}, {}, {}] in standard C notation), and I need to be able to search for any value of any key within that set of pairs ...
0
votes
1answer
17 views
A* algorithm for undirected graph
I know A* algorithm can be used in directed graph, can we use it in undirected graph as well?
3
votes
2answers
37 views
Using hashing for efficient Deep Packet Inspection
In order to enhance the performance of Deep Packet Inspection we are preprocessing the set of rules by performing a hashing algorithm on them which in turn divides the rules into smaller chunks of sub-...
0
votes
1answer
34 views
Graph of n vertices such that its diameter is 3 and the diameter of the complement is also 3?
Is it possible to have such a graph for every n? If so, is it possible to generate such a graph programatically?
Thanks in advance.
2
votes
2answers
48 views
Prefix search against half a billion strings
I have a list of 500 mil strings. The strings are alphanumeric, ASCII characters, of varying size (usually from 2-30 characters). Also, they're single words (or a combination of words without spaces ...
2
votes
2answers
40 views
Segmentation using maximum likelihood algorithm on images using python
I would like to perform image segmentation using maximum likelihood algorithm implemented in python.
The mean vectors of the classes, and covariance matrices are known, and iterating over the images (...
0
votes
2answers
44 views
Find sequence of consecutive numbers which's multiple is N
I have an exercise with an input N and it wants me to find a sequence of consecutive numbers which's multiple is equal to N. Example
Input | Output
60 | 3 5
3*4*5=60
What i have tried
cin&...
0
votes
1answer
22 views
Algorithm: Buying a collection of goods with vouchers
I'm struggling to come up with a solution for this problem for an algorithms course:
You go to a store and want to buy n = {n1, n2, ..., nn} goods, where the items can be different or not.
The store ...
2
votes
4answers
39 views
logic to print a number series 1,n,2,n-1,3,n-2,… series should be 1 to n(the input given)
I'm trying my hands on basic programming and I came across this question. I have a function with a return type as string, that takes an integer input and has to print the series mentioned. Here's what ...
1
vote
0answers
42 views
generating random variables with openmp in c++
How can I generate in parallel (is it efficient? possible?) random variables with my linear congruential generator below:
double* uniform(long N)
{
long i,j;
long a=16807;
long long m=(((long long)1)&...
-6
votes
0answers
46 views
C# - How to divide an array into 3 parts and find the smallest sum [on hold]
Example if I have this array:
4, 5, 1, 7, 8, 2, 6, 5
so it'll be divided into 3 part like this between 2 or 3 elements:
subarray1 {4,5} sum = 9
subarray2 {1,7,8} sum = 16
subarray3 {2,6,5} sum = 13
...
0
votes
0answers
17 views
Algorithm for constructing a CFG given a CFL
How would one construct a CFG from a language such as:
I know the answer and can verify it to be correct but have difficulty in understanding how to construct it; is there an algorithm to follow?
1
vote
2answers
43 views
0-1 Knapsack with penalty for under and overweight cases
Assume a classic 0-1 knapsack problem but you are allowed to overflow/underflow the sack with some penalty. X profit is deducted for every unit overflow (weight above max capacity) and Y profit is ...
0
votes
0answers
4 views
How to add elimination mechanism in Python genetic algorithm based on DEAP
Here is my question.
I'm dealing with one optimization problem using DEAP.
For now, I use toolbox.register("select", tools.selNSGA2) to select some fittest indivual to survive.
But I want to add ...
2
votes
2answers
42 views
JavaScript Code does not run in wanted order (Node.js, MongoDB)
I know about Node.js's non blocking I/O and what are async functions but I'm having trouble to point down why this code runs like it runs.
I'm connecting to a MongoDB collection, searching for ...
-1
votes
1answer
51 views
Number of ways N circles of different radius can be arranged in a line
Question: Given M points on a line separated by 11 unit. Find the number of ways N circles of different radii can be drawn so that they don't intersect or overlap or one inside another?? Provided that ...
-7
votes
0answers
48 views
{Noob help} Efficient way of coding a matrix multiplication using this algorithm in C?
I am studying algorithms , I found an algorithm for Fibonacci sequence but I find it difficult to code in c.
Let:
A[2][2] = {{1,1},{1,0}}
[{Fib(n),Fib(n-1)] = (A[2][2])^(n-1)*({1,0}) ;
Now this ...
-3
votes
1answer
26 views
Java Partition Algorithm
I'm looking for an recursive algorithm for partitioning a number in k parts.
For exemple :
P(5,2) > { {1,4},{2,3} }
P(7,2) > { {1,6},{2,5},{3,4} }
P(5,3) > { {1,1,3},{1,2,2} }
In Java, but ...
0
votes
0answers
22 views
Stacking plates( javascript)
I am trying to solve https://icpc.kattis.com/problems/stacking
here is what i have tried
var k=0;
function merge(arrays, sortFunc) {
let result = [], next;
const findNext = () =>
arrays.filter(...
1
vote
2answers
70 views
run time of two nested while loops inside a for loop
I am very confused while trying to find the complexity of an algorithm with a for loop and 2 nested while loops inside it that concern two linkedLists. Consider the following code:
public int func(...
-1
votes
1answer
27 views
build a linked list from broken sequnece
Suppose we have some sequence like A->B, C->D, B->C, D->E
We have to build a linked list out of it.
Output: A->B->C->D->E
There can be two scenarios. First case, we have all the sequences. Second ...
0
votes
0answers
52 views
knapsack if weight[i] is greater than total weight
i'm trying to get the greater value even if the weight[i] is greater than total weight and subtract the total value = total value - (20 * (weight[i] - total weight))
suppose i have set of weights {2, ...
0
votes
0answers
35 views
Nullify array only by incrementing and decrementing
This is not a homework question. Just encountered this interesting problem while preparing for regional informatics olympiad.
You have number N and an array of integers A1, A2, …, An. You can perform ...
0
votes
1answer
43 views
Represent a prime number as a sum of four squared integers
Given a prime number p, find a four integers such that p is equal to sum of square of those integers.
1 < p < 10^12.
If p is of form 8n + 1 or 8n + 5, then p can be written as sum of two ...
0
votes
0answers
14 views
laser minimal zap greedy algorithm
Suppose you are standing in a field surrounded by several large balloons. You want to use your brand new Acme Brand Zap-O-MaticTM to pop all the balloons, without moving from your current
location. ...
-6
votes
0answers
72 views
Number of ways N circles can be arranged, centered on a line [on hold]
Question:
Given M points on a line separated by 1 unit. Find the number of ways N circles of different radii can be drawn so that they dont intersect or overlap or one inside another?? Provided that ...
0
votes
0answers
18 views
How do recommendation systems break their subjects into list of attributes [on hold]
I learnt about recommendation engines and various approaches of handling them. I am a bit confused on the initial part. How do they break the subject they are working on into usable attributes? For ...
5
votes
3answers
129 views
How to efficiently find 10 greatest numbers from billions of numbers?
Problem Statement: Find 10 maximum numbers from a file which contains billions of numbers
Input:
97911
98855
12345
78982
.....
.....
I actually came up with the below solution which has
best case ...
1
vote
1answer
20 views
Longest Chain in 3D (Longest Increasing Subsequence on Posets)
Given two points:
A(x1,y1,z1) & B(x2,y2,z2)
chain basic condition
if x1 <= x2 and y1 <= y2 and !(x1 =x2 and y1 = y1) and z1< z2
A and B are in a Chain
Z coordinates will ...
0
votes
3answers
43 views
Copy values (mapped_type) from map to vector given a mapping from keys to indices
Suppose we have a function key_to_index that maps keys of a map to indices of a vector. For an example, let's just make it trivial:
std::map<int, int> source = {{1,55}, {4, 20}, {6, 25}};
std::...
0
votes
2answers
25 views
storing streaming data
Assuming streaming data (i.e. 10 Million strings every 10 minutes), what would be the fast and memory efficient way of storing strings such that if two strings have exactly the same characters but in ...
-4
votes
0answers
15 views
what algorithm stack overflow uses to check subjectivity/objectivity? [migrated]
I have observed that stack overflow doesn't let you post questions which are subjective.like if i have a keyword "question" it won't let me to post this. so, i want to know little bit about the ...
-1
votes
0answers
65 views
enclose maximum no of point inside square of length l
What would be the algorithm for given problem statement?
Given n points in 2D plain you need to find square(sides parallel to axes) of side length l which cover maximum no of points from given n ...
1
vote
2answers
41 views
Find circle of given radius that contains no points
I'm working on a problem that essentially reduces down to the following:
Given:
a set of (x,y) points. There may be 0 points in the set.
min and max x and y values, where the minimum values are ...