Prove that the set of positive rational numbers is countable by showing that the function K is a one-toone correspondence between the set of positive rational numbers and the set of positive integers if
K(m/n) = p 2a1 1 p 2a2 2 p 2as s q 2b11 1 q 2b21 2 q
Prove that the set of positive rational numbers is countable by setting up a function that assigns to a
rational number p/q with gcd(p, q) = 1 the base 11 number formed by the decimal representation of p
followed by the base 11 digit A, which corresponds
Show that if a b (mod m) and c d (mod m), where a, b, c, d, and m are integers with m 2, then a c
b d (mod m).
Show that if n | m, where n and m are integers greater than 1, and if a b (mod m), where a and b are
integers, then a b (mod n).
Express in pseudocode the trial division algorithm for determining whether an integer is prime.
Prove that for every positive integer n, there are n consecutive composite integers. [Hint: Consider the n
consecutive integers starting with (n + 1)! + 2.]
Sh
Suppose that a and b are integers, a 11 (mod 19), and b 3 (mod 19). Find the integer c with 0 c 18
such that
a) c 13a (mod 19).
b) c 8b (mod 19).
c) c a b (mod 19).
d) c 7a + 3b (mod 19).
e) c 2a2 + 3b2 (mod 19).
f ) c a3 + 4b3 (mod 19).
1) Prove or disprove that if a | bc, where a, b, and c are positive integers and a = 0, then a | b or a |
c.
2) Show that if n and k are positive integers, then n/k = (n 1)/k + 1.
Show that Zm with addition modulo m, where m 2 is an integer, satisfies the closure, associative, and
commutative properties, 0 is an additive identity, and for every nonzero a Zm, m a is an inverse of a
modulo m
Show that the distributive property of mul
Show that if a and b are positive integers, then ab = gcd(a, b) lcm(a, b). [Hint: Use the prime
factorizations of a and b and the formulae for gcd(a, b) and lcm(a, b) in terms of these factorizations.]
How many divisions are required to find gcd(21, 34) u
. Adapt the proof in the text that there are infinitely many primes to prove that there are infinitely many
primes of the form 3k + 2, where k is a nonnegative integer. [Hint: Suppose that there are only finitely
many such primes q1, q2,.,qn, and consider
Constraint
Satisfaction
Problems
powered by FreeFind
Modified: 09/22/2004 02:49:02
Outline
CSP Examples
Backtracking search for CSPs
Problem structure and problem decomposition
Local search for CSPs
5.1 CONSTRAINT SATISFACTION PROBLEMS
CSP definitions
Var
Outline
7.1 KNOWLEDGE-BASED AGENTS
Example: Vaccum world
Knowledge Base
Initially rules and facts (e.g. if Status=Dirty then
Action=Suck)
TELL KB of percepts (e.g. Status=Dirty,
Location=A) and inference (e.g. Suck
ASK KB what to do based on rules and fac
Solving Problems by
Searching
powered by FreeFind
Modified: 09/02/2004 23:12:20
Outline
Problem-solving agents
Problem types
Problem formulation
Example problems
Basic search algorithms
3.1 PROBLEM-SOLVING AGENTS
Agent has map of Romania to guide journey
nternet
Python
Programming
powered by FreeFind
Modified: 09/23/2004 23:35:24
Overview
Adversarial programs must by nature communicate some shared state such as a chess board or
moves to a new state. Obviously, the problem is more interesting and realistic
Heapsort
1. Constructs an array satisfying the max-heap property.
2. Sorts the array in ascending order.
Note: A.length is the length of array A, which does not change.
A.heap-size is the size of the heap, which does change.
1 A.heap-size A.length
Heapsor
Binary tree - recursively defined on a finite set of nodes that either
contains no nodes
is composed of three disjoint sets of nodes:
root node
binary tree called the left subtree
binary tree called the right subtree
Examples
(b)
(a)
(c)
(d)
2
/
3
/
4
/
6
Build-Max-Heap
"Max" refers to the fact that this algorithm calls Max-Heapify, which guarantees that the
object the with the largest value is at the top of the heap.
Build-Max-Heap (A)
- alters A
- post: the tree rooted at location 1 in A satisfies the he
Uses:
Use recursion tree to determine a good asymptotic bound on the recurrence T(n) =
o
Sum the costs within each level of the tree to obtain a set of per-level costs.
o
Sum all the per-level costs to determine the total cost of all levels of recursion.
Definition
Asymptotic
a line that continually approaches a given curve but does not meet it at any finite
distance.
Example
x is asymptotic with x + 1
limit -
f(x) = k
Roughly translated might read as:
x approaches , f(x) approaches k
for x close to , f(x
Max heaps maintain the maximum heap value at array location 1.
A priority queue requires that the priority value be accessible at the head of the queue, location 1.
Example - The highest priority (max value) is array location 1.
Question 6.8
Suggest an al
Max-heap property
The max-heap property:
for every node i other than the root
A[ Parent( i ) ] A[ i ]
Note that the root is excluded as it has no parents.
The max-heap property means that the parent value child value
Max-Heapify
Max-Heapify function, give
4.3 OVERVIEW - Don't confuse with forward or backward substitution
Substitution as used here, refers to substituting a guess for a closed-end recurrence solution into
an induction proof.
To prove asymptotic bounds, or O, of the recurrence T(n) must show h
Sorting_Machine can be implemented by the sorting algorithms listed in the table below.
The actual work done to get the items sorted will be performed in one of the three
different sorting machine operations:
o
Insert
o
Extract
o
Change_To_Extraction_Pha
How fast can we sort?
We will prove a lower bound.
Why ( n ) as a lower bound?
Comparison sorting
The only operation that may be used to gain order information about a
sequence is comparison of pairs of elements.
if A[ i ] < A[ i + 1 ]
A[ i ] A[ i + 1]
Al
Definition
A heap can be defined as a binary tree with one key (value) assigned to each node provided the
following two requirements are met:
Tree shape - the binary tree is essentially complete; all levels are full
except possibly the last level where on
Note that tree here means binary tree.
A complete tree is a full tree.
1. There are at most 2h leaves in a binary tree of height h.
That is the nodes at the bottom level.
Base
h=1, no more than 21 = 2 leaves since a binary tree
IH
2h-1 leaves at most in b
Computing the limit of the ratio of two functions is another way to classify the growth of a
function.
What f(n) is in terms of O, , , o, and
f(n)/g(n
)
o
0
O
f(n)
O(g(n)
f(n)
(g(n)
f(n)
(g(n)
f(n)
o(g(n)
c
f(n)
(g(n)
Definition of O, , , o, and by
Assignment
1. Write down for each statement the number of times the statement is executed in the worst
case.
2. Compute T(n), i.e., the running time of Find_Largest, and simplify (if possible) by
combining terms.
3. What data produces the worst case? The