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.

learn more… | top users | synonyms (2)

1
vote
0answers
6 views

How should I keep track of several objects

I am trying to get better at programming and doing several exercises, I ve found this article http://www.cplusplus.com/forum/articles/12974/ and I got issue with that Graduation /The one harderst at ...
0
votes
2answers
9 views

Do connected graphs with more than N-1 edges always contain connected graph with N-1 edges?

We know that: If we have N vertices To build a connected undirected graph, you'll need at least N-1 edges. Let M be the set of possible connected undirected graphs with N-1 edges. ...
0
votes
1answer
16 views

Sum primes via Sieve of Eratosthenes in Javascript: Fails only if argument is prime

My implementation of the sieve itself seems to be working fine, and the summing function returns the correct result as long as the last value is not itself a prime number. Oddly, I can see the ...
0
votes
0answers
15 views

Depth First Search C++ implementation using adjacency list with two linked list

I am a university student and this is my first time asking a question here. First of all thank you for taking the time to read. We have a project which is about Graphs. So far I did the creation of ...
0
votes
0answers
17 views

What is the best algorithm for sorting biggest X number in a set

As the title says What is the best algorithm for sorting biggest X number in a set. With most algorithms we can do that NlogN. But is it possible better than that? For example with BinaryTree NLog(X). ...
-7
votes
0answers
37 views

How to do implement the solution (in C)? [on hold]

