CSC 236 H1
Midterm Test #2 Solutions
Winter 2017
Note to Students: This file contains sample solutions to the term test together with the marking
scheme and comments for each question. Please read the solutions and the marking schemes and comments
careful
Introduction to the Theory
of Computation
AZADEH FARZAN
FALL 2015
LAST WEEKS SUMMARY .
We Learned about mathematical induction.
P(1)
P(2)
P(3)
.
P(n)
We Learned about complete induction.
P(1)
P(2)
P(3)
.
P(n)
EXAMPLE
Prove that for any non-empty (complete
Introduction to the Theory
of Computation
AZADEH FARZAN
FALL 2015
NOW THAT WE KNOW ABOUT
RECURSIVE FUNCTIONS, LETS GO
BACK TO PROGRAMS .
SEC. 3.9
ANALYZING RECURSIVE FUNCTIONS
RUNNING TIME OF FACTORIAL PROGRAM
(1)
(2)
(3)
13
int fact(int n)
cfw_
if (n <=
Introduction to the Theory
of Computation
AZADEH FARZAN
FALL 2015
THE RUNNING TIME OF
PROGRAMS
/* set small to the index
shown void SelectionSort(int have the original line number
in Fig. 3.1. The statements A[], int n) of the first
/* is to set of theto
Introduction to the Theory
of Computation
AZADEH FARZAN
FALL 2015
s
Fibonacci numbers. (The rst two are 1, and each succeeding number is the sum of
the previous two. The rst seven Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13.) Note
that the value of n is th
Introduction to the Theory
of Computation
AZADEH FARZAN
FALL 2015
THERE IS A LECTURE ON
FRIDAY!
LAST WEEK .
We learned about recursively dened functions!
How to get solve them and get a closed-form denition of the
function.!
How they related to running ti
CSC 236 H1
Winter 2012
Midterm Test #1
Duration: 50 minutes
Aids Allowed: one single-sided handwritten 8.511 aid sheet
Student Number:
Family Name(s):
Given Name(s):
Lecture Section:
L0101 (A. Farzan)
L0201 (F. Pitt)
Do not turn this page until you have r
CSC 236 H1
Winter 2012
Midterm Test #2
Duration: 60 minutes
Aids Allowed: one single-sided handwritten 8.511 aid sheet
Student Number:
Family Name(s):
Given Name(s):
Lecture Section:
L0101 (A. Farzan)
L0201 (F. Pitt)
Do not turn this page until you have r
CSC 236 H1F
1.
Tutorial Solutions for Week 1
Fall 2015
Prove that for all n N, every set of size n has exactly 2n subsets.
Ans: The precise denition of predicate is
P (n) : all sets of size n have 2n subsets
Base case: An empty set (set of size 0) has onl
CSC 236 H1F
Tutorial Solutions for Week 3
Fall 2015
1. A complete binary tree is a binary tree in which every node has two children, except for the leaves (which
have no child), and every leaf is at the same depth (same distance from the root).
a) Give a
CSC 236 H1F
1.
Tutorial Solutions for Week 4
Fall 2015
Consider the function T(n) dened by the following recurrence:
2
T (n) =
3 + T (
if n = 1
n
2
) if n > 1
Prove that T (n) is in (log n).
Ans: In order to prove (log n), we have to show T (n) (log n) an
CSC 236 H1F
Tutorial Solutions for Week 5
Fall 2015
1. List and explain the steps used to analyze the time complexity of a recursive algorithm (provide as much
detail as possible).
Ans:
a) Write a recurrence relation for T (n), the worst-case number of st
CSC236H: Introduction to the Theory of Computation
The proof of the second direction of Lecture 3 problem
Problem. Let S be dened recursively as follows:
cfw_(1, 1), (1, 2), (2, 1) S.
(a, b) S = (a, b + 2) S (a + 2, b) S.
Let S = cfw_(x, y)| x, y N k, m
EXAMPLE
Consider the following recursive denition of a set S of points in a
plane:
cfw_(1, 1), (1, 2), (2, 1)
S
if (a, b) S then (a + 2, b) S and (a, b + 2) S.
Can you give a formal non-recursive description of S?
Can you prove that your description is
IN SUMMARY .
We Learned about mathematical induction.
P(1)
P(2)
P(3)
.
P(n)
We Learned about complete induction.
P(1)
P(2)
P(3)
.
P(n)
WHY DOES INDUCTION WORK
AS A PROOF METHOD?
PROOF BY CONTRADICTION
Imagine I have my two induction proof ingredients:
PRO
CSC 236 H1
Midterm Test #1 Solutions V2
Winter 2017
Note to Students: This file contains sample solutions to the term test together with the marking
scheme and comments for each question. Please read the solutions and the marking schemes and comments
care
CSC 236 H1
Midterm Test #1 Solutions V1
Winter 2017
Note to Students: This file contains sample solutions to the term test together with the marking
scheme and comments for each question. Please read the solutions and the marking schemes and comments
care
Homework 1 Solutions
1. Show, using induction and the fact that
, the Hockey Stick
for all appropriate values of n, c.
Theorem:
This is most certainly not a double-induction problem. The question is: how do we know
that? Clearly, there are two variables t
CSC 236 Summer 2015
Homework 2
Due Friday, May 29
1. If 2 + 5 0 (mod 7), show that is an equivalence relation.
2. A greedy algorithm is one in which we always choose the biggest move, under some definition
of the size of each move. When we refer to The Gr
CSC236H: Introduction to the Theory of Computation
Exercise 2
Due on Friday October 18, 2013 before 10pm (submit on Markus)
Note that this is an exercise and has to be submitted individually by all students. Have a happy thanksgiving week with your
family
1. Prove (by induction) that n, =0 2 =2 +1 -1:
n, P (n) P (n) =0 2 =2 +1 -1
Base Case: P (0) 0 20 =20+1 -1=1 P (0) holds
=0
Induction Hypothesis: assuming P (k) =0 2 =2 +1 -1 is True, then we can prove P (k+1) is True
as well.
The Step:
+1
=0 2 =2(+1)+1
CSC236H: Introduction to the Theory of Computation
Exercise 1
1. (10 points) Prove (by induction) that
n N, n 2i = 2n+1 1
i=0
(warm up problem!)
Solution: Dene predicate P (n) as:
P (n) n 2i = 2n+1 1.
i=0
The goal is to show nP (n).
Basis: P (0) is true s
CSC236H: Introduction to the Theory of Computation
Assignment 1
Due on Friday October 9, 2015 before 5pm (submit on Markus)
Note that this is an assignment and can be submitted in groups. In fact, it is highly encouraged. This is long and designed
for a g
Introduction to the Theory
of Computation
AZADEH FARZAN
FALL 2015
WELCOME!
QUICK OVERVIEW OF THE
COURSE WEBPAGE
RULES OF THE CLASS
Respect your fellow classmates:!
Dont talk loudly to each other during lecture.!
Dont eat/drink in a disturbing manner (smel
INDUCTION PRINCIPLE
Let P(n) be a predicate dened over N.
P (1) is true, and
n N [P (n) =
P (n + 1)],
then
8n 2 N, P (n) is true.
n 2 N.
LETS PLAY WITH THE
BASIS!
EXAMPLE: BASES OTHER THAN 1
For all n
6, we have 2n > 10n.
EXAMPLE: BASES OTHER THAN 1
For
Introduction to the Theory
of Computation
AZADEH FARZAN
FALL 2015
LAST WEEK .
We Learned about mathematical induction.
P(i)
P(1)
P(1)
P(2)
P(3)
P(i + 1)
.
P(n)
EXAMPLE
Problem: prove that every natural number greater than
1 can be written as a product of
CSC236 Tutorial 6: Divide and Conquer
In this tutorial, we take the opportunity to study a couple of interesting divide and conquer algorithms.
1
Minimum Element
Given an unsorted list A, nd the smallest element of the list.
(a) Provide an algorithmic sol
CSC236 Tutorial 6: Divide and Conquer
In this tutorial, we take the opportunity to study a couple of interesting divide and conquer algorithms.
1
Minimum Element
Given an unsorted list A, nd the smallest element of the list.
(a) Provide an algorithmic sol
CSC236 Tutorial 5: Master Theorem
1. Consider the following generic divide-and-conquer code:
foo(A[1.n]) cfw_
if (n = 1) cfw_
return 1
else cfw_
if (.) cfw_
x = foo(A[1.n/3])
else cfw_
y = foo(A[1.n/3])
z = foo(A[2n/3.n])
return x + y * z
Develop a r
CSC236H Additional Lecture Notes For Week 9
Bahar Aameri
Winter 2016
1. Give a proof of correctness for the program below with respect to the given specification.
Precondition: A is a non-empty list of numbers.
Postcondition: Returns the average of the
CSC236 Summer 2017
Assignment #1: Induction
Zimu Liu, Yiyi Cheng
June 8, 2017
1. Consider the Fibonacci function f :
(
1,
f (n) =
f (n 2) + f (n 1)
if n = 0 or n = 1
if n > 1
Use simple induction to prove that if n is a natural number, then f (0) +
f (2)
CSC236 Winter 2017
Assignment #3: Algorithm Analysis, Formal Languages | Sample
Solution
Due April 5th, by 9:00 pm
The aim of this assignment is to give you some practice with topics related to formal languages. You will also design an
algorithm, and do a
CSC236 Summer 2017
Assignment #1: Induction
Due June 8th, by 6:00 pm
The aim of this assignment is to give you some practice with various forms
of induction. For each question below you will present a proof by induction,
using the type of induction specif
CSC236 Summer 2017
Assignment #2: Analysis of Recursive Algorithms
Due July 13th, by 6:00 pm
The aim of this assignment is to give you some practice analyzing runtime and proving correctness of recursive algorithms.
For each question, please write up deta