Friday, June 6, 2014

Palidromes

Given a string find the minimum number of characters to be inserted for converting a string into a palidrome

Wednesday, June 4, 2014

Palindrome String

Compute the longest palindrome string

Tuesday, June 3, 2014

Dynamic Programming -

Given an array of integers find the longest bitonic sequence

Monday, June 2, 2014

Coin change

Given  n dollars, how many different ways there are to make the change into a set of coins

Saturday, May 31, 2014

Friday, May 30, 2014

Thursday, May 29, 2014

Integer Knapsack

A knapsack has max capacity C and there are n items each with weight wi, and value vi. Maximize the value in the knapsack without exceeding its max capacity

Wednesday, May 28, 2014

Jump stairs

There ia stair with n steps. You can climb either one step or two steps at a time. How many different ways there are to climb the stair?

Tuesday, May 27, 2014

Monday, May 26, 2014

Dice

Given a dice count how many ways to get sum s

Sunday, May 25, 2014

Palindromes

Given a string find the minimum number of characters to be inserted for converting the string into a palindrome.

Saturday, May 24, 2014

Bridge matching

N cities are on the northern bank of a river and n cities are on the southern bank. You can build a bridge only between cities with the same number

Friday, May 23, 2014

Sum subset

Given an array of integers of size n, partition it in such a way that the two subsets have equal sum s.

Thursday, May 22, 2014

Partition set

Partition a multiset S of positive integers into two subsets S1 and S2, such that the sum of the numbers in S1 equals the sum of the numbers in S2

Wednesday, May 21, 2014

Segment partition

Given a segment of integer length n, cut into different integer parts in such a way to maximize the product of the lengths of all parts

Tuesday, May 20, 2014

Cutting a rod

Given a rod of length n and a vector of prices for different lengths, cut the rod for maximizing the gain

Monday, May 19, 2014

Max matrix 0/1

Given a matrix consisting only of 0 and 1 find the maximum size square submatrix with all 1.

Sunday, May 18, 2014

Matrix parentization

Given a set of m matrices find the most efficient way of multiplying them

Saturday, May 17, 2014

Max submatrix

Given a matrix of size n x n fine the maximum sum rectangle

Friday, May 16, 2014

BST and dynamic programming

Given a binary search tree, find the size of the largest independent set of nodes

Thursday, May 15, 2014

Games of coins

A set of coins are aligned and two players can pick one coin from each side in turn. Maximize the value of the coins picked by the first player

Wednesday, May 14, 2014

Maximum value contiguous subsequence

Given an array of real numbers, find a contiguous subsequence with max sum S

Tuesday, May 13, 2014

Stock prices

Given an histogram array of unsigned integers encoding the price of a stock title during previous year, compute the area for the largest rectangle contained in this histogram

Monday, May 12, 2014

Ship battle

Given a matrix M and an array V match the array in the matrix

Sunday, May 11, 2014

Scheduling

Given n jobs, each one with a processing time t1 a profidt p1 and a deadline di maximize the profit

Saturday, May 10, 2014

Boolean parentesization

Given a boolean expression of AND, OR, XOR, TRUE, FALSE find the number of ways to parenthesize and evaluate to true

Friday, May 9, 2014

Balanced partition

Given an array of integers between 0 and M divide the integers into two sets such that the difference of their sum is minimized

Wednesday, December 25, 2013

Egg drops

Given k eggs and n floors in a building, find the minimum number of trials required to determine the lowest floor from which when we drop an egg it does not break. Provide a Dynamic Programming solution.

Tuesday, December 24, 2013

Bridge Matching

n cities are sitting on the northern bank of a river and n cities are sitting on the southern bank. You can build a bridge only between cities with the same number. Provide a dynamic programming solution.

Monday, December 23, 2013

LBS

Given an array of integers find the longest bitonic sequence. Provide a dynamic programming solution

Sunday, December 22, 2013

Box Stacking

Given a set of 3d boxes compute the largest stack of boxes. A box can be stacked only on the top of another box with lager base. Provide a dynamic programming solution for stacking the boxes

Saturday, December 21, 2013

Boolean Parentization

given a Boolean expression of and, or, xor, true, false, find the number of ways to parenthesize and evaluate to true. Provide a dynamic programming solution

Friday, December 20, 2013

Box Stacking

Given a set of 3d boxes compute the largest stack of boxes. A box can be stacked only on the top of another box with lager base.

Thursday, December 19, 2013

Maximum value contiguous subsequence

given a real numbers’ array find a contiguous subsequence with max sum. Provide a dynamic programming solution

Wednesday, December 18, 2013

Balanced partition

given an array of integers between 0 and M divide the integers into two set such that difference of sums is minimized. Provide a dynamic programming solution

Tuesday, December 17, 2013

Scheduling

given n jobs each of which with a processing time, a profit and a deadline maximize the profit. Provide a dynamic programming solution

Saturday, November 9, 2013

Chapter 3 is done

This chapter is about Graph computation and there are classical algorithms (BFS, DFS, MST). MST is implementing the classical Prim's algo but using Fibonacci heap available in Boost. Here you find the first version of the graph code

Wednesday, October 30, 2013

Writing a programming / algorithmic book

