# Questions tagged [algorithms]

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 design and analysis of algorithms.

9,991 questions
Filter by
Sorted by
Tagged with
19 views

### find the minimum cost conversion between currencies A and B, given a matrix of currency conversions

Given a matrix of currency conversions, find the minimum cost conversion between currencies A and B (ex. maybe min cost conversion is A->C->D->B) I was thinking of this as some sort of max ...
45 views

### Dynamic Programming: What is a subproblem space? Why do we need varying indexes to characterize a subproblem?

In dynamic programming: 1. what is the definition of the space of subproblems? does it have a mathematical definition? 2. why is it necessary to have an arbitrary index for the subproblem to vary? To ...
85 views

### Subset Sum With Interval Target

Define the subset sum with interval target problem (SSITP) as follows: SSITP Input: A multiset $S = \{a_1, …, a_p\}$ of positive integers $a_i$ such that $\sum_{a_i \in S} a_i = T$. SSITP Output: ...
17 views

### Prove that if $k$ was the $(i+1)$st key to be inserted into the hash table, then $E[probes(k)]=\frac{1}{1-\frac{i}{m}}$

Theorem: Inserting an element into an open-address hash table with load factor α requires at most $1/(1 − α)$ probes on average, assuming uniform hashing. By following unsuccessful search strategy, we ...
71 views

### Minimize the sum of diameters of 2-clustering graph

Is there an algorithm with runtime $\mathcal{O}(n^2)$ that for given weighted graph $G$, partition it into 2 cluster $C_1,C_2$ such that sum of diameters of two clusters minimized? I find a paper with ...
35 views

### Number of probes in a unsuccessful search in open address hashing

Theorem: Given an open-address hash table with load factor $α = n/m < 1$, the expected number of probes in an unsuccessful search is at most $1/(1−α)$, assuming uniform hashing. Let us define the ...
17 views

### How to implement a trail for pointer on the screen like the one in fruit ninja game (image in the question)?

So I basically want to make a trail behind a cursor - I'm fairly new to coding and am more interested in the method then some exact code which will do the thing. I've attempted to solve the problem in ...
32 views

### Checksum Algorithm that produces correct 16-bit checksum value for any given input

I need a checksum algorithm that produces the correct 16-bit checksum value for a given input. It's a packet recording from serial communication that I would like to reverse engineer. I have two data ...
60 views

### Making use of one function to recursively find n/3 of another

Given an algorithm M that computes the median of an array A in O(n) time, describe an O(n) algorithm to repeatedly call M in order to find the element of rank n/3 in A. This is a problem I am tasked ...
46 views

### Filling in the image by the brain

The Cones and rods are not evenly or precisely sensitized on the retina by incoming light. Because of this, the image is formed with distortions. But the brain corrects these deformations through a ...
33 views

### All 1D lines overlap each other

I want to verify the correctness of this algorithm. Problem: given a list of intervals, where the first index is greater than the second, determine if every interval overlaps with every other interval....
52 views

### Prove that the expected length $E [n_{h(k)}]$ of the list containing key $k$ is at most $1 + \alpha$

Theorem: Suppose that a hash function $h$ is chosen from a universal collection of hash functions and is used to hash n keys into a table $T$ of size $m$, using chaining to resolve collisions. If key ...
52 views

### Proving that a successful search of hash function is $\Theta(1+\alpha)$

Question: Prove that successful search of hash function with chaining (list at each slot) takes $\Theta(1+\alpha)$. Given a dictionary or hash table that has a chain at each slot in case we have a ...
1k views

### HackerRank August 2021 Coding Challenge - Minimum Time Needed to Finish All Tasks

I was doing the HackerRank Coding Challenge and ran into this problem. I thought through it a bit but wasn't able to come up with a concrete solution, and going through the solution was not very ...
225 views

### Implement a dictionary by using direct addressing on a huge array

For the following question from Introduction to Algorithms book, "We wish to implement a dictionary by using direct addressing on a huge array. At the start, the array entries may contain garbage,...
43 views

### Does an FPTAS exist for the multiple subset sum problem when m is fixed and c is not a variable?

From Wikipedia Multiple subset sum: The multiple subset sum problem (MSSP) is a generalization of the subset sum problem (SSP): given a multiset $S$ of $n$ integers, and an integer $m$, the goal is to ...
47 views

### Analyzing Hybrid Merge and Insertion Sort

We know that merge sort takes O(n log n) and insertion sort takes (n^2) for worst case. The combination of these two algorithm is to speed up and reduce key comparisons, as for a subarray with small ...
17 views

### How to mix populations in multi population genetic algorithm?

I'm working on an optimization problem using genetic algorithm. To increase diversity of potential solutions I'm using multi-population approach: Instead of evolving one population I run 10 ...
12 views

### Mechanism of improved version of Howard's algorithm

For Efficient algorithms for optimum cycle mean and optimum cost to time ratio problems , could anyone advise how the following Howard's algorithm works to compute minimum mean cycle path ?
41 views

