Practice Problems for Exam 2
Structural Induction and invariants
1. Below is the inductive definition for a balanced sequence (of parantheses):
Foundation: The empty sequence is balanced.
Constructor: If s and t are balanced sequences, then so are st an
CS/Math 240: Intro to Discrete Math
Fall 2015
Solutions to Homework 4
Problem 1
We denote by Zeros(S) the number of 0s that appear in sequence S. Similarly, Ones(S) denotes
the number of 1s in S.
We use strong structural induction to prove the given state
240 Discussion 5 Solutions
Fall 2015
1. We begin by defining any puzzle state by its sequence of tiles in-order,
starting from the top left corner and proceeding in a left-right, top-down
fashion. So our initial board state is
(1, 2, 3, 4, 5, 6, 7, 8, 9,
Homework 5 Solution
Problem 1
1. The first time we reach line (2) A is [5, 8, 2, 6, 1, 4, 7, 3]
2. The second time we reach line (2) A is [5, 2, 6, 1, 4, 7, 8, 3]
3. The third time we reach line (2) A is [2, 5, 1, 4, 6, 7, 8, 3]
4. The fourth time we reac
Discussion 5
Fall 2015
In class we showed that the 8-puzzle is unsolvable. In this problem youll
show that the same holds for the 16-puzzle.
Recall that in the 16-puzzle, there are 15 tiles, numbered 1 through 15, and
one empty square arrange in a 4 4 gri
Discussion 7
Fall 2015
1. Consider the following program specification and implementation for determining if a string is a palindrome:
Algorithm 1: IsPalindrome(A, b, e)
Input: A, b, e - String A, indices b and e
Output: true if A[b, e] is a palindrome, f
240 Discussion 6 Solutions
Fall 2015
Part b
Let xk , yk , rk be the values of x, y and r the kth time we reach the test of the while loop. We show by
induction on k that 0 xk yk and gcd(xk , yk ) = gcd(a, b).
For the base case k = 1, we need to find what
Discussion 6
Fall 2015
The algorithm below is known as Euclids algorithm for the greatest common divisor.
Algorithm 1: GCD(a, b)
Input: a, b N, at least one of a, b is nonzero
Output: gcd(a, b)
(1)
(2)
(3)
(4)
(5)
(6)
(7)
if a b then (x, y) (a, b)
else (x
Hey! Were Learning!
CS524: Introduction to Optimization
Lecture 4
Last Time
Simple Input/Output LP
Sets: Algebraic Modeling
Michael Ferris
Today
Computer Sciences Department
University of Wisconsin-Madison
Another I/O model The Diet Problem
What can go wr
Last Time
Last Time
Convexity
CS524: Introduction to Optimization
Lecture 8
Modeling | |
Minimax and Maximin
Michael Ferris
This Time
GAMS: Dynamic Sets
Network Problems:
Computer Sciences Department
University of Wisconsin-Madison
September 27, 2016
Mich
Update
CS524: Introduction to Optimization
Lecture 10
Last Time
Networks
GAMS: Solution attributes
GAMS: Setting options to solvers
Michael Ferris
Computer Sciences Department
University of Wisconsin-Madison
This Time
Optimization Problem: Min Cost Networ
CS/ISyE/ECE 524
Introduction to Optimization
3. Linear programs
Review: linear algebra
Geometrical intuition
Standard form for LPs
Example: transformation to standard form
Laurent Lessard (www.laurentlessard.com)
Spring 201516
Matrix basics
numbers. A
Review
Last Time
Softening Constraints
CS524: Introduction to Optimization
Lecture 6
Blending Constraints
This Time
Some GAMS (ordered) set notation
Michael Ferris
Computer Sciences Department
University of Wisconsin-Madison
Multiperiod models
GAMS Logica
Modeling
Optimization Hierarchy
Optimization hierarchy
Optimization models can be
categorized based on:
types of variables
types of constraints
type of cost function
Models: LP, QP, SOCP, SDP,
MIP, IP, MINLP, NLP,.
CS524: Introduction to Optimization
L
What Are We Doing
Last Time.
Multiperiod Models
CS524: Introduction to Optimization
Lecture 7
GAMS: Ordered Sets
GAMS: A little bit of logic
Michael Ferris
This Time
Backlogging
Computer Sciences Department
University of Wisconsin-Madison
Convexity a slig
Class Information
Todays Outline
CS524: Introduction to Optimization
Lecture 1
About this class.
About me.
About you.
Modeling:
Michael Ferris
What is it?
Why should we care about this stuff?1
Computer Sciences Department
University of Wisconsin-Madison
G
CS524: Introduction to Optimization
Lecture 9
Michael Ferris
Computer Sciences Department
University of Wisconsin-Madison
October 3, 2016
Michael Ferris (UW-Madison)
CS524:Lecture 9
Lecture Notes
1 / 10
Update
Last Time
GAMS: $ Logic and Dynamic Sets
Netw
Learn, Learn, Learn
Last Time
LP: Simplex Method
CS524: Introduction to Optimization
Lecture 5
LP: What Can go Wrong?
Michael Ferris
Today
Finish LP/What can go wrong
Computer Sciences Department
University of Wisconsin-Madison
Softening Constraints
Blend
Update
CS524: Introduction to Optimization
Lecture 3
Last Time
First LP. Introduction to GAMS.
Assumptions of LP.
Michael Ferris
This Time
Algebraic syntax for large-scale LP
Computer Sciences Department
University of Wisconsin-Madison
Corresponding GAMS
Software Design I (CS 120)
Assignment 03 (20 points): A Calculated Plan
Due by 5:00 PM, Friday, 17 February 2017
For this assignment, you will produce two separate small programs. Make a single Java project; in
that project you will write two distinct cla
An Object
This object is everyday, and
yet complicated
Interacts with other objects
Class #03: Objects and Methods
Cell towers
You!
Made of other objects
Most of us can figure out how
to use it as a black box
Software Design I (CS 120): M. Allen, 2
Simple Text Display
The primitive types convert easily to String and
can be easily printed out to the basic console
double result = 73 / 3.5;
String s = " + result;
Class #15:
More about Displaying
and Processing Text
System.out.println( result );
Softw
Two Types of Types
So far, we have mainly been dealing with objects, like
DrawingGizmo, Window, Triangle, etc. that are:
1.
2.
3.
4.
Class #07: Java Primitives
The language has some other things as well:
1.
2.
Software Design I (CS 120): M. Allen, 02 Fe
Software Design I (CS 120)
Assignment 01 (15 points): Caaaaaaaawwww!
Due by 5:00 PM, Friday, 03 February 2017
Instructions: For this assignment, you will be using four simple graphics classes to draw a picture.
One of those classes, Window, can be used to
Software Design I (CS 120)
Lab Exercise 01
Friday, 27 January 2017
Instructions: For this lab, you will practice using objects and running methods. You will use two
existing classes that have been written for you, Window and Triangle. You will write your
Software Design I (CS 120)
Lab Exercise 02
Friday, 03 February
Instructions: This lab will give you more practice using objects, primitive variables, and Java
arithmetic. You will modify code in the pre-written main() method from the Program class.
To com
Important Java Syntax I: Identifiers
Each object in a Java program has an identifier (name)
This includes:
Each identifier in a Java program:
Class #05:
More About Objects and Methods
any class, like DrawingGizmo
any variable, like pen or penci
Review: Classes and Object Instances
DrawingGizmo pencil;
pencil = new DrawingGizmo();
We are working with both a class (DrawingGizmo) and
an object (actual code and data saved in memory, to
which the name pencil refers)
Class #06:
Objects, Memory, & Pr
Software Design I (CS 120)
Assignment 02 (15 points): Rollicking Rowboats!
Due by 5:00 PM, Friday, 10 February 2017
Instructions: For this assignment, you will be using the simple graphics classes from the prior
assignment to draw a picture, and will be u