I wanted to take on a new challenge and start writing a book about algorithms and design. The intent is to have Simplicity by Design (SD): every Chapter is a collection of 15-30 questions, followed by the solution, followed by a C++ code snippet which can be easily re-used.

So far, I have drafts for 3 chapters: bit programming, dynamic programming, and graphs. Here an example of graph code with very classical questions: implement a graph, implement bfs, implement dfs, implement topological sort, I already have code for other graph problems.  Dynamic programming has more mathematical content and I will publish an excerpt next weeks.

A number of questions:

  1. Should I publish code for public review? If so, can i still use it for the book?
  2. Should I publish questions for public review?
I think that this will be one of my side projects off work for the next year or so.


Sunday, September 29, 2013

Create your Team

you have a pool of players. Each player ha a set of skills. For creating a team you need to hire the minimum number of players who have together a predetermined set of skills

Wednesday, September 25, 2013

P0 - what people are saying

Here some previous postings

















Find i = n^3 + m^3

how can a number be expressed as sum of two cubes?

52 cards

You have 52 cards half of them are red and half of them are black. You have a given amount of money M and every time you can bet k < M money. If you predict the right colour you will win 2k money, if not you will loose k. What is the best strategy?

Sort lexicographically an array of strings in C++ and in C

Monday, September 23, 2013

Conflits in k keywords

A keyword is made up of n bits. Given k keywords generated with uniform probability what is the probability to have collision? Provide an evaluation and write the code.

Sunday, September 22, 2013

Radix Sort -

Write a radix sort implementation in C++

Saturday, September 21, 2013

PageZero and Ted

I enjoyed attending Ted and give a talk about PageZero. While I was listening a number of very inspiring talks, I asked to myself would this PageZero really help users?

So I started to write {Ted} and immediately PageZero suggested {Ted Talks} as first suggestions and {Speakers} Speakers as su-bintent. That's exactly what I was looking for!!! I am impressed.








Then, I thought and what if I was interested in the Movie? PageZero predicted that potential choice too. Kind of cool, no?

Friday, September 20, 2013

Buying with constrains

You have a bag with capacity C and can insert items with value wi which will occupy space si. You cannot exceed the capacity. Write an algorithm in C++

Thursday, September 19, 2013

Project PageZero

SearchBox never changed since 1993, when the first search engine was created. Bing is disrupting the box by bridging the gap with the World of Entities. Names, Web Sites, and Generic Entities are directly accessible and understood as soon as you type.



http://www.slideshare.net/antoniogulli/project-page-zero-bi 

Tuesday, September 17, 2013

k balls, n floors

There is a building with n floors and you have k balls.  Balls are identical and when you drop them they can break or not. You need to figure out the highest floor of the building an egg can be dropped without breaking.

Monday, September 16, 2013

Friday, September 13, 2013

Design Patterns : C++ full collection of Gamma's patterns

Design Patterns : C++ full collection of Gamma's patterns

Full collection of Gamma's patterns in Full collection of Gamma's patterns in c++: 
  1. Creational: Abstract Factory, Builder, Factory, Prototype, Object Pool, Singleton,
  2. Structural: Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Proxy patterns,
  3. Behavioral: Chain of Responsibility, Command, Iterator, Mediator, Memento, Observer, State, Strategy, Template, Visitor, and Interpreter

Thursday, September 12, 2013

Capped payrolls

In a company there are different payrolls pi, and we want to find a cap C such that the total amount of money paid is not above a maxim M. How can you determine C?

Wednesday, September 11, 2013

Int 16 bit - compute the sqrt

Given an integer in 16 bits compute the sqrt

Tuesday, September 10, 2013

Thursday, September 5, 2013

Monday, September 2, 2013

(10^9)!

count the number of trailing zeros

Sunday, September 1, 2013

Given two numbers a and b

Swap them with no temp variable. How many way  do you know for achieving that?

Thursday, August 29, 2013

Load balancing

We have a set of task i={1, ..., n} and each one has a cost b_i, how can we assigned to m servers so that the load is balanced?

Sunday, August 25, 2013

Triangle and Ants

On a triangle, there are 3 ants what is the probability that they collide when they move

Saturday, August 24, 2013

Sunday, August 18, 2013

What is wrong with this code?

string FindAddr( list emps, string name )
{
  for( list::iterator i = emps.begin();
       i != emps.end();
       i++ )
  {
    if( *i == name )
    {
      return i->addr;
    }
  }
  return "";
}

Friday, August 16, 2013

generate strings

Write a program that generates from the string "abcdefghijklmnopqrstuvwxyz{" the following: a bcb cdedc defgfed efghihgfe fghijkjihgf ghijklmlkjihg hijklmnonmlkjih ijklmnopqponmlkji jklmnopqrsrqponmlkj klmnopqrstutsrqponmlk lmnopqrstuvwvutsrqponml mnopqrstuvwxyxwvutsrqponm nopqrstuvwxyz{zyxwvutsrqpon

Thursday, August 15, 2013

Sunday, August 4, 2013

Use a dictionary

Given a string like "thisisalongstringwithmisakenoten" and a dictionary of words, split the string so that the number of non matched words are minimized. Try to optimize the code

Saturday, August 3, 2013

Implement a smartpointer class

using templates in C++

Smartpointer s1(T * ptr)
Smartpointer s1(Smartpointer & s2)
and the assigment
s1=s2