Questions tagged [algorithm]

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.

algorithm
23,732 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
15 votes
1 answer
2k views

Computing a move score in a Minimax Tree of a certain depth

I've implemented a Chess game in C, with the following structs: move - which represents a move from (a,b) to (c,d) on a char board[8][8] (Chess board) moves - which is a linked list of moves with ...
Evgeny's user avatar
  • 417
12 votes
1 answer
428 views

Algorithm itemset matching pattern

I've a set of elements (potentially big) with an order relation: [a,b,c,d,e,f] and a set of frequent patterns (potentially big) with ids: [a]:1,[b]:2,[c]:3,[a,b]:4,[b,c]:5,[a,b,c]:6 I have a ...
Alex's user avatar
  • 351
12 votes
5 answers
2k views

Check if there exist a path between two vertices in directed acyclic graph - queries

This question can be easily solved in O(n + m) per query, however is this possible to answer such queries in better complexity with preprocessing better than O(n²) ? In tree it can be easily done by ...
Badf's user avatar
  • 335
12 votes
1 answer
9k views

Abstract syntax tree using the shunting yard algorithm

I have an infix expression that I have tokenised and would like to proceed to create an abstract syntax tree. I understand the shunting-yard algorithm used in these cases. I have only found ways to ...
user27114's user avatar
  • 129
11 votes
0 answers
266 views

Is the libc++ implementation of the STL deque push_front function standards-compliant?

The C++ Standard (N4901) says this with reference to the deque push_front function: An implementation shall provide these operations for all container types shown in the “container” column, and shall ...
1f604's user avatar
  • 275
11 votes
0 answers
2k views

GUI layout algorithms overview

I'm looking for systematic review of the algorithms used for GUI layout. I'm particularly interested in the algorithms that favor speed over complexity, but it's hard to find anything useful other ...
Anton's user avatar
  • 281
11 votes
1 answer
5k views

DIvisive ANAlysis (DIANA) Hierarchical Clustering

(This post is continuation of my previous question on divisive hierarchical clustering algorithm.) The problem is how to implement this algorithm in Python (or any other language). Algorithm ...
Andrej's user avatar
  • 3,799
11 votes
1 answer
421 views

Average case algorithm analysis using Kolmogorov Incompressibility Method

The Incompressibility Method is said to simplify the analysis of algorithms for the average case. From what I understand, this is because there is no need to compute all of the possible combinations ...
user3813812's user avatar
11 votes
2 answers
944 views

How are fluid simulations integrated into Rigid Body physics engines?

Is there any proof that simulations that mix Rigid Body physics and fluids (say SPH) can provide modeling for real world? How does a frame of such mix work? Say we have a wooden swing inside a box ...
DuckQueen's user avatar
  • 852
11 votes
1 answer
1k views

My implementation of the evaluation function and Alpha-beta pruning for Connect Four is not smart enough

I am trying to implement correctly the Connect Four game AI yet not to avail my AI acts stupid: It does not block the opposite player pattern which can lead to failure of the AI, It does not take ...
coderodde's user avatar
  • 1,413
10 votes
0 answers
345 views

Why does C++11 require std::sort to have WCET O(n log n)?

Since C++11, the C++ Standard Library (c.f. Section 25.4.1.1 of a draft verion of the standard) requires the std::sort algorithm to have asymptotic worst case execution time O(n log n) instead of ...
Max Haslbeck's user avatar
10 votes
3 answers
1k views

Minimum add to make parentheses string consisting of '{', '}', '[', ']', '(', ')' valid

This problem is an addition to the familiar stack question(https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/) where we have to return the minimum number of additions to make the ...
John Mathews's user avatar
10 votes
0 answers
2k views

Can I guess the appropriate epsilon for RDP (Ramer-Douglas-Peucker)?

I have sets of time series data which I display as charts in mobile applications. To make the charts clearer, I simplify the sets by applying Ramer-Douglas-Peucker. If I apply RDP to a small set ...
noamt's user avatar
  • 7,585
10 votes
2 answers
154 views

Strategy for translating a UX `pan` gesture to set a linear value without an upper bound

I'm trying to set a slider (actually a kitchen timer) using a pan gesture in ionic2 see: http://ionicframework.com/docs/v2/components/#gestures The slider/timer has an open upper-bound that could be ...
michael's user avatar
  • 4,437
10 votes
3 answers
12k views

Parenthesizing a string so that expression takes a given value

The following problem is from the chapter on Dynamic Programming by Vazirani et. al. [6.6]Let us define a multiplication operation(×) on three symbols a; b; c according to the following table: ...
curryage's user avatar
  • 481
9 votes
0 answers
337 views

Multiset domination algorithm

Let us say that a multiset M dominates another multiset N if each element in N occurs at least as many times in M. Given a target multiset M and an integer k>0, I'd like to find a list, L, of size-k ...
dshin's user avatar
  • 2,334
9 votes
2 answers
429 views

Autogram Algorithms