### Why we get at most $N^2$ probe sequences using double hash function

Question:Given the following double hash function: $$h(k,i) = (h_1(k) + i\times h_2(k)) \bmod{N}$$, where $h_1(k): key \to \mathbb{Z}$. $h(k,i)$ can generate $N^2$ probe sequences at most and $h_2(k)$ ...
44 views

### Are recursion and a stack equivalent in terms of inplementing DFS?

It is well known that DFS can be implemented either with recursion or a stack, and that both approaches are equivalent, but how far can we take that statement? Consider the following LeetCode problem: ...
24 views

### A Variant to "Boats to Save People"

This question is a variant of LeetCode 881. Boats to Save People by removing the restriction of "each boat carries at most two people at the same time" from the original question. Problem ...
109 views

### Is there an algorithm to solve the following point clustering problem?

According to this post Given $n$ points $P=\{p_1,p_2,\dots,p_n\}$ in 2D space, and a matrix $D^{n\times n}$ with the distances between each pair of points, we want to partition the points into two ...
83 views

### Is $P=NP$ even if we need infinitely many algorithms?

If $P=NP$ was proven with an algorithm, would that have to mean that there is one algorithm that has to work for all inputs of length $n$? More specifically, what if there were infinitely many ...
68 views

### Formulate a 2-clustering problem in LP

The problem: Suppose there are $n$ points in plane, and we want to partition points into two clusters such that sum of diameter of clusters is minimized. The diameter of cluster is maximum distance ...
32 views

### Prove that Horner's method produce only 6 collisions on 50000 English words

Polynomial for producing hash values: $p(z)=a_0+a_1z+\cdots, a_{n-1}z^{n-1}$ Honor's method for that polynomial: $$p_0(z)=a_{n-1} \\ p_i(z)=a_{n-i-1}+zp_{i-1}(z), (i=1, \cdots, n-1)\\$$ Problem: For ...
28 views

### What is the complexity of (prime?) factorization with a fixed number of primes?

I was wondering what the complexity of factorization (on quantum computers or classical computers) is if we know that there must be exactly two prime numbers and we know the two prime numbers. For ...
55 views

### Bubble sort correctness proof

Given following bubble sort pseudocode, prove it's correctness. I am curious if what I have written so far is correct and I would like a feedback. ...
18 views

### Query regarding Length of an Input and Time Complexity of algorithms

What is actually meant when we say 'size/length of an input'? As far as I have interpreted it in different books,it means the values of the parameters to be inputted in an algorithm. But I am actually ...
439 views

### What is the meaning of this symbol that looks like an inverted uppercase A?

I found this symbol in a book I'm reading. Does anyone know what this symbol means? Does it mean for all js?
20 views

### Important cuts bound

Important $(X,Y)-cut$ is defined as follows: S is an important $(X,Y)-cut$ if it is inclusion-wise minimal and there is no $(X,Y)-cut$ $S'$ with $|S′|<=|S|$ such that $R′⊃R$ where R,R' are the sets ...
72 views

### Prove that the following algorithm for division and remainders of natural numbers is correct

I am currently brand new to the correctness proof method, and have stumbled upon this algorithm which I find very tricky. Prove that the following algorithm for division and remainders of natural ...
23 views

### What is the value returned by Hoare partitioning?

Following the article about Quicksort from Wikipedia, there is an implementation of Hoare partitioning: ...
105 views

### Invariant vs Assertion vs lemma

I am reading Distributed Algorithms by Nancy Lynch. I have come across lemmas, assertions and invariants, but I do not understand the difference between them. I think lemma means an intermediate ...
24 views

### Building a game tree from a board game

Currently I want to come up with a program able to solve a specific type of board game, where we have a car moving across a randomly generated board, can't move backwards, a gas gauge and a food gauge....
38 views

### What are the reasons for solution assumptions behind the longest subsequence problem?

All O(N^2) solutions that I have seen for the longest increasing subsequence problem, as their first step, state something like this "Let L[i] be the length of the LIS ending at index i...": ...
23 views

15 views

### Iterative version of depth-first-search code to detect cycle in a directed graph [duplicate]

I have solved a problem that required me to find if the given directed graph had a cycle or not. The deal is, I used a recursive approach to solve it in the depth-first-search method. I was just ...
73 views

### Why do basic graph algorithms (BFS, DFS, Prim, Kruskal) have a similar structure?

This is my first post on CS Stack Exchange. For some time, I have been studying basic graph algorithms, mainly BFS, DFS, minimum spanning trees and their basic algorithms (Kruskal and Prim). One thing ...
52 views

### Approximation algorithm for minimal Covering of an orthogonal polyhedron

Covering an orthogonal polygon with rectangles is according to Culberson and Reckhow NP-complete, even for the case without holes. Franzblau shows an 2-approximation algorithm for simple polygons for ...