Many algorithmic puzzles are circulating around the net. Here i want to present some problems i came across and found interesting to solve (or not to solve).
Neither did i solve all the problems nor do i even know, if solutions exist for particular problems.
Partial shifts
Consider an array . A k-shift (notation:
) is an operation that takes the k-th element and moves it to the first position. For example
.
The goal is to sort the array using only k-shifts. Give an polynomial-time algorithm that calculates the minimum number of shifts to sort the array, and the shifts itself.
Bonus: What is the expected number of moves?
Finding minimum / maximum
Given an array, that either consists of first ascending and then descending numbers (e.g. 0, 3, 5, 7, 9, 13, 7, 4, 2), of first descending and then ascending numbers (e.g. 10, 8, 3, 2, 5, 7, 9).
Give an efficient algorithm that computes the position of the maximum or minimum, respectively.
Finding palindromes
A palindrom is a sequence of signs that can be read from left to right and right to left without changing, that is: .
Given an array of characters, find the longest palindromic subarray efficiently (that is: ).
Stack sorting
Given a stack, sort its content using only:
Tree distances
Given a undirected, unweighted tree, give an preprocessing algorithm, so that all distances from node to node
can be computed in
.