An autogram is a sentence which describes its letters. For example, from Wikipedia: This sentence employs two a’s, two c’s, two d’s, twenty-eight e’s, five f’s, three g’s, eight h’s, eleven i’s, ...
user avatar
9 votes
4 answers
1k views

How to determine whether removing a given cycle will disconnect a graph

I have seen ways to detect a cycle in a graph, but I still have not managed to find a way to detect a "bridge-like" cycle. So let's say we have found a cycle in a connected (and undirected) graph. How ...
Wayne's user avatar
  • 91
9 votes
1 answer
2k views

Algorithm for offsetting edges of 3D triangle mesh

I have a 3D triangle mesh, and I'm looking for an algorithm to offset all the un-bordered edges border edges of the mesh inwards, along the surface of the triangle mesh. I've looked at Clipper as ...
Jeff's user avatar
  • 556
9 votes
2 answers
365 views

Is there an implementation of the idea described in "Detecting NearDuplicates for Web Crawling"

The paper: http://www2007.org/papers/paper215.pdf I am just wondering are there any implementations of chapter 3 of that paper. I mean querying among large datasets, NOT only the simhash (it's easy ...
Mickey Shine's user avatar
  • 12.3k
8 votes
1 answer
4k views

2D Bin Packing Algorithm

I have spent some time researching 2d bin packing algorithm. I have no extensive experience in algorithm especially in advanced math but I can code :) The perfect example of what I need to achieve is ...
Colin's user avatar
  • 174
8 votes
0 answers
194 views

which design considerations justify std::make_heap() to be apparently sub-optimal?

According to cppreference (and the requirement in the C++ standard) std::make_heap() takes at most 3n comparisons, but according to Wikipedia no more than 2n comparisons are actually needed. What are ...
Walter's user avatar
  • 44.8k
8 votes
1 answer
402 views

Proposing an algorithm for arbitrary shape Bit Matrix Transposition with BDD-like structure

We consider a bit matrix (n x m) to be a regular array containing n lines of integers of size m. I have looked in Hacker's Delight and in other sources and the algorithms I found for this were rather ...
ZakC's user avatar
  • 479
8 votes
0 answers
3k views

Python implementation of Multiple-Choice Knapsack

I have been searching for python implementation of multiple choice knapsack problem. So far I have found a java implementation in github: https://github.com/tmarinkovic/multiple-choice-knapsack-...
t0m9er's user avatar
  • 143
8 votes
1 answer
947 views

How to find cycles of a given length in a directed graph? (Using networkx)

