import java.util.ArrayList;
public class AdjList cfw_
/ An AdjList is a (source, inDegree, dests) entry of a Graph
private String source;
/ source node label
private int inDegree;
/ # nodes pointing at this node
private ArrayList<String> dests;
/ the list
The Automatic Efficient Test Generator (AETG) System
D. M. Cohen, S. R. Dalal, A. Kajla, G. C. Patton
Bellcore
Morristown, NJ
Piscataway, NJ
Abstract
1993 [6]. A complete system with many new capabdities and constructs was created by us in 1993. Besides c
10/17/2016
Permutations and Combinations
Rosen, Chapter 5.3
Motivating question
In a family of 3, how many ways can we
arrange the members of the family in a line
for a photograph?
1
10/17/2016
Permutations
A permutation of a set of distinct objects is an
Midterm Exam 2 for 08161:
Fall 2015
Instructor: C. Anderson
100 points total
Answers to counting questions must be written as mathematical expressions that may include
factorial operations. Use the last page if you need more space.
1. [10 points] For th
12/1/2016
Sorting
Savitch Chapter 7.4
Why sort
Easier to search (binary search)
Sorting used as a step in many algorithms
1
12/1/2016
Sorting algorithms
There are many algorithms for sorting:
Selection sort
Insertion sort
Bubble sort
Merge sort
Heap sort
Assertions, pre/postconditions
Assertions: Section 4.2 in Savitch (p. 239)
Programming as a contract
n
Specifying what each method does
q
n
Precondition
q
q
n
Specify it in a comment before method's header
What is assumed to be true before the method is
e
CS161 Recursion Continued
Tail recursion
n
Tail recursion is a recursive call that occurs as
the last action in a method.
Tail recursion
n
n
Tail recursion is a recursive call that
occurs as the last action in a method.
This is tail recursion:
public int
10/12/2016
Counting: Basics
Rosen, Chapter 5.1-2
Motivation: Counting is useful in CS
Application domains such as, security, telecom
How many steps are needed to solve a problem
(time complexity)
How much space is needed to solve a problem
How many passwo
10/29/2016
Counting: Review
Rosen, Chapter 5.1-2
Midterm
Midterm will be Friday, November 4th
Must have your ID to take the exam
CS110 lab between 8am and 4pm
Closed book, closed notes
Bring a calculator
We will provide scratch paper
1
10/29/2016
Week 11
Mathematical Induction
Rosen Chapter 4.1 (6th edition)
Rosen Ch. 5.1 (7th edition)
Mathmatical Induction
Mathmatical induction can be used to prove
statements that assert that P(n) is true for all
positive integers n where P(n) is a
propositional function
Objects and classes
Java classes
object: An entity that combines state and behavior.
object-oriented programming (OOP): Writing
programs that perform most of their behavior as
interactions between objects.
class:
1. A program/module. or,
2. A blueprint/te
Inheritance
Big software
n
n
software engineering: The practice of conceptualizing,
designing, developing, documenting, and testing largescale computer programs.
Large-scale projects face many issues:
q
q
q
q
q
n
getting many programmers to work together
About this course
n
CS 161: Object Oriented
Problem Solving
Like 160, 161 is a combination of programming
and discrete math.
q
n
Why is math important to us? What does that
have to do with computer science?
From procedural to object oriented programming
2
7/15/15
The software crisis
Inheritance
n
n
software engineering: The practice of conceptualizing,
designing, developing, documenting, and testing largescale computer programs.
Large-scale projects face many issues:
q
q
q
Obtained from the web:
Question
6/30/15
What does this method do?
Recursion
Chapter 5.4 in Rosen
Chapter 11 in Savitch
Recursion
n
recursion: The definition of an operation in terms
of itself.
q
n
Solving a problem using recursion depends on solving
smaller occurrences of the same pro
ArrayLists
Chapter 12.1 in Savitch
Using arrays to store data
Arrays: store multiple values of the same type.
q Conveniently refer to items by their index
q Need to know the size before declaring them:
int[] numbers = new int[100];
n We often need to stor
Interfaces
Savitch ch. 8.4
Relatedness of types
n
n
Consider the task of writing classes to represent
2D shapes such as Circle, Rectangle, and
Triangle.
There are certain attributes or operations that
are common to all shapes:
perimeter, area
n
By being a
6/17/15
Using arrays to store data
ArrayLists
Chapter 12.1 in Savitch
Arrays: store multiple values of the same type.
Conveniently refer to items by their index
q Need to know the size before declaring them:
int[] numbers = new int[100];
n We often need
Permutations and Combinations
Rosen, Chapter 5.3
Motivating question
n
A)
B)
C)
D)
In a family of 3, how many ways are there to
arrange the members of the family in a line
for a photograph?
3x3
3!
3x3x3
23
Permutations
n
A permutation of a set of distinct
A simple counting problem
Counting: Basics
You have 6 pairs of pants and 10 shirts. How
many different outfits does this give?
Possible answers:
A) 6 x 10
B) 6 + 10
Rosen, Chapter 6.1
Counting: the product rule
If there are n1 ways of doing one task, and
Preliminaries
Linked Lists
Arrays are not always the optimal data
structure:
Chapter 12.3 in Savitch
An array has fixed size needs to be copied to
expand its capacity
Adding in the middle of an array requires moving
all subsequent elements
ArrayLists have
Linked Lists
Chapter 12.3 in Savitch
Preliminaries
n
Arrays are not always the optimal data
structure:
q
q
n
An array has fixed size needs to be copied to
expand its capacity
Adding in the middle of an array requires moving
all subsequent elements
ArrayLi
CS 161: Object Oriented
Problem Solving
About this course
n
Like 160, 161 is a combination of programming
and discrete math.
q
n
Why is math important to us? What does that
have to do with computer science?
From procedural to object oriented programming
A
Motivating question
Permutations and
Combinations
A)
Rosen, Chapter 5.3
B)
C)
D)
Permutations
A permutation of a set of distinct objects is an
ordered arrangement of these objects.
Example: (1, 3, 2, 4) is a permutation of the
numbers 1, 2, 3, 4
How many
Motivation
Mathematical
Induction
Rosen Chapter 5
Motivation
Let n be a positive integer. Show that every
2n x 2n chessboard with one square removed
can be tiled using triominoes, each covering
three squares at a time.
Show that any postage of 8 can be
ob
Mathematical Induction
Rosen Chapter 5
Induction versus recursion
n
n
Recursion: method m(n): implement m for any
n in some domain (e.g. n>=0) by
testing for a base case and returning result
or creating the result using the solution of a
smaller problem,
Loop invariants
Loop invariants: Section 5.5 in Rosen
Loop invariants as a way of reasoning
about the state of your program
<precondition: n>0>
int i = 0;
while (i < n)cfw_
i = i+1;
<post condition: i=n>
We want to prove:
i=n right after the loop
Example
Relatedness of types
Interfaces
Consider
the task of writing classes to represent
2D shapes such as Circle, Rectangle, and
Triangle.
There are certain attributes or operations that are
common to all shapes:
perimeter,area
Savitch ch. 8.4
Interface as a