The input is a set of array and we have to find the array with unique code. 0 : [ 1, 8, 56, -9 ] 666 : [ 42, 7, 11, -96, 8 ] 42 : [ 9, 3, 6, 8, 12, 9, 3 ] 15 : [ 8, 12, 9 ] 666 : [ 56, -9, 1, 8, 56, -...
0
votes
0answers
24 views

PHP - Round Robin and 3rd person (2 players and one writer / refugee)

I have the following code poule = ['Jason', 'Raymond', 'Rupert', 'Mike', 'Simon', 'Jeremy']; $games = []; $cnt_players = count($poule); $players = $poule; if ($cnt_players % 2 != 0) { ...
2
votes
2answers
52 views

Using functors with STL algorithms versus lambda expressions? [duplicate]

Stroustrup gives the example of using an overloaded operator() to execute a function on vector elements during a transform operation: class Example { public: std::vector<int> Test1 {1,2,3,...
-3
votes
0answers
21 views

Algorithm for surviving [on hold]

I tried to solve a Problem from a Website and I can't find a algorithm to solve this Problem. Problem A person was send to mars with x potatoes and y candy. Everyday he produces only 5 units of ...
0
votes
1answer
19 views

Difference in normalization of Levenshtein (edit) distance?

If the Levenshtein distance between two strings, s and t is given by L(s,t), what is the difference in the impact on the resulting heuristic of the following two different normalization schemes? L(s,...
-3
votes
0answers
23 views

Selection algorithm

I'm taking an intro to algorithms course and unable to answer the following question: Let m>1 be some constant integer. Say there is a "blackbox" routine that finds value in in/m place (meaning the ...
-2
votes
0answers
23 views

ArrayIndexOutOfBoundsException - de Boor algorithm [duplicate]

I am currently working on writing a java implementation of the de Boor algorithm for B-spline curves, but the "ArrayIndexOutOfBoundsException: 2" error prevents my code from compiling. No matter ...
0
votes
0answers
18 views

Incorrect Knapsack recursive function

I wrote a recursive function to solve the Knapsack problem. It takes such arguments: Knapsack object(initially empty), array of items, available to put into knapsack(KnapsackItem). My recursion doesn'...
-1
votes
1answer
21 views

Maximum sum in a contiguous subarray of a given 2D array

I have solved this problem but all the explanation given are with DP solutions having complexity at least N^3. I have solved it in N^2 I am wondering if my solution is wrong. We are given a 2D array ...
1
vote
2answers
39 views

Python: List all possible paths in graph represented by dictionary

I have a dictionary with keys representing nodes and values representing possible nodes that the key can traverse to. Example: dependecyDict = { 'A': ['D'], 'B': ['A', 'E'], 'C': ['B'], 'D': ['C'],...
0
votes
0answers
40 views

Given an array of distinct integers , find 8 elements which sum up to a given Number?

Given an array of distinct integers , find 8 elements which sum up to a given Number. Arr[] = [10,2,6,3,4,9,0,1,7,6,8,5,14,234,5645,1124] Sum = 36 Answer: [1,2,3,4,5,6,7,8] What's the best way to ...
0
votes
1answer
20 views

algorithm approach to render a node mesh in an overlap free way

I have a couple of nodes (e.g. application names) and a couple of edges with labels (e.g. information flows/system interfaces with their information objects). I would like to be able to code a ...
-1
votes
0answers
13 views

best way to work with complex query relation generated By Yii2

I'm using yii2 for developing a complex website. i have already create my database and has a lot of tables that most of them are related to each other by foreign keys. First, i'm a yii beginner and ...
1
vote
1answer
26 views

Karatsuba algorithm working for small numbers but not for big ones, can't see why

I am relatively new to programming and am not looking to be particularly efficient with this algorithm regarding running time but only trying to replicate the Karatsuba algorithm and make it work. I ...
1
vote
3answers
39 views

Number of arrangements with no consecutive letter the same

This question is related to my question here. I am trying to get the following count programmatically to verify whether my mathematics is right. How many arrangements of the letters in the word ...
0
votes
1answer
27 views

Does 'Divide and conquer' yield O(log N) for unsorted array?

Following algorithm finds max QAZ. QAZ of an element is number of elements with higher value after that element's index. The popular answer is to use divide and solve using O(nLog(n)).. The array is ...
0
votes
1answer
6 views

Finding the Maximum Cut of undirected graph using Stoer-Wagner algorithm

Can I use Stoer-Wagner algorithm to find the max cut? Say, I negate all weights of the edges and find the minimum cut of this graph using Stoer-Wagner algorithm, is the result cut a max cut of the ...
0
votes
1answer
27 views

Form M groups having buildings of equal height from N buildings

I have been given N buildings with their height. I have to form groups of size M having equal height buildings. Given, I can destroy buildings of greater height to make their height equal to the ...
-1
votes
0answers
28 views

Solving TSP in Python [on hold]

I am trying to solve tsp and I get: import math import itertools def length(x,y): return math.sqrt((x[0] - y[0])**2 + (x[1] - y[1])**2) def solve_tsp_dynamic(points): #calc all lengths ...
0
votes
1answer
65 views

A star algorithm finding shortest path but not computing it correctly

Using the following A star visualization as a way to compare path accuracy, I found a large variation between my implementation and this one. https://qiao.github.io/PathFinding.js/visual/ Path I'm ...
0
votes
1answer
17 views

For a graph, given that a vertex has a loop, why is the degree of that vertex taken as 2 instead of 1?

I was reading a book called "Discrete Mathematics and Its Applications" by Kenneth H. Rosen. In the book, the degree of a vertex of an undirected graph is defined as follows: "The degree of a vertex ...
0
votes
0answers
10 views

The Scalable Hyperlink Store(From Microsoft research)

This paper describes the Scalable Hyperlink Store, a distributed in-memory “database” for storing large portions of the web graph. SHS is an enabler for research on structural properties of the web ...
-1
votes
1answer
24 views

Is there a fast implementation of finding bounding boxes according to pixel values?

In my implementation, I am producing an activation map which is a map with the same size as my image and its values will help me understand where are the objects of the image for localization. For ...
0
votes
1answer
35 views

Python Secret Santa Program - How To Achieve Higher Success Rate

I decided to make a Python program that generates Secret Santa pairings based on hardcoded restrictions (ex. someone can't get his wife). My family members have busy schedules so it's hard to organize ...
-4
votes
0answers
25 views

Need suggestions to find the fastest approach [on hold]

I have a process which take around 1 day to finish. It does the following things: 1. get a list of ids. 2. for every id a. extract from db b. process data extracted in the last step c. ...
0
votes
3answers
26 views

What is the time complexity of searching in a binary search tree if the tree is balanced?

The given answer is O(nlog(n)) but I also look it up on Wikipedia and it says it is log(n). Which one is correct? Also what is the worst case complexity for search an unbalanced binary tree?
0
votes
1answer
59 views

Running time of sorting algorithm

I have written a function to sort time stamps (hh:mm:ss) in order from oldest to newest. I am interested in knowing the approximate worst case running time of my code but i don't know how to determine ...
0
votes
3answers
32 views

N-Rooks Number of Solutions Backtracking

These methods are supposed to give the count of arrangements that any number of rooks could have on a board in non-attacking arrangement. I know I must be missing something silly here. Help me out. ...
3
votes
3answers
70 views

Lowest n Numbers in an Array

How can I assemble a set of the lowest or greatest numbers in an array? For instance, if I wanted to find the lowest 10 numbers in an array of size 1000. I'm working in C but I don't need a language ...
-2
votes
1answer
50 views

Search all ocurrences of string in array

Let's say I have a string array A of size n, and A is lexicographically sorted, for example: 0: abcaoeir 1: acda 2: acdttt 3: acdy 4: degaeiour 5: utsss given a string S of size m, how can I find ...
1
vote
2answers
45 views

How do I compare the similarity of person names using a metric? [on hold]

I am particularly working on a function to allow the misspelled and aliases of person names. I have done some research & found there are quite a number of algorithms for String metric and ...
-9
votes
0answers
34 views

observed pin python algorithm

looking for full code python solution that works, don't give me an idea of how it works, my friend already did that, except he is a c# expert not familiar with python, i prefer the full solution code ...
-1
votes
0answers
24 views

the first Java for loop ignored! I don't really understand why? [duplicate]

My code is as below: /** Caesar Cipher Cracker * Tony */ import java.util.*; public class Solution66 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int ...
0
votes
1answer
34 views

Counting with recursion in binary trees confuse me

I am trying to learn as much as i can about tree's and their algorithm's. And it seems like i can't really learn how recursion works when i want to count something in binary tree. For example if i ...
0
votes
0answers
41 views

What happens to the Merge-Sort algorithm when med is changed from (ini + end) /2 to ini + (end-ini)/4?

Concerning the following form of the Merge-Sort algorithm: public static void merge(int [] a, int ini, int med, int end){ int [] b = new int[end - ini + 1]; int i = ini; int j = med +...
0
votes
0answers
14 views

Matlab Perceptron algorithm with linear classifier

I am trying to make a single layer linear classifier program but with some addons and a loop! 1) User must have the ability to import data from a file like i.e. x = [x0, x1, x2, ..., xn] T and the ...
-3
votes
1answer
56 views

How to get out of the if statement and back to the top of the while

I have this looping structure where I am trying to parse a file. I want to jump from one if statement to the top of the while loop. However when I use continue what I want to happen does not. When I ...
2
votes
1answer
26 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 ...
0
votes
2answers
51 views

How do I count the number of occurrences of a char in a Multiple String?

My question is so special , giving those Strings 123456 String1 ABCD String2 BDD String3 CDEF As we can see the number of A in column 1 is 1. the number of B in column 2 is ...
1
vote
1answer
33 views

How is Swift Array.sort() sorting integers faster than tuples if it uses IntroSort algorithm? Is Swift sorting integers differently?

I have been picking and probing at Swift Array's sort function and I was surprised to find that in-place sorting an array of 500,000 integers was remarkably faster than sorting an array of 500,000 ...
-1
votes
3answers
20 views

Digit swap wrong examples

swap digit problem This problem is screwing with my mind because of the examples. If I have: 38276 Then the next biggest is 87632 But the problem points it out as the next biggest being 38627 ...
1
vote
1answer
30 views

Miller Rabin primality test two types?

I encountered two types of Miller Rabin primality test methods suddenly. One which uses randoms and another does not use randoms. Is there a hidden random generation inside the second one or what? ...
-3
votes
1answer
32 views

What is this matrix in php? And what does it do? [on hold]

I came across this encryption algorithm, and I grabbed the algorithm it uses which looks like to be an matrix, but I do not know what it does or how to use it? Help! <?php $array = [ 2 => ...
0
votes
0answers
90 views

Which is the best data structure for searching under these conditions

I have a system with some factors, say A, B, C, and D. There can be different values of all these factors. Let us consider few values to have a better understanding. Let's say A has 4 different ...
0
votes
1answer
37 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 ...