In mathematics and computer science, an algorithm is an effective method expressed as a finite list of well-defined instructions for calculating a function. Algorithms are used for calculation, data processing, and automated reasoning.

learn more… | top users | synonyms (1)

-1
votes
0answers
8 views

Segment sieve of Eratosthenes code

I got this code to print prime number between m and n and while doing its dry run ,i observed that even if prime is not set to be 1 for composite 4 it gives same result int main(int argc, char** ...
1
vote
2answers
105 views

Shuffle/Randomize a collection without knowing the knowing the number of items?

Let's say I have a sequence of items of unknown length, n. I want to randomize the order of this sequence without having to go through the entire sequence. Are there any algorithms that can do this? ...
1
vote
0answers
54 views

Search algorithm on sequential data model

For sequential data models like LinkedList, search algorithms like linear-search and binary-search are well known. Are their any other search algorithms apart from these two, that work on sequential ...
0
votes
0answers
63 views

inserting into priority queue. MIT c programming opencourseware [migrated]

Iam currently trying an exercise from the "practical programming in C" from MIT opencourseware. the exercise is on huffman coding. it is lab2 part 2 where Iam having an Issue. Primarily the ...
2
votes
1answer
154 views

Is there a better algorithm to distribute integer to X integers minimizing their difference?

Is there a better algorithm to distribute values from one source to X destinations minimizing their difference? I have some source integer. I need to know how much of that value I need to distribute ...
0
votes
1answer
112 views

How can I learn algorithms? [on hold]

I just took a coding challenge on a popular coding challenge site which gives you a problem and a fixed amount of time to solve it. I've been writing software for around 10 years, good software for ...
-1
votes
1answer
62 views

Intersection of two arrays [on hold]

While solving problem abcdef on spoj i came across this code for intersection of two sorted arrays Here is the link to problem http://www.spoj.com/problems/ABCDEF/ The code sort(s1.begin(), ...
0
votes
0answers
23 views

What is prerequisite for Algorithm and Data Structure Analysis and Designing [on hold]

I want to learn Programming, So I want to start this learning program with studying of the Introduction to algorithms book. I'm familiar with C, C++ and ASM Language a little bit, but I can't write ...
2
votes
2answers
84 views

Incorporating functions into a Shunting-Yard algorithm implementation

tl;dr What would be a simple way of incorporating functions into a Shunting-Yard algorithm implementation? If only expressions like function(arg1, arg2, arg3) were allowed (where function is some ...
-3
votes
0answers
100 views

Can My Algorithm be Patented [closed]

I developed an algorithm that runs about 1000 times faster than the standard version found in other platforms. I did this while I was doing some work for my company. Is this algorithm patentable? If ...
17
votes
5answers
526 views

Algorithm for calculating a bullet path to a target with max. 2 ricochets

Sorry for the poor title but I didn't have a better way to phrase it... So there's this amazing game by Nintendo (yes!) on Wii called WiiPlay. There're 9 minigames in it, and my favorite one is ...
0
votes
0answers
25 views

Why do drawing applications use handles to connect lines to shapes? [migrated]

Most drawing programs that I know of (eg. Visio) give shapes handles in order to connect two shapes with a line. These handles allow lines to be "locked on" to the shape so if you move the shape, the ...
2
votes
2answers
95 views

Algorithm to go from infix notation to a tree

I've been trying to figure out an algorithm to go from an infix equation to a syntax tree, like so: (1+3)*4+5 + * 5 + 4 1 3 However, I don't just want it to handle operators, I ...
-4
votes
0answers
22 views

My code compiles, executes, but crashes for certain inputs [migrated]

I am trying to get the length of longest common subsequence for two strings. It works for most of the inputs but it crashes for the input specified. The code is as follows: #include <cmath> ...
0
votes
0answers
50 views

Calculating audio delay to eliminate echo in VoIP

In this issue, the microphone at point A records audio, compresses it, and sends it to the server at point B somewhere "in the cloud." The point B server then figures out what rooms the recorded ...
9
votes
3answers
2k views

My algorithm that extracts the largest box that can be made from smaller boxes, is too slow

Imagine a cube based world (such as Minecraft, Trove, or Cube World) where everything is made up of identically sized cubes and all the cubes are of the same kind. The goal is to represent the world ...
0
votes
1answer
93 views

Bad idea to use the same test cases for multiple parts of a contiguous algorithm?

I'm working on an algorithm that's split up into multiple parts, each of which performs different tasks but is more or less separate from the others, by which I mean the only interaction between the ...
1
vote
2answers
79 views

Multi-pattern matching

I have a given byte array in C and I need to match it against several byte arrays and return true if there is any match. I can make various memcmp's but I feel that it is very inefficient. Do you ...
1
vote
1answer
151 views

Is the time complexity of a while loop with three pointers different than 3 nested for loops?

This program (written in ruby) finds the largest 3 numbers in an array (without sorting the array). It has a while loop with three pointers. My fist instinct, since there is only one loop is to say ...
-1
votes
2answers
179 views

How they design this algorithm? [closed]

I started taking the lessons from Codility. In the PDF about time complexity, at the end, the put an simple example: Problem: You are given an integer n. Count the total of 1 + 2 + . . . + n. The ...
19
votes
4answers
3k views

When speaking, how can I say that the time complexity order of an algorithm is O(N log N)?

What term can I use to describe something with O(N log N) complexity? For example: O(1): Constant O(log N): Logarithmic O(N): Linear O(N log N): ?????? O(N2): Quadratic O(N3): Cubic
2
votes
1answer
63 views

Precedence of function in Shunting-yard algorithm

I am working through the Shunting-yard algorithm, as described by wikipedia. The description of the algorithm when dealing with operators is as follows: If the token is an operator, o1, then: ...
1
vote
0answers
46 views

clustering of strings with variable-length prefixes

I've got bunch of strings with variable-length prefixes (or postfixes - I can always revert them) as follows: 0155555555 523455555555 755555555 ... 87129999999999999 119999999999999 09119999999999999 ...
2
votes
1answer
53 views

Looking for an Appropriate Search Algorithm

I am currently planning an upcoming project and am looking for an algorithm for searching a database. The search is as follows; There will be some specifically labelled criteria (or fields) and I ...
1
vote
1answer
88 views

How to generate Generate Hash incorporating time stamp so it can be unhashed to get the timestamp when it was generated?

I want to create hash based on random id, That hash has to be valid for only 15 minutes. Is there a way to do that? I'm using this for form submission. If some unknown submitted form or some one ...
3
votes
1answer
120 views

Finding the optimal root

I am trying to solve a quora hackathon challenge question. The question descrpition is as follows : For the purposes of this problem, suppose Quora has N questions, and question i (1≤i≤N) takes ...
1
vote
0answers
206 views
+100

Fast fixed-size (256 bit) integer modulo/division

What is the fastest way to divide two 256-bit integers? They are represented as an array of 26-bit words, each stored in 32-bit integers. I have access to a 64-bit type if that's useful. It seems ...
1
vote
1answer
66 views

Why use a unique hashkey for form submissions?

I have multiple forms and use AJAX to submit them. I asked my boss if he needed any specific format for the form ID and he told me to generate a unique hash and keep it in session; check it whenever ...
-3
votes
2answers
69 views

Integer Map Algorithm

For my project, I need to map integers so that inputting int X will output int Y where both X and Y are defined during runtime. I've used Dictionary<int,int> in .NET but its memory use is too ...
0
votes
1answer
115 views

How to sort fractions (small numbers)

We have 100 000 fractions: Let's consider following fractions. p/(2^q) such that 0 <= p,q <= 10 As you can see there are <= 10 * 10 different fractions, but we have 100 000 that we have to ...
1
vote
1answer
91 views

Algorithm to cut out and straighten rectangles from image

I am looking to write an algorithm to cut rectangular images and straighten them in a new image. The bigger concept is that I will be scanning a bunch of physical pictures (on a physical scanner). ...
0
votes
2answers
80 views

AABB collision algorithm with a condition

So I'm doing a 3D implementation of collision detection. Considering Boxes are oriented on the axis. They are rotatable but has to be orientated on the axis. Box A and Box B cannot go through each ...
2
votes
1answer
73 views

Seeds distribution algorithm with complexity better than O(n^3)?

I have included my approach and solution. My solution works fine, however, is unoptimized with O(n^3) complexity An NGO is running seed distribution program. It has limited quantity of varied quality ...
2
votes
2answers
117 views

Algorithm to solve this “treefarm” puzzle

How would I go about writing a program to solve this kind of puzzle: The green squares represent trees, and you have to plant them in such a way, so that: Trees do not touch each other at all (not ...
3
votes
2answers
167 views

Obstacle bypass in 2d environment

For this 2d grid (black square are not penetrable, white square are): I want to find path who permit to move an object to a start point (x:18, y:18) to a end point (x:1, y:1), square by square. ...
3
votes
2answers
83 views

Work out which parcel deliveries we ship ourselves and which we outsource

Firstly, I hope I'm asking this in the right place. I work for a large online retailer in UK. We ship approaching 2000 orders each day and are growing very quickly. We currently use multiple delivery ...
6
votes
5answers
193 views

Hamming Distance using a dictionary

First time poster. I'm currently programming a hamming distance program using a dictionary. So if we start with the word "cat" and we want to transform it into "dog", the sequence is ...
0
votes
0answers
34 views

Final array after M updates on Segment Tree

I am stuck in a middle of a problem. I have made segment Tree of N elements and performed M updates through lazy propagation Now I need to store the final array (to some array B of size N) after all ...
1
vote
1answer
116 views

What does it mean for an algorithm to converge?

I keep coming across this term when reading about reinforcement learning, for example in this sentence: If the problem is modelled with care, some Reinforcement Learning algorithms can converge to ...
2
votes
1answer
39 views

Which algorithm to find the shortest (nodes count) path that encompasses all polygons inside a larger polygon?

Inside a large polygon (say the USA boundaries) I need to find the shortest path that will encompass smaller polygons (say the following cities: Kansas city, St Louis, Memphis, Oklahoma City) By ...
4
votes
1answer
97 views

Improve bisection method or alternate algorithm for efficient determination of text font size to fit in a box

I need to find the font size of a text that fits in a box. Given my current font size, I can get the bounding rectangle of the text. If I set some arbitrary min and max font size, I suppose I can ...
1
vote
0answers
97 views

Software Design, Generic Programming, Physical Devices, and Algorithms in C++ [closed]

I often have data that in some contexts I want to handle uniformly, but in other contexts I wish to differentiate it. For example, I could have a vector that is series of angles or a series of ...
0
votes
0answers
36 views

Approaches to combinatorial optimization problem

Problem I have the following combinatorial optimization problem: A set of applications need to be distributed among a set of nodes. Each node has a capacity and each application has a required ...
1
vote
1answer
93 views

Evaluation function for games [closed]

I have been trying to write a bot for quarto game. As usual I tried to solve it with Min-Max and alpha-beta pruning. But I am stuck at finding a proper method to evaluate non-final states. As you can ...
0
votes
0answers
52 views

Simple Path to Route Algorithm

I'm currently conducting research into subway paths, but stand in front of a problem, with no programming knowledge and an extremely short time-limit. Probably the question I am asking is trivial, ...
2
votes
2answers
160 views

Algorithm and data structure to match groups of users (1-5 each) into 2 balanced sets of 5 users

I'm building a matchmaking queueing service for a 5v5 team-based game. I have a large set of users that are grouped into unique lobbies comprised of 1-5 users each. Each user has an integer based ...
4
votes
1answer
179 views

Minimizing compression overhead in a simple compression algorithm

Note: this question has been re-written to simplify and generalize the problem. The original is available below. Suppose I created a simple compression scheme for lists of 2-digit numbers. It has 2 ...
3
votes
2answers
58 views

(Partially) Sorting a lazy-evaluated collection

So I'm trying to implement a lazy-evaluating data type (in PHP, though that shouldn't matter any) where you can queue up actions to take on a set of data. This data can come (theoretically) from any ...
0
votes
1answer
92 views

Is external merge sort a divide-and-conquer algorithm? [closed]

Today I was corrected for mentioning "External Merge Sort" as an example of a divide-and-conquer (D&C) algorithm and after doing a lot of research online and in the most prominent books on ...
1
vote
0answers
62 views

Efficient extensions of degree of separation

I'm trying to play around with the 6 degrees of separation problem, specifically the Kevin Bacon game to find alternative ways of playing the game. I want to eventually port it over to MapReduce, but ...