# Methodology for problem solving: the case of iterator live-out value

## 888.11 seminars

 [<< home] [Lecture 1] [Lecture 2] [Lecture 3] [Lecture 4] [Lecture 5] [Lecture 6]

### Lecture 1: Overview and definition of the problem

• Find the slides here.

#### Assignment for next class

Note: students will present their solution for the exercices on the whiteboard during the class.

##### Exercise 1
Write at least three sample input C programs that respect the Static Control Part constraints, and the associated desired output. Each input program must contain at least 4 loops and one conditional.

### Lecture 2: Writing algorithms

• Find the slides here.

#### Assignment for next class

Note: students will present their solution for the exercices on the whiteboard during the class.

##### Exercise 1
Write an algorithm which implements the description below:
Input:
• The starting address of a matrix of integer `A` of size `n x n`
• The starting address of a matrix of integer `B` of size `n x n`
• A function `matrix(16x16): getBlock(address:X, int:i, int:j)` which returns a sub-matrix (a block) of the matrix starting at address `X`, of size `16 x 16` whose first element is at position `(i,j)`
Ouput:
• An integer `c`, the sum of the diagonal elements of the product of `A` and `B`

##### Exercise 2
Write an algorithm which implements the description below:
Input:
• An arbitrary binary search tree `A` with integer nodes
• The left subtree of a node contains only nodes with keys less than the node's key.
• The right subtree of a node contains only nodes with keys greater than the node's key.
• Both the left and right subtrees must also be binary search trees.
Ouput:
• A balanced binary search tree `B` containing all elements in the nodes of `A`

### Lecture 3: Solving the problem, part I

• Find the slides here.

#### Assignment for next class

Note: students will present their solution for the exercices on the whiteboard during the class.

##### Exercise 1
Write an algorithm which implements the description below:
Input:
• an AST `A` of a program such that:
• `A` represents a Static Control Part
• For each loop in `A`, the lower bound is always smaller than the upper bound
• Conditionals are always true
• There is no loop iterator symbol assigned outside its defining loop
Ouput:
• an AST `B` containing `A` which is appended another AST that assigns to each loop iterator in `A` the value it takes when `A` is executed

### Lecture 4: Solving the problem, part II

• Find the slides here.

#### Assignment for next class

Note: students will present their solution for the exercices on the whiteboard during the class.

##### Exercise 1
Write an algorithm which implements the description below:
Input:
• an AST `A` of a program such that:
• `A` represents a Static Control Part
• Conditionals are always true
• There is no loop iterator symbol assigned outside its defining loop
Ouput:
• an AST `B` containing `A` which is appended another AST that assigns to each loop iterator in `A` the value it takes when `A` is executed

### Lecture 5: General algorithm for the Live-out Iterator Problem

• Find the slides here.

#### Assignment for Wednesday, Sept. 15th

Note: students will present their solution for the exercices on the whiteboard during the class.

##### Exercise 1
Write an algorithm which implements the description below:
Input:
• an AST `A` of a program such that:
• `A` represents a Static Control Part
• There is no loop iterator symbol assigned outside its defining loop
Ouput:
• an AST `B` containing `A` which is appended another AST that assigns to each loop iterator in `A` the value it takes when `A` is executed

### Lecture 6: Proving your Algorithm

• Find the slides here.

#### Assignment for Friday, Oct. 1st

Note: students will present their solution for the exercices on the whiteboard during the class.

##### Exercise 1
Given an algorithm which implements the description below, prove its correctness.
Input:
• The starting address of a matrix of integer `A` of size `n x n`
• The starting address of a matrix of integer `B` of size `n x n`
• A function `matrix(16x16): getBlock(address:X, int:i, int:j)` which returns a sub-matrix (a block) of the matrix starting at address `X`, of size `16 x 16` whose first element is at position `(i,j)`
Ouput:
• An integer `c`, the sum of the diagonal elements of the product of `A` and `B`