I'm trying to find cycles of length 2, 3, 4, and 5 in a directed graph. So far I've had decent luck on most inputs using the simple_cycles algorithm from networkx (https://networkx.readthedocs.io/en/...
user3413468's user avatar
8 votes
1 answer
2k views

Active Shape Models: matching model points to target points

I have a question regarding Active Shape Models. I am using the paper of T. Coots (which can be found here.) I have done all of the initial steps (Procrustes Analysis to calculate mean shape, PCA to ...
Ad Fundum's user avatar
  • 665
8 votes
3 answers
539 views

Algorithm : Letters and envelopes pairing

Disclaimer : This isn't any kind of homework, the problem just came to my mind while I was going through all the Christmas cards The problem is given as follows : We've got M envelopes and N letters, ...
Danstahr's user avatar
  • 4,219
8 votes
1 answer
2k views

How do I balance a BK-Tree and is it necessary?

I am looking into using an Edit Distance algorithm to implement a fuzzy search in a name database. I've found a data structure that will supposedly help speed this up through a divide and conquer ...
Merlyn Morgan-Graham's user avatar
8 votes
3 answers
8k views

Count number of cycles in directed graph using DFS

I want to count total number of directed cycles available in a directed graph (Only count is required). You can assume graph is given as adjacency matrix. I know DFS but could not make a working ...
Sushil Verma's user avatar
7 votes
0 answers
254 views

Elegant algorithm to control max value for carousel

I have a slider which at most can show 3 elements. If there are more elements, these are hidden and can come into view by clicking left right as following image. This slider will be taking in a ...
karvai's user avatar
  • 2,561
7 votes
0 answers
243 views

Minimise the median of the distances from a string

The problem Lets consider you have a list of strings r, s, t, .... How could you determine the string u such as M = Med(d(r, u), d(s, u), d(t, u), ...) is minimised? d is a function which returns ...
user avatar
7 votes
1 answer
308 views

Optimal covering with non-uniform discs

What kind of algorithm can I use to search for an optimal (minimum area) covering of a limited region of the XY plane with n discs ( xj, yj, rj ) ? I've found many investigations on fixed radius discs,...
6502's user avatar
  • 113k
7 votes
2 answers
782 views

Find minimum number of triangles enclosing all points in the point cloud

Input You have a points list which represents a 2D point cloud. Output You have to generate a list of triangles (should be as less as possible triangles) so the following restrictions are ...
Mykola Kotsabiuk's user avatar
7 votes
2 answers
2k views

Directed Acyclic Graph with Hierarchical Layout

I am trying to programmatically build a family tree. I don't care what format the input data is in, as text is easy to parse (I'm an NLP researcher), but I'm having trouble figuring out how to build (...
inkalchemist1994's user avatar
7 votes
0 answers
212 views

Is there a more concise way to implement css' An+B micro-syntax as xpath predicates?

I'm creating a CSS selectors to xpath 1 converter and one detail I struggled the most with is finding a concise substitute for the An+B micro-syntax. Since I'm implementing it for xpath 1 and in such ...
Decent Dabbler's user avatar
7 votes
1 answer
256 views

Topologically sort DAG into batches

I'm looking for an algorithm to sort a DAG into batches of vertices, such that no vertices in a batch have an edge between them, and the batches are sorted in an order such that no vertex in a batch ...
shane's user avatar
  • 1,813
7 votes
1 answer
3k views

Surface Area Heuristic (SAH) kd-tree of triangles - flat cells

I've implemented a SAH kd-tree based upon the paper On building fast kd-Trees for Ray Tracing, and on doing that in O(N log N) by Wald and Havran. Note I haven't done their splicing and merging ...
PeteUK's user avatar
  • 1,082
7 votes
0 answers
2k views

Graph algorithm: simplify graph by replacing chains of nodes with single node

I'm looking for a directed weighted graph simplification algorithm that seeks chains of nodes which have exactly one inbound edge and exactly one outbound edge and are interconnected and replaces such ...
Emil Çiçek's user avatar
7 votes
2 answers
2k views

How to calculate distance between 2D matrices

Hello Community, I'm new (as a member) to the site, so if you think it might be better to post it on http://datascience.stackexchange.com, let me know. I am tackling a Machine Learning problem ...
Haris Michailidis's user avatar
7 votes
1 answer
1k views

SGM Disparity subpixel estimation - how to?

Some weeks ago I've implemented a simple block matching stereo algorithm but the results had been bad. So I've searched on the Internet to find better algorithms. There I found the semi global ...
rottaca's user avatar
  • 106
7 votes
1 answer
2k views

Parametric equation to place a leaflet marker on the circumference of a circle is not precise?

I am working on an application where I have the center of a circle and the radius and I am plotting the circle with the help of Leaflet. I placed a marker on the north most end of the circumference ...
Rohan's user avatar
  • 13.6k
7 votes
0 answers
3k views

iOS Swift Flood fill algorithm

I created this extension for "bucket fill" (flood fill) of touch point: extension UIImageView { func bucketFill(startPoint: CGPoint, newColor: UIColor) { var newRed, newGreen, newBlue, ...
Libor Zapletal's user avatar
7 votes
1 answer
886 views

Range Query the number of inversion in O(lg N)

Given an unsorted array of n integers, I know I can find the total number of inversions using BIT in O(N lg N)following this method: Count Inversion by BIT However is it possible if I have to query ...
shole's user avatar
  • 4,064
7 votes
1 answer
982 views

Symbol Directed Graph using data from text file

I'm so stuck, I would greatly appreciate some help. I'm currently learning Algorithms, but I have no idea where to start. I was given code recently (We have only really done theory so seeing the code ...
JvK92's user avatar
  • 135
7 votes
1 answer
2k views

Uniformly arranging points on a sphere using Fibonacci Lattices

I'm trying to arrange points more-or-less uniformly along the surface of a unit sphere. I'm told that while this problem is difficult, Fibonacci Lattices give a very good solution. I've been trying ...
Ozzah's user avatar
  • 10.7k
7 votes
5 answers
591 views

How can I find a way to minimum the number of edges?

I am thinking an algorithm to solve the problem below: A given graph composed of vertices and edges. There are N customers who want to travel from a vertex to another vertex. And each customer ...
Yun-Lung Lee's user avatar
7 votes
1 answer
580 views

How to find the best (most informative) plotting limits?

I am developing a 2D plotting program for functions of 1 variable. It is designed to be very simple so that the user should not have to select the initial plot limits (or "range"). Are there known ...
fffred's user avatar
  • 616
7 votes
1 answer
287 views

Counting unvisited nodes at distance n for every node in graph

For each point in a large graph I am trying to create a list that contains the number of unvisited nodes at distance n from the starting node. An example output is: [1,3,6] which means that at ...
Ben Ruijl's user avatar
  • 5,083
7 votes
5 answers
4k views

How to find if a 3D object fits in another 3D object (the container)?

Given two 3d objects, how can I find if one fits inside the second (and find the location of the object in the container). The object should be translated and rotated to fit the container - but not ...
Ophir Yoktan's user avatar
  • 8,299
7 votes
2 answers
2k views

Efficient algorithm for removing loops from polylines

I have a polyline, given as an ordered set of (X,Y) coordinates, that may cross over itself to form one or more loops. From this, I want to extract a polygon that has the loops removed, which will ...
SmacL's user avatar
  • 22.7k

1
2 3 4 5
475