exercise1-solved

# exercise1-solved - and white cells will not be equal...

This preview shows pages 1–2. Sign up to view the full content.

Algorithm and Data Structures Assignment 1 - Solution Dr. Andreas N¨uchter Fall 2009 Exercise 1.1 1. S ( m, n, a, d ) = n X k = m +1 ( a + d · k ) (1) = n X k = m +1 a + n X k = m +1 ( d · k ) (2) = ( n - ( m + 1) + 1) · a + d n X k = m +1 k (3) = ( n - m ) · a + d · ( n X k =1 k - m X k =1 k ) (4) = ( n - m ) · a + d 2 · ( n · ( n + 1) - m · ( m + 1)) (5) 2. C Function: int ArithmeticSeries ( int m, int n , int a , int b) { return (n - m) * a + d * (n * (n - 1) - m * (m - 1))/2; } Pascal Function: function ArithmeticSeries (m, n , a , b : integer ) : integer ; begin ArithmeticSeries := (n - m) * a + d * (n * (n - 1) - m * (m - 1))/2; end ; 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Exercise 1.2 1. The cells on the chess board are colored in black and white such that 2 adjacent cells have diﬀerent colors. Also cells on the diagonals have the same color. Note that one domino of size 2 × 1 or 1 × 2 will always cover 2 adjacent cells and therefore both white and black cell. So no matter how many dominos are on the board equal number of black and white cells will be covered. If 2 corners of the chess board have been removed the number of black
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: and white cells will not be equal. Therefore one cannot fully cover this kind of board with dominos. ¥ 2. ”= ⇒ ”. If number of white cells isn’t equal to the number of black cells on the board covering is impossible as shown above. ” ⇐ =”. Suppose 2 cells, one black and one white have been removed. Let these 2 cells be corners of a rectangular region. Covering the board outside the region is simple. Covering the inside region can be done as shown below. Note that if g is odd and not even covering will be the same up to rotation of the board. Also u will always be odd, since corner colors should be diﬀerent. Exercise 1.3 http://en.wikipedia.org/wiki/Boyer-Moore_string_search_algorithm :) 2...
View Full Document

## This note was uploaded on 05/04/2010 for the course CS 320251 taught by Professor Nuechter during the Fall '09 term at Jacobs University Bremen.

### Page1 / 2

exercise1-solved - and white cells will not be equal...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online