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
3answers
45 views
Longest Path for Directed Cyclic Graph
What algorithm is used to find the longest path thru a directed cyclic unweighted graph. Each node points to only one other node. The graphs have up to 10^9 nodes. (I searched here and google to no ...
1
vote
0answers
29 views
Java: How to implement wildcard matching?
I'm researching on how to find k values in the BST that are closest to the target, and came across the following implementation with the rules:
'?' Matches any single character.
'*' Matches ...
2
votes
1answer
40 views
Using matrices to find the number of different ways to write n as the sum of 1, 3, and 4?
This is a question given in this presentation. Dynamic Programming
now i have implemented the algorithm using recursion and it works fine for small values. But when n is greater than 30 it becomes ...
15
votes
2answers
293 views
Mix two non-opaque colors with “hue” blend mode
I want to implement color blending as described in the W3C compositing and blending spec. (I'm doing this in JavaScript but the language shouldn't really matter for solving my problem.)
In retrospect:...
1
vote
2answers
87 views
Trying to compare a recursive and an iterative algorithm
I have two algorithms that solve this problem: Generate all sequences of bits within hamming distance t. Now I want to compare them theoretically (I do have time measurements, if needed).
The ...
0
votes
1answer
42 views
Can someone explain why these running times are right for this?
An algorithm runs in time n^2 + 3n + 5 for all inputs of size greater or equal to 500 and in time 2^(2n) for all input sizes less than 500. Select all the true statements from below:
1: Its running ...
-4
votes
0answers
26 views
hashin sets. Pairwise independence of hash functions [on hold]
i want to know how can i establish if k was in S or not? What is the probability of error?
imaging Your company has a database S ⊆ U of keys. For this database, it uses a hash function h uniformly ...
0
votes
2answers
46 views
Trying to understand one-class SVM
I am trying to use one-class SVM with Python scikit-learn.
But I do not understand what are the different variables X_outliers, n_error_train, n_error_test, n_error_outliers, etc. which are at this ...
0
votes
0answers
13 views
Trying to understand isolation forest algorithm
I am trying to use isolation forest algorithm with Python scikit-learn.
I do not understand why do I have to generate the sets X_test and X_outliers, because, when I get my data, I have no idea if ...
1
vote
0answers
7 views
Java ECLIPSE Nearest TSP with Nearest Neighbour Algorithm
First question I ask here on the forum, had some use on many questions posted here. I am stuck with my current assignment: I need to make a TSP with a nearest neighbour algorithm and then store the ...
96
votes
24answers
55k views
How do you calculate the average of a set of circular data?
I want to calculate the average of a set of circular data. For example, I might have several samples from the reading of a compass. The problem of course is how to deal with the wraparound. The same ...
0
votes
1answer
15 views
Resolving a logic issue with Arduino user input
I'm working on an Arduino program that reads data from an anemometer and if the wind is above a certain threshold, it activates a relay. The threshold can be set in two ways:
1) The user can use two ...
-1
votes
1answer
32 views
Specific Sorting Algorithm in dictionary
I'm trying to sort a dictionary in this way:
I have a list of 9 randoms letters : ['A', 'R', 'E', 'T', 'R', 'I', 'E', 'D', 'S']
and a letter can occur multiple times like T, R and E in this example.
...
0
votes
0answers
23 views
+50
Dictionary in Swift with Mutable Array as value is performing very slow? How to optimize or construct properly?
I am trying to build a data structure in Swift that maps an Integer to an array of objects (a dictionary with int as key and array as value). The objects are extremely small, and they simply wrap a ...
62
votes
6answers
77k views
calculate mean and standard deviation from a vector of samples in C++ using boost
Is there a way to calculate mean and standard deviation for a vector containing samples using boost?
Or do I have to create an accumulator and feed the vector into it?
0
votes
0answers
12 views
Tabu list length vs cadency
I'm trying to solve TSP problem with tabu search. I understand most foundations of this heuristic method. But I have trouble with figuring out what is the difference between cadence of some tabu move ...
7
votes
2answers
151 views
Is There a Reason Standard Algorithms Take Lambdas by Value? [duplicate]
So I asked a question here: Lambda Works on Latest Visual Studio, but Doesn't Work Elsewhere to which I got the response, that my code was implementation defined since the standard's 25.1 [...
2
votes
1answer
36 views
algorithm to find optimal x y index such that the sum of points in each quadrant is minimized
I have a 2D array that contains various data points. Refer to Fig 1.
I need to split it into 4 quadrants in a such way that the sum of all points within each quadrant is minimized. The minimum size of ...
1
vote
1answer
31 views
azure sql database intelligent search algorithm suggestions needed
I have a sql database in Azure. The search algorithm would proceed more or less as follows:
It would consider a text field in Table_A, Field_A1, which contains a varying amount of text (nvarchar(max)...
-1
votes
0answers
12 views
Show the results of inserting the keys in a B-tree with minimum degree 2
Show the results of inserting the keys
F; S; Q; K; C; L; H; T; V; W; M; R; N; P; A; B; X; Y; D; Z; E
in order into an empty B-tree with minimum degree 2. Draw only the configurations
of the tree ...
3
votes
4answers
180 views
Finding prime number between 1 and N
In fact my teacher has passed the program that calculates the prime numbers from 1 to N. But I did not understand some things in the code and would like to help.
In line 18 we have the following: for(...
1
vote
4answers
103 views
Best way to erase vector of ranges from std::vector
In one of my projects it is necessary to remove certain elements from a std::vector<double> values. The indices I have to remove are given as a vector of intervals. For example {1,3} means, that ...
-3
votes
1answer
21 views
What can be said about time complexity of $C(N) + A(N).B(N)$?
Let A(N)= Θ(N)
B(N) = Θ(N) and
C(N) = Ω(N)
Then, What can be said about C(N) + A(N).B(N) ?
-3
votes
0answers
29 views
Why we drop all numers in Big O Notation and just take the highest powered item [on hold]
For Example :
for(i = 0; i < x; i++) {
for(z = 0; z < x; z++) {
Val *= 2;
Tmp += 1;
}
}
while(x != 0) {
Val –= x;
x--;
}
return 0;
Big O ...
-3
votes
0answers
26 views
Automated internet search algoritm
I would like to know if it is technically possible to develop an automated internet search algorithm. Let me give you a random example of what I have in mind.
For example, let’s say I am the largest ...
-1
votes
0answers
11 views
B&B solution to 1-0 knapsack with dependent item weight
I am trying to solve a variation of the 0-1 knapsack problem, where the weight of the items is a function of the set of items already included in the knapsack. I have tried to approach it through ...
0
votes
0answers
108 views
Solving N queries on array on N elements in linear time O(N)
Given an array of n elements. ‘n’ operations needs to be performed on the array. For each operation start_index, end_index,trim_value is given. One has trim the value starting from the start_index to ...
0
votes
1answer
50 views
Finding remainder of division the sum of the given diapason and 987654321
Could you help me please ? I need a fast algorithm for calculating the following : the remainder of division the sum of the integers in the power from given range ( from A to B , 1 < A,B < 10^8 )...
1
vote
3answers
78 views
Java - numbers with at least one 7 and one 9 in its digit
I have to code a program to determine how many positive integers under 1,000,000 have at least one 7 and at least one 9 among its digits by examining the digits in each number from 1 to 999,999 ("...
0
votes
0answers
21 views
Finding the leaf nodes in a tree using adjacency matrix
Hey guys I'm currently writing a code that is detecting whether a directed and unweighted graph is tree or not using the adjacency matrix, and also printing the leaf nodes. But I'm not quite happy ...
0
votes
0answers
27 views
Difference of Banker's algorithm and Deadlock avoidance?
What is the difference of deadlock avoidance and banker's algorithm? Deadlock avoidance is the evaluation of safe or unsafe state based on whether the processes have enough resources (memory, right?) ...
2
votes
2answers
27 views
An algorithm which finds a path in a tree along the maximum node values at each level
I am looking for an algorithm wich finds a path in a tree along the maximum node values at each level. The following graphic illustrates the problem:
If all nodes on a level would have unique values, ...
5
votes
6answers
227 views
Find free port not in use for apps - find some algorithm
I use the following API in my program to detrmine free port and provide it to application to run
portscanner.findAPortNotInUse(3000, 65000, '127.0.0.1', function(error, port) {
console.log('...
74
votes
4answers
16k views
What Java Collection should I use?
In this question How can I efficiently select a Standard Library container in C++11? is a handy flow chart to use when choosing C++ collections.
I thought that this was a useful resource for people ...
1
vote
2answers
48 views
Detect self intersection of a polygon with n sides?
I am using Google Maps SDK to allow a user to draw a polygon on the map by tapping. Everything works perfectly is the user is to draw a polygon following a path and continues on that path without ...
0
votes
1answer
56 views
Minimum Spanning tree variation algorithm
I was asked the following question in an interview and I am unable to find an efficient solution.
Here is the problem:
We want to build a network and we are given n nodes and m edges. Edges
are ...
4
votes
2answers
174 views
Calculating Luhn Algorithm with Java 8 Stream
I am trying to validate an IMEI number with the Help of Stream API in Java 8.
private void ValidateIMEI() {
field //a field holding an IMEI Number
.getText().chars()
.map(...
-5
votes
0answers
39 views
How can I designate big power?
How can i designate this?
(pow(a,b) +j) % m
Where a and b are very big? I tried to use a modular algorithm, but it is for a^b mod m.
2
votes
3answers
88 views
what is the algorithm behind the solution below
I encountered recursive exercises for improving my coding skills and found the following problem.
Given an array of ints, is it possible to choose a group of some of the ints, such that the group ...
0
votes
0answers
16 views
Harmony search Algorithm
I was asked to implement a Simplified Harmony search algorithm to solve 0-1 knapsack problem from a scientific paper, but I've never worked on Harmony search Algorithm before and I have no idea how ...
1
vote
1answer
47 views
Algorithm: How to re-arrange a time-range event (interval) list based on wether time events overlap, faster than O(n^2)?
Let's say I have an array of time ranges like so:
[
{ name: 'A', startTime: '10:15', endTime: '11:15'},
{ name: 'B', startTime: '10:45', endTime: '14:15'},
{ name: 'C', startTime: '15:35', ...
-1
votes
1answer
34 views
Convert logical formula to DNF in vb.net
I need a function to convert a formula like this:
(A = 1 AND (B > 4 OR C > 5)) OR (A = 3 AND (B > 4 OR C > 10))
to a DNF format. The formula could be more complex that this example.
...
-5
votes
2answers
87 views
How to find next element in Array moving clockwise?
See attached image.
The one in red is what the array looks like normally and the values go round clockwise.
e.g [A, B, C, D, E, F, G, H]
So say you had the one in green, how could you work out ...
0
votes
2answers
55 views
Genetic algorithm to solve a quadratic equation
I have a problem understanding the process for genetic algorithms. I found examples of maximizing a function over an interval, and I think I understand them, but how can a genetic algorithm be used to ...
0
votes
2answers
81 views
Find duplicate in a table
I have a table that contains duplicate.
The way to identify a duplicate is
- the key should be in the same group(1,2,3 or 4)
- the p should be the same
- P is an id that say this keys are the same
...
0
votes
1answer
32 views
Modified Dominos Algorithm
I'm trying to solve a slight variation of dominos, in which you're given a set of domino tiles, and must order them such that the number of mismatches (when two adjacent tiles don't have the same ...
1
vote
2answers
54 views
Given a list of real numbers. What is a good algorithm to group them together so that the max and the min in the group is smaller than, say 5?
Say I have a list of number like this: 1,100,2,10,3,14,55,101,102,58
I want an algorithm to group them together such that
The number of groups should be as small as possible
The difference between ...
0
votes
0answers
11 views
How I can use the For Statement in Latex in my Pseudocode?
hi i am new in latex and want to write a pseudocode in my document. For this I use the package
\usepackage[]{algorithm2e}
I want to show the bellman-ford-algorithm.
BEGIN
d(v[1]) ← 0
FOR j = ...
2
votes
1answer
44 views
Algorithm for rendering DAG as table
I have a DAG representing a program in a stack-based dataflow language. Each node represents a function or value. Edges represent inputs and outputs, of which each node may have 0 or more.
First, ...
-2
votes
0answers
19 views
How can we solve problems like DQUERY of SPOJ using online programming? [on hold]
I couldn't come across a solution for this type of problem using online programming. I have solved this problem(and few more of this type) using offline programming by 3 different ways- Segment Tree, ...