Presentation is loading. Please wait.

Presentation is loading. Please wait.

Brian Mitchell - Drexel University MCS680-FCS 1 Brian Mitchell

Similar presentations


Presentation on theme: "Brian Mitchell - Drexel University MCS680-FCS 1 Brian Mitchell"— Presentation transcript:

1 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 1 Brian Mitchell http://www.mcs.drexel.edu/~bmitchel email: bmitchel@mcs.drexel.edu Drexel University Fall 1997 MCS680: Foundations Of Computer Science int MSTWeight(int graph[][], int size) { int i,j; int weight = 0; for(i=0; i<size; i++) for(j=0; j<size; j++) weight+= graph[i][j]; return weight; } 1111 n n O(1) O(n) Running Time = 2O(1) + O(n 2 ) = O(n 2 )

2 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 2 Introduction Instructor Brian Mitchell - “Brian” bmitchel@mcs.drexel.edu www.mcs.drexel.edu/~bmitchel (215)895-2668 Course Information Foundations of Computer Science (FCS) MCS 680 Section 510 Wednesday 6:00 - 9:00 PM Room Location: Curtis 250A Office Hours By Appointment Online Information www.mcs.drexel.edu/~bmitchel/course/mcs680-fcs Please check course web page several times per week. The web page will be my primary mechanism for communicating: Special and Emergency Information Syllabus Assignments Solutions to Problems

3 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 3 Introduction Course Objective –To provide a solid background in the theoretical and mathematical aspects of Computer Science Provide essential background knowledge that is required for success in other core computer science graduate courses Textbook A.V.Aho, J.D.Ullman, Foundations of Computer Science, W.H. Freeman and Co., 1995. Additional References H.R. Lewis, C.H. Papadimitriou, Elements Of The Theory Of Computation, Prentice Hall, 1981. T.H. Cormen, C.E. Leiserson & R.L. Rivest, Introduction To Algorithms, McGraw Hill, 1996.

4 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 4 Introduction Homework, Exams Assignments & Programming Projects: Homework sets consisting of 4-5 problems will be regularly assigned (consult web page). Based on difficulty, you will have 1-2 weeks to complete each assignment. Some assignments might require you to write a small program or a program fragment. For this course you may develop programming solutions using the ‘C’, ‘C++’ or Java programming languages Midterm: A 90 minute midterm exam will be given during the 5th or 6th week of the course. Final: A 2 hour final exam will be given during our regularly scheduled class time on finals week.

5 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 5 Introduction Grading –The following distribution will be used to determine your final grade in this course: 50%: Homework & Programming Projects 20%: Midterm Exam 30%: Final Exam Policies –All homework and programming assignments are individual efforts, unless specifically stated otherwise in the assignment definition. You may use your colleagues for advice, however, all assignments must be your original work –Late assignments will be penalized 10% per week. Any assignment not submitted within 2 weeks of the deadline will not be accepted unless you work out special arrangements with me.

6 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 6 Introduction Tentative List Of Topics –Summation and Logarithm Review –Ineration, Induction & Recursion –Big-Oh Analysis –Running Time –Recurrence Relations –Trees (Mathematical Aspects & Algorithms) –Sets –Graph Theory & Graph Algorithms –Relations –Automata –Regular Expressions –Context Free Grammars –Propositional Logic –Predicate Logic

7 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 7 Summations Algorithms often contain an interative control construct –Loops (while, for, do…while) –Algorithm analysis can be performed by examining the sum of the times spent on each execution of the loop –Example: What is the value of i?  n j=1 j = 1+2+…+(n-1)+n int i; for (i=1; i<=n; i++) { i += i; }

8 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 8 Summations Properties of sums ajaj =  n j=1 ajaj   j=1 lim n  If the limit does not exist, the sum diverges; otherwise, it converges.  n j=1 ca j + db j =  n j=1 ajaj c+ dbjbj  n j=1 Summations obey the linearity property

9 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 9 Common Summations  n j=1 j = n(n+1) 2  n j=0 x j = x n+1 - 1 x-1  n j=1 a j - a j-1 = a n - a 0  n-1 j=0 a j - a j+1 = a 0 - a n  n j=1 c = n c

10 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 10 Summation Example Consider: int foo(int n) { int i,j,k; for (i=1; i<=n; i++) for(j=1; j<=n; j++) k += i + j; } How much time is spent performing the addition operations in the above code fragment if an add operation takes 2 clock cycles on a Pentium 120Mhz microprocessor?  n i=1  n j=1 addOps =  n addOps n i=1 = n 2 addOps On a 120Mhz microprocessor each clock cycle takes 8.3333 ns. (10 -9 seconds). Thus the total amount of time the code fragement spends adding is: = n 2 (2 8.3333E-9) = 16.667n 2 ns.

11 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 11 Summation Example- Results

12 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 12 Summation Example int foo(int n) { int i,j,k; for (i=1; i<=n; i++) for(j=1; j<=n; j++) k += (i + j); } What is the value of k?

13 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 13 Summation Example int foo(int n) { int i,j,k; for (i=1; i<=n; i++) for(j=1; j<=i; j++) k += (i + j); } What is the value of k?

14 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 14 Logarithms Logarithms appear often during the analysis of algorithms –General form: log b x b is the base of the logarithm if b is not specified then 10 is assumed –Definition: The logarithm to the base b of x represents the power to which b must be raised to produce x –Examples:log 2 8 = 3 (since 2 3 = 8) log 3 81 = 4 (since 3 4 = 81) log 10 1 = 0 (since 10 0 = 1) –During the analysis of algorithms, log 2 x appears often We will use lg x to represent log 2 x

15 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 15 Logarithms Notation –lg n = log 2 n = (log n / log 2) –ln n = log e n Identities –log b 1 = 0 –log b k n = (log b n) k –log b log b n = log b (log b n) –log b (a/c) = log b a - log b c –log b n = (1/ log n b) –log c n = (log arb n / log arb c) - c is any base –log b (1/n) = - log b n –log b n r = r log b n –log b nj = log b n + log b j –a = b log b a –a log b n = n log b a

16 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 16 Logarithms Logarithmic algorithms grow slowly with respect to the amount of input data: –Bubble sort growth  n 2 –Quick sort growth  n lg n

17 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 17 Data Models, Data Structures & Algorithms Data Models –Abstractions used to formulate problems –Any mathematical concept can be treated as a data model Values that the data objects can assume Operations on the data –Programming languages (‘C/C++’, Pascal, Java...) support primitive data models Integers, floating point, strings, chars,... Operations: +, -, /, *, %,, =, ==... However there are other important data models –Sets, graphs, trees, expressions –These data models are mathematically understood, however, most programming languages do not provide intrinsic support

18 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 18 Data Models, Data Structures & Algorithms Data Structures Most programming languages do not directly support important data models –Must represent the needed data model by using abstractions that are supported by the language Data structures are methods for representing a data model in a programming language Consider the following weighted and directed graph: A B C D

19 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 19 Data Structures A B C D This graph can be represented in a table: ABCDABCD A0001A0001 B4000B4000 C3200C3200 D0600D0600 1 6 4 3 2 A table can be represented in a computer language as a two-dimensional array: int graph[4][4];... graph[0][1] = 4; graph[0][2] = 3; graph[1][2] = 2; graph[1][3] = 6; graph[3][0] = 1;

20 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 20 Algorithms Precise an unambiguous specification of a sequence of steps that can be carried out automatically In Computer Science, algorithms are expressed using programming languages Consider an algorithm for calculating the total weight of a graph. –Our data structure is a two-dimensional graph int GraphWeight(int graph[][], int size) { int i,j,weight; weight = 0; for(i=0; i<size; i++) for(j=0; j<size; j++) weight+= graph[i][j]; return weight; }

21 Brian Mitchell (bmitchel@mcs.drexel.edu) - Drexel University MCS680-FCS 21 Running Times Of Algorithms Desire to analyze algorithm running time Used to determine how “good” an algorithm performs –Inputs of various sizes –Best Case –Worst Case –Average Case –Bounding Performance We use “Big-Oh” analysis to model running time (also known as execution complexity) –O(n) –O(n 2 ) –O(2 n ) –O(n log n) –O(n lg n)


Download ppt "Brian Mitchell - Drexel University MCS680-FCS 1 Brian Mitchell"

Similar presentations


Ads by Google