Exercise 1
a) Define token attributes of the following, Z = 2x * y + x
b) Define token attributes of the following (i.e show Identifiers, keywords,
numbers etc. )
i) If (A+3<400) A = 0;
Else B = AA
ii) #include<stdio.h>
void maincfw_
cfw_
int x,y,z;
print
Lexical Analysis(Finite Automata)
Finite Automata
A finite automaton (FA) is a simple idealized machine used to
recognize patterns within input taken from some character set
(or alphabet) C.
The job of an FA is to accept or reject an input depending on
Code Generator
Issues in the Design of a Code
Generator
Input to the code generator
Target programs
Memory management
Instruction selections
Register allocation
Choice of evaluation order
Input to the code generator
Intermediate representation of t
Compiler; it is a program that translates source program to target program.
Interpreter; a program that reads the source program and produces the results of executing the
source.
Qualities of a compiler
1.
2.
3.
4.
5.
6.
7.
Works well with the debugger
Ge
Computer Science 2620, CRN 31005 Fundamentals of Programming II
Course Outline Fall 2014
Time of Lectures:
TuTh 12:15 13:30
Room: D633
Instructor:
Dr. S. Hossain
Office: C576
Academic Assistant:
Arie Bomhoff
Office: C510
Text:
C+ From the Beginning
by Jan
Binary search
When the list elements are ordered
Given a list A
Ordered means it can be non decreasing order, a0 >= a1 >= an-1
How many times is the while loop iterated?
Answer:
The while loop is exited when left > right , left and right are moving toward
Homework 3 (Solutions)
(1) We get
84
=
22 3 7
846 = 2 3 141
111 = 3 37.
(2) Let n be a number with exactly three divisors. Let n = p1 p2 pk be
1
2
k
its prime factorization. Then we get
3=
(i + 1).
Since 3 is prime we get that i + 1 = 1 for all but one of
Homework 2
(Due: Thursday Feb 9th)
(1) Calculate (n 1)! mod n for n cfw_2, 3, 4, 5, 6, 7, 8, 9, 10, 11.
(2) Find the remainder of
1! + 2! + 3! + + 100!
(3)
(4)
(5)
(6)
when it is divided by
(a) 2
(b) 7
(c) 12
(d) 25
(Hint: Most of the terms are congruent
Homework 8
(1)
(2)
(3)
(4)
Show that there is no positive integer n such that (n) = 14.
Find all positive integers n such that (n)|n.
Show that if m and n are positive integers with m|n, then (m)|(n).
An integer n is perfect if (n) = n. For example
(6) =
Homework 10 Solutions
(1) Note that x is a primitive root if it has order 6 modulo 7. To make sure
x has order 6, it suces to check that does not have order dividing 3 or
2. So, we need to check if x3 and x2 are equivalent to 1 modulo 7. The
following tab
Homework 1
(Due: Thursday Jan 19th)
(1) Assume that there is a surjective map : N S. Show that the map
: S N given by (s) = min 1 (s) is injective.
(2) Assume that : S N is injective. Show that there is a surjective map
: N S. Conclude that subset of a
Homework 2
(Due: Thursday Jan 26th)
Recall that we say a and b are coprime to each other if their greatest common
divisor is 1.
(1) For a given prime p, how many positive integers less than p are coprime to
p?
(2) For a given odd prime p, how many positiv
This is a quick example of Hensels lemma.
Say we want to solve the equation f (x) = x3 + 8x 5 0 (mod p3 ) where p = 5.
We can check that f (0) 0 (mod p). Also f (0) 3 (mod p).
Here is one way of doing this: Let x1 = 0. Let x2 = 0 + pt (since we know
x2 x1
Homework 5 - Solutions
(1) Given a, c, and m, the linear congruence ax c (mod m) is satised if and
only if there is an integer y such that ax + my = c.
Note that the solutions to ax + my = c can be solved using Euclids
algorithm. In some of the easier cas
Homework 7
(1) Find the last digit of the decimal expansion of 71000 .
(2) Show that if a is an integer such that a is not divisible by 3 or such that a
is divisible by 9, then a7 a (mod 63).
(3) Show that a(b) +b(a) 1 (mod ab), if a and b are relatively
Homework 6 - Solutions
(1) Let f (x) = x3 + 8x2 x 1.
(a) Checking all congruences we get that x 4, 5 (mod 11).
(b) We apply Hensels lemma to the two roots x 4 and 5 (mod 11).
x 4 (mod 11) First note that f (4) = 111 1 (mod 11). Therefore, a = 1 is
an inve
Homework 5: Due Nov 29th (Thursday)
(1) Evaluate the limits (note i, j, and k are the three basis vectors in R3 ):
(a) lim (t2 , 4t, 1/t)
t3
(b) lim (e2t i + ln(t + 1)j + 4k).
t0
r(t)
where r(t) = (sin(t), 1 cos(t), 2t).
t
Compute the following:
(a) r (t)
(1) (a) Let
(b) Let
(c) Let
(2) Suppose
Sample midterm 1
an = n n. What is a5 ?
br = 2ar . What is b2 ?
ck = ak ak+1 . Find a formula for ck .
that lim an = 4 and lim bn = 2. Determine
2
n
n
(a) lim an /bn
n
(b) lim sin(b2 )
n
n
(c) lim an2
n
(3) Let a0 =
Sample nal
(1) True or False
(a) There are convergent sequences that are not monotonic.
(b) If lim an = 10 then there is an integer N such that 9.9 < aN < 10.1.
n
(c) There is a sequence an so that a1 = a2 = a3 = = a10 = 1, but
lim an = 0.
n
(d) If 0 < li
Sample midterm 2
(1) The following sequences are convergent. Find their limits.
(a) an = nn+1 .
2
(b) an = n1/n .
(c) a1 = 1, and an+1 = 2 + an for n > 1.
(2) Which of these series converge and why.
n
(a)
log
n+1
n=1
(b)
n
3n
n=1
(c)
1
n(log n + 1)
n=1
1
Homework 5: Due Nov 20th (Tuesday)
x2n
Show that F (x) has innite radius of convergence.
2n n!
n=0
(2) Find the power series for f (x) = x log(1 + x ).
2
1
(3) Find the rst three terms of the Taylor series of f (x) = 1+tan x around 0.
(4) Evaluate
2n
(1)