COMP 410 (Spring 2012)
COMP 410 (Spring 2012)
L ECTURE 1
Introduction
Computer science is all about abstractions Too complex to know everything abstractions simplify by hiding the details (and allow us to know about more things...) Example: electronic circuits bits bytes assembly But someone has to know the details; for DSs, you do Many examples in CS. The one well be discussing: data-structures or objects, which are data + operations Example: Arrays. Operations are create (declare; not in all languages). E.g., double[] A = new double[10]; retrieve e.g., x = A[i]; assign e.g., A[i] = 5.5; The standard representation, and a representation as (index, value) ordered pairs. Standard representation needs size to be known beforehand; but allows faster access(random access) Notion of preconditions: what if the index i in A[i] is > A.length?
Organizational details
The web-site: http://www.cs.unc.edu/baruah/Teaching/2012-1Sp/ TA: primarily grading responsibilities appointment by email. (TuTh 11:00 -12:00)
Expected background
Math (Proofs, etc. sections from book) Sec 1.1 (the selection problem) Sec 1.2 - Math Review 1.2.1-1.2.3, 1.2.5 (proofs) Sec 1.3 Recursion Fluency in programming (just the basics nothing fancy; e.g., no GUIs needed) Well have a test soon, after 3 lectures
= = = = =
+X
2N + 2 N
Sec 1.2.2: Logarithms (base 2, unless otherwise specied) Denition: logb n = k means that bk = n. (In base 2: (log n = k) (2k = n)) log AB log(AX ) = = log A + log B X log A
log 1 = 0; log 2 = 1; . . . , log 1024 = 10; . . . log 1000 10; log 106 20; log 109 30; . . . Sec 1.2.3: Series N
i=0
Ai =
AN +1 1 A1
(A = 1)
i=0
Ai ,
for A < 1
Some sums:
N i=1
1 2i i=0
= =
Sec 1.2.5: Proofs (particularly by induction) N Illustrating the technique by an example: i=1 i. k k(k+1) Let STMT(k) denote the statement i=1 i = 2 We wish to prove that STMT(k) is true for all k 0. Easy to prove for specic values of k (e.g., k = 0, k = 1, etc.) using simple algebra. The method of induction: Explicitly show STMT(k) is true for small values of k (base case) Assume STMT(k) is true for all values of k n (induction hypothesis), and use these to show STMT(n + 1) is true as well It then follows that STMT(k) is true for all n
N i=1
N i=1
i2 ik