# Tagged Questions

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.

56 views

### Pre-computation strategies when solving multiple linear equations with the same matrix?

Often in modeling, data processing, and optimization; the intensive portions of the code can often reduce to solving a lot of linear equations. e.g. solve for x1 in A x1 = b1 solve for x2 in A x2 =...
89 views

### Planning dinner seating, having each person sit with as many other people as possible, changing tables between each course

My project is as follows: I am making a program for planning dinner seating that will take a number of courses, a number of tables, and a list of people. The goal is to have each person sit with as ...
95 views

### What Graph Theory approaches or algorithms are useful for designing a House?

I have a set of data about a family, and I want the software to find a house design that fits the data (which includes stuff like preferences and whether they want a pool. The current way I am going ...
88 views

### Brute force improvement over generating permutations?

I am trying to improve a brute force algorithm for letters of the English alphabet [a-z][A-Z] and numbers [0-9]. The length of the generated permutations should be 8. So far, I've built a simple brute ...
151 views

### Finding longest subsequence with sum less than or equal to a fixed number

I was trying to solve Problem 279-B. Given an natural number, t, and an array, a[0],...,a[n-1], of natural numbers, find the maximum length of a continuous subarray, a[i],...,a[j] in a where a[i]+....
50 views

### One producer and one consumer vs inconsistent shared resource state

I was reading about implementation of producer-consumer problem with one producer and one consumer. Looking at this paragraph I see the implementation where shared resource access is not synchronized ...
55 views

### finding optimal token definitions for compression

I have a collection of strings which have a lot of common substrings, and I'm trying to find a good way to define tokens to compress them. For instance, if my strings are: s1 = "String" s2 = "Bool" ...
145 views

### Generating sort keys when reordering items

We have a number of items which the end user will be able to organize into a desired order. The set of items is unordered, but each item contains a sort key which can be modified. We're looking for ...
85 views

### Fast straight-line-integrals over a discrete grid

I have a grid that represents a sampling of a continuous function in a 2 dimensional space. I'm looking for a (preferably fast) algorithm that can calculate the discrete line integral along a straight-...
35 views

### Algorithms for Distribution and Logistics problem

I am looking for a way to express the following logistics/distribution problem as an equation that could be solved with a solver (optimization). Or if there is an known algorithm that would most fit ...
197 views

### How to implement backtracking to check if all fields have been traversed

I have been learning algorithms and trying to solve problems and now I have the following problem: In a 4x4 matrix, and it contains fields with height. There is a start field with given height also ...
109 views

### Understanding recursive solution of some algorithm

Most of the time we need to understand someone else' code for example I am studying Graph Algorithms from Sedgewick's online resources, the particular code example is taken from cycle detection ...
52 views

### Generate a string generator (constant associative array)

There is a finite set of unique strings and a limited key space. One key corresponds to one string value and a function must exist to perform the resolution. There is no need to support other ...
46 views

### Most efficient way of allocating participants to conference tracks

I am redesigning a system by which conference participants can choose which track they want to attend. Participants express their track preferences arranging them in order and submitting them at a ...
62 views

### How to traverse “linked list” like structure with parallel nodes

I am working on a signal processing project that allows for parallel processing on data streams as well as inputs and outputs to and from multiple endpoints. The signal chain is broken down into "...
49 views

### Finding longest ambiguous words with a given set of letters

I have been playing hangman with my friend over an app for a while now, and we have a gentlemen's understanding between us that we are both "cheating" by using online software both to solve the given ...
78 views

### Trying to find time complexity of modulus algorithm

I can't quite figure out the time complexity of this algorithm I've written for finding the modulo. I've added it here in psuedocode. Modulo(int x, int n) // x is the dividend, n is the divisor e ...
35 views

### Listing search/query results from 30+ web services efficiently and orderly

We have a system that currently has approx 25 customers (will never expand from this) that each have a public facing web service which allows each other to query each others internal application ...
48 views

### Algorithm for matrix positioning

Lets say I have an original mxn matrix like this: 1 2 3 4 5 6 7 8 For the purpose of my program, I then concatenate the rows into this new one dimensional matrix: 1 2 3 4 5 6 7 8 I know the mxn ...
164 views

### How to calculate business days difference without a lookup table

How can I calculate the number of buisness days (M-F, agnostic of Holidays) between two dates without a look up table? There has to be some sort of algorithm based on the number of all days and the ...
67 views

### Conditionally show questions based on previous answers in a database driven survey

I'm trying to design survey-type application that uses user responses to determine what the next question should be. For simplicity's sake, question types can be either combo boxes (they have a set ...
260 views

### Swapping variable values without creating a new one

Recently, I was faced with a question that asked me to swap variable values without creating an extra variable. i.e. A = 10, B = 20. How store 20 to A and 10 to B? The solution is: A = A + B #...
87 views

### Optimizing the exponential smoothing of a big array

I have a large set of values (let's say 1M entries) where I need to apply an exponential smoothing algorithm, but only incrementing one value at a time (all others decay to zero). The trivial ...
55 views

### The maximum number of induced cycle in a simple directed graph

Given a simple directed graph G=(V,E) an induced cycle is a cycle where no two vertices of the cycle have an edge that is not in the cycle. (Chordless cycles are induced cycles with at lease 4 ...
42 views

### Dynamic programming vs branch-and-bound for the knapsack problem

I have to implement a program that solves the 0-1 knapsack problem, where the weights and values of all items are nonnegative integers. We went over two methods in class: dynamic algorithms (...
170 views

### What does Rob Pike mean by fancy algorithms?

In "Rob Pike's 5 Rules of Programming", he states, "Fancy algorithms are slow when n is small, and n is usually small. Fancy algorithms have big constants. " and as the next rule he states that "Fancy ...
2k views

### Pattern for algorithm that outputs an explanation of how it gets to a solution when needed

The following scenario happened to me several times. I programmed a algorithm that solves a certain problem. It works fine and finds the correct solutions. Now, I want to have an option to tell the ...
87 views

### Finding unique tuples list of options

I'm having a bit of hard time finding a solution to the following problem. I need to find tuples of (a-c, 0-2) such that if I make a choice with one letter and a key I can't select it again. Example: ...
56 views

### Find best layout to reduce use of space or material

Example case: You have a truck, that can hold 2.8m by 3.2m by 16m of storage capacity. You you get a bunch of physical objects you want to store in that truck. These objects are not always cubic, but ...
194 views

### Is “a general process for solving a category of problems” the right definition of an algorithm?

I am reading Think Python: How to Think Like a Computer Scientist, the author says that an algorithm is: A general process for solving a category of problems. But I don't know if that a right ...
214 views

### Are there multiple Hamiltonian Paths on a Graph?

Can anyone suggest an algorithm for this problem. Given an undirected unweighted cyclic graph, and a given start and end node in that graph, I'd like to determine if there is exactly one valid path ...
147 views

### How to create an algorithm for a raffle, where each raffle guarantees a winning ticket?

I am looking for an algorithm to create a raffle, where each participant is assigned a ticket with a random series of numbers. Each raffle hast N participants, and there should exist same amount of ...
61 views

### Resource Allocation Algorithm

I have a question about assigning values to nodes laid out in a physical space: There is a set of N fixed nodes spread out throughout a certain 2 dimensional region that need to be assigned a value ...
169 views

### Poker split / side pots

I am writing a poker application and trying to figure out how to deal with split pots and side pots There are four rounds of betting and each round of betting can have multiple orbits Can only ...
63 views

### Alert when size of continuous stream of events exceeds 1000

A friend of mine was recently asked this question in an interview. Lets say there is a continuous stream of incoming events E1, E2 each with timestamp of entry associated with them. Write a java ...
52 views

### Creating hyperlinks in documents and messages

In Sweden the abbreviation "t.ex." means "for example" ("till exempel") and it is extremely common. Every time I write that t.ex. in an email or in a text message it gets marked up as a clickable ...
185 views

### Getting started with machine learning a zero sum game?

I have a simple zero sum, discrete, deterministic, complete information board game. I want to machine learn an evaluation function for an AI agent. Suppose each board state has ~20 identifiable ...
188 views

### a funky interleaved sorting problem

I have an array of items. Some items have a number on both sides. I'll call these "matched pairs". I need to sort the items between the matched pairs in a particular way. There's a "from number" ...
79 views

### How to improve timeout value dynamically?

I'm working on an application where I want to keep a timeout value computed dynamically using a moving average of say 100 previous response times for service A. This value + some buffer (~3 seconds) ...
55 views

### Efficient Value-Lookup in List of k-Tuples

I've encountered a problem in a personal project that I think could be solved by a particular data structure but I'm not sure what. The problem is as follows: Given a set of k-tuples, provide an ...
84 views

### Yen's k shortest paths algorithm

I'm currently trying to understand Yen's k shortest paths algorithm. I based myself on the original paper as well as on the Wikipedia article, but still cannot see why it is correct if k > 2. In fact, ...
157 views

### What algorithm would have the fastest average run time and least memory requirements for sorting a deck of playing cards?

Considering a deck of N playing cards with X different rankings and Y different suits (i.e. there are Y cards with X ranking, thus N=X*Y). What is the fastest algorithm to sort them assuming that X, Y,...
211 views

### Binary Search Tree without Natural Ordering

This is kind of a multi-part question. Is it possible to do a binary search tree if the data does not possess natural ordering? Would you be forced to impose artificial ordering to such data? Like ...
272 views

### My brute force solution is too slow, needed DP solution [closed]

Concise problem definition: given n and {a,b,c}; (1 ≤ n, a, b, c ≤ 4000); Constraint -> a*i + b*j + c*k==n (i,j,k>=0); Objective-> maximize(i,j,k) Examples: n=47 and a=7,b=5,c=8 -> ...
216 views

### My algorithm is too slow

Reposted from Stack Overflow - I think this is a more appropriate place to ask the question. I have an algorithm that for an integer x and a starting integer i such that 1 < i < x the next ...
273 views

### What should I call this utility function? Is something like it commonly used?

Suppose you want to combine some arrays of objects that have similar properties: var people = [{name: 'Jack', age: 10}, {name: 'Jill', age: 12}] var items = [{owner: 'Jack', name: 'pail'}, {owner: '...
47 views

### Filtering algorithm for word game

Suppose you have a number of anagrams for the same letters, for example: alerting altering integral relating triangle Suppose you have a game where you must find all the anagrams, by placing letters ...
142 views

I have a problem dealing with word ladders. The problem is: given two words and a dictionary file, find the shortest word ladder between the two words. So if given the words cat and pot: cat -> ...