Problem Detail: I want to write an algorithm to find the closest pair of points among n points in an XY-plane. I have the following approach in my mind: Find the minimum x co-ordinate(minX) and minimum y(minY) co-ordinate. Name the point Read More …
Category: Uncategorized
[Solved]: Algorithm for a list of best solutions to the Assignment problem
Problem Detail: I am trying to brute force a classical substitution cipher. The problem is that there are $26!$ possible keys. So, I’d like to do frequency analysis to try likely keys first. Then, on the first $n$ tries I will Read More …
[Solved]: Shortest paths in weighted graphs, and minimum spanning trees
Problem Detail: I stuck in one challenging question, I read on my notes. An undirected, weighted, connected graph $G$, (with no negative weights and with all weights distinct) is given. We know that, in this graph, the shortest path between any Read More …
[Solved]: Is this probability distribution data structure already discovered?
Problem Detail: Problem formulation I have implemented an interesting probability distribution data structure: having $n$ elements $a_1, a_2, dots, a_n$ in the data structure with respective positive weights $w_1, w_2, dots, w_n > 0$, upon request each $a_i$ may be returned Read More …
[Solved]: Finding farthest item in an array with duplicates
Problem Detail: I have an array $A[]$ of size $L$, which contains numbers in the range $1 ldots N$. Here $L>N$, so the array will contain repetitions. If $x,y$ are two numbers that are both present in the array, define the Read More …
[Solved]: Counting subarrays that satisfy either of two conditions
Problem Detail: We have an array of integers $a[]$, with each $|a[i]| leq 10^{6}$, $size(a)leq10^{5}$, and $a[i]-a[i-1]leq100$. Then we define the term range as a subarray $[x,y]$ of the array $a[]$, $x lt y$. We need to find total number of Read More …
[Solved]: In the Gas-Up problem, how is the amount of gas the same up to a cyclic shift regardless of starting city?
Problem Detail: I’m working through Elements of Programming Interviews as practice for finding a job. I’ve spent a ridiculous amount of time on Problem 18.7. In the gas-up problem, $n$ cities are arranged on a circular road. You need to visit Read More …
[Solved]: What is the time complexity of this atrocious algorithm?
Problem Detail: This grew out of a discussion of deliberately bad algorithms; credit to benneh on the xkcd forums for the pseudocode algorithm, which I’ve translated to Python so you can actually run it: def sort(list): if len(list) < 2: return Read More …
[Solved]: Show that a regular language L contains only palindromes if and only if all words of length at most 3n are palindromes
Problem Detail: This is an extension of a previous question asked by a different user earlier: Let $x, u, v, w, y, x’, u’, v’, w’, y’$ be words satisfying $y’x’ = xy$. $y’u’x’ = xuy$. $y’v’x’ = xvy$. $y’w’x’ = Read More …
[Solved]: Fast implementation of basic addition algorithm
Problem Detail: Write code for a modified version of the Grade School addition algorithm that adds the integer one to an m-digit integer. Thus, this modified algorithm does not even need a second number being added. Design the algorithm to Read More …