CPS 100 1.1 What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread.

Slides:



Advertisements
Similar presentations
Introduction to Computer Science Exam Information Unit 20.
Advertisements

Data Structures Introduction. What is data? (Latin) Plural of datum = something given.
CS /29/2004 (Recitation Objectives) and Computer Science and Objects and Algorithms.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
1 An introduction to design patterns Based on material produced by John Vlissides and Douglas C. Schmidt.
Abstraction: Polymorphism, pt. 1 Abstracting Objects.
1 CSC241: Object Oriented Programming Lecture No 07.
Computer Science and Software Engineering University of Wisconsin - Platteville 7. Inheritance and Polymorphism Yan Shi CS/SE 2630 Lecture Notes.
CPS 108 : Spring What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking.
Compsci 101, Spring COMPSCI 101, Spring 2012 Introduction to Computer Science Owen Astrachan
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
CPS 100, Fall COMPSCI 100, Fall 2011 Owen Astrachan w/ Michael Hewner
Teaching Teaching Discrete Mathematics and Algorithms & Data Structures Online G.MirkowskaPJIIT.
UNIVERSITI TENAGA NASIONAL “Generates Professionals” CHAPTER 4 : Part 2 INTRODUCTION TO SOFTWARE DEVELOPMENT: PROGRAMMING & LANGUAGES.
CPS What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread.
CPS What’s easy, hard, first? l Always do the hard part first. If the hard part is impossible, why waste time on the easy part? Once the hard part.
A Computer Science Tapestry 1 Recursion (Tapestry 10.1, 10.3) l Recursion is an indispensable technique in a programming language ä Allows many complex.
CPS 100, Spring COMPSCI 100, Spring 2010 Owen Astrachan
ITEC 2620A Introduction to Data Structures
Invitation to Computer Science, Java Version, Second Edition.
Computer Programming I An Introduction to the art and science of programming with C++
Introduction. 2COMPSCI Computer Science Fundamentals.
A Computer Science Tapestry 11.1 From practice to theory and back again In theory there is no difference between theory and practice, but not in practice.
Chapter 13 Recursion. Learning Objectives Recursive void Functions – Tracing recursive calls – Infinite recursion, overflows Recursive Functions that.
CompSci 100e 11.1 Sorting: From Theory to Practice l Why do we study sorting?  Because we have to  Because sorting is beautiful  Example of algorithm.
CSS446 Spring 2014 Nan Wang.  Java Collection Framework ◦ Set ◦ Map 2.
A Computer Science Tapestry 12.1 Tools for programming l Syntatic details of control and variables  If, while, switch, function calls  Scope and lifetime.
CPS 100, Fall COMPSCI 100, Fall 2009 Owen Astrachan
CPS Anagram: Using Normalizers l How can we normalize an Anaword object differently?  Call normalize explicitly on all Anaword objects  Have.
Programming Life Cycle Problem analysisunderstand the problem Requirements definition specify what program will do High- and low-level designhow it meets.
L11-12: Design Patterns Definition Iterator (L4: Inheritance)‏ Factory (L4: Inheritance)‏ Strategy (L5: Multiple Inheritance)‏ Composite (L6: Implementation.
Design Patterns Gang Qian Department of Computer Science University of Central Oklahoma.
CSC 212 – Data Structures Lecture 37: Course Review.
CompSci 100E 1.1 CompSci 100E Dietolf (Dee) Ramm Robert A. Wagner
Introduction to Programming (in C++) Sorting Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC.
CPS 100, Spring Tools: Solve Computational Problems l Algorithmic techniques  Brute-force/exhaustive, greedy algorithms, dynamic programming,
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
CPS What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread.
CPS 100, Spring COMPSCI 100, Spring 2009 Owen Astrachan
CPS Inheritance and the Yahtzee program l In version of Yahtzee given previously, scorecard.h held information about every score-card entry, e.g.,
1 CS April 2010 binary search, linear search insertion sort, selection sort, quick sort Do exercises on pp to get familiar with concepts.
CompSci Analyzing Algorithms  Consider three solutions to SortByFreqs, also code used in Anagram assignment  Sort, then scan looking for changes.
A Computer Science Tapestry 10.1 From practice to theory and back again In theory there is no difference between theory and practice, but not in practice.
Overview of C++ Polymorphism
CompSci Reading from Files  import java.io.File;  Declare a file File fileOfCats = new File(”cats.txt”);  Use file – pass it as an argument to.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
Compsci 06/101, Spring COMPSCI 06/101, Spring 2011 Introduction to Computer Science Owen Astrachan
CPS Review of Data Structures l We’ve studied concrete data structures/type (CDT)  Vectors Homogeneous aggregates supporting random access  Linked.
Welcome to Software Engineering. Lecture 1 Metaphysics of Software Engineering Alex
Genome Revolution: COMPSCI 006G 15.1 Recursion and Recursive Structures l Definition in the dictionary: in mathematics an expression in which a value is.
CPS 100e 5.1 Inheritance and Interfaces l Inheritance models an "is-a" relationship  A dog is a mammal, an ArrayList is a List, a square is a shape, …
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
Principles of Imperative Computation Lecture 1 January 15 th, 2012.
CPS Searching, Maps, Tables (hashing) l Searching is a fundamentally important operation  We want to search quickly, very very quickly  Consider.
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
CPS What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread.
CPS Anagram: Using Normalizers l How can we normalize an Anaword object differently?  Call normalize explicitly on all Anaword objects  Have.
CPS Searching, Maps, Tables l Searching is a fundamentally important operation ä We want to do these operations quickly ä Consider searching using.
CompSci 100 Prog Design and Analysis II
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
CompSci 100E cs. duke CompSci 100E Dietolf (Dee) Ramm
Introduction To Repetition The for loop
CompSci 100 Dietolf (Dee) Ramm
Lecture 2 of Computer Science II
Announcements Final Exam on August 17th Wednesday at 16:00.
Announcements Final Exam on August 19th Saturday at 16:00.
Why inheritance? shape mammal map
COP3530- Data Structures Introduction
Java String Class String is a class
COMPSCI 100, Spring 2008 Owen Astrachan
Presentation transcript:

CPS What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is the linking thread which gathers these disparate branches into a single discipline? My answer to these questions is simple --- it is the art of programming a computer. It is the art of designing efficient and elegant methods of getting a computer to solve problems, theoretical or practical, small or large, simple or complex. C.A.R. (Tony)Hoare

CPS Sir Hoare "…I first learned about recursive procedures and saw how to program the sorting method which I had earlier found such difficulty in explaining…Due credit must be paid to the genius of the designers of ALGOL 60 who included recursion in their language and enabled me to describe my invention so elegantly to the world." "I have learned more from my failures than can ever be revealed in the cold print of a scientific article and now I would like you to learn from them, too….failures are much more fun to hear about afterwards; they are not so funny at the time."

CPS Efficient design, programs, code Object-oriented design and patterns. Software design principles transcend language, but … Engineer, scientist: what toolkits do you bring to programming? Mathematics, design patterns, libraries --- standard and Tapestry Know data structures and algorithms. Trees, hashing, binary search, sorting, priority queues, greedy methods, … Using the language: C++ (or Java, or Python, or …), its idioms, its idiosyncracies

CPS Course Overview l Lectures, Recitations, Quizzes, Programs  Recitation based on questions given out in previous week Discuss answers, answer new questions, small quiz More opportunities for questions to be answered.  Lectures based on readings, questions, programs Online quizzes used to motivate/ensure reading In-class questions used to ensure understanding  Programs Theory and practice of data structures and OO programming Fun, practical, tiring, … Weekly programs and longer programs l Exams/Tests  Semester: closed book  Final: open book

CPS Questions If you gotta ask, you’ll never know Louis Armstrong: “What’s Jazz?” If you gotta ask, you ain’t got it Fats Waller: “What’s rhythm?” What questions did you ask today? Arno Penzias

CPS Tradeoffs Simple, elegant, quick, efficient: what are our goals in programming? What does XP say about simplicity? Einstein? How do we decide what tradeoffs are important? Tension between generality, simplicity, elegance, … Fast programs, small programs, run anywhere- at-all programs. Runtime, space, your time, CPU time… Programming, design, algorithmic, data- structural

CPS Code/hierarchy in readwords.cpp l Count number of different words in a vector, how? class WordStats { public: WordStats(){} // no state, nothing to do virtual ~WordStats(){} // make compiler happy virtual int uniqueCount(tvector v); }; class SetStats : public WordStats { public: int uniqueCount(tvector v) {…} };

CPS Tracking different/unique words l We want to know how many times ‘the’ occurs  Do search engines do this? Does the number of occurrences of “basketball” on a page raise the priority of a webpage in some search engines? Downside of this approach for search engines? l Constraints on solving this problem  We must read every word in the file (or web page)  Search for the word? Avoid counting twice? Store?  Are there fundamental limits on any of these operations? Where should we look for data structure and algorithmic improvements?

CPS What does this do? Why is it wrong? int WordStats::uniqueCount(tvector v) // post: returns # unique/different words in v { int count = 0; for(int k=0; k < v.size(); k++){ string word = v[k]; count++; for(int j=k+1; j < v.size(); j++){ if (v[j] == word){ string temp = v[j]; v[j] = v[v.size()-1]; v[v.size()-1] = temp; v.pop_back(); } return count; }

CPS Search: measuring performance l How fast is fast enough? bool search(const tvector & a, const string & key) // pre: a contains a.size() entries // post: return true if and only if key found in a { int k; int len = a.size(); for(k=0; k < len; k++) if (a[k] == key) return true; return false; } l C++ details: parameters? Return values? Vectors? l How do we measure performance of code? Of algorithm?  Does processor make a difference? G5? Itanium? 64-bit?

CPS Tradeoffs in processing and counting l Read words, then sort, determine # unique words?  frog, frog, frog, rat, tiger, tiger, tiger, tiger l If we look up words one-at-a-time and bump counter if we haven't seen a word, is this slower than previous idea?  How do we look up word, how do we add word l Are there kinds of data that make one approach preferable?  What is best case, worst case, average case?

CPS Benefits of inheritance, interfaces l Consider adding new algorithm for determining unique word count void doStats(tvector v, WordStats& stats) { CTimer timer; timer.Start(); int unique = stats.uniqueCount(v); timer.Stop(); cout << unique << " different words in "; cout << timer.ElapsedTime() << " sec." << endl; } Why can we pass different kinds of objects to doStats ?  Why is this an advantage?  Inheritance and late/dynamic binding

CPS Why inheritance? l Add new shapes easily without changing much code  Shape * s1 = new Circle();  Shape * s2 = new Square(); l abstract base class:  interface or abstraction  pure virtual function l concrete subclass  implementation  provide a version of all pure functions l “is-a” view of inheritance  Substitutable for, usable in all cases as-a shape mammal ScoreEntry FullHouse, LargeStraight User’s eye view: think and program with abstractions, realize different, but conforming implementations, don’t commit to something concrete until as late as possible

CPS Example of inheritance l What is behavior of a shape? void doShape(Shape * s) { cout area() << endl; cout perimeter() << end; s->expand(2.0); cout area() << endl; cout perimeter() << endl; } Shape * s1 = new Circle(2); Shape * s2 = new Square(4); Shape * s3 = new Rectangle(2,5); doShape(s1); doShape(s2); doShape(s3);

CPS Inheritance (language independent) l First view: exploit common interfaces in programming  Streams in C++, iterators in Tapestry classes Iterators in STL/C++ share interface by convention/templates  Implementation varies while interface stays the same l Second view: share code, factor code into parent class  Code in parent class shared by subclasses  Subclasses can override inherited method Subclasses can override and call l Polymorphism/late(runtime) binding (compare: static)  Function actually called determined when program runs, not when program is compiled

CPS Who is Alan Perlis? l It is easier to write an incorrect program than to understand a correct one l Simplicity does not precede complexity, but follows it l If you have a procedure with ten parameters you probably missed some l If a listener nods his head when you're explaining your program, wake him up l Programming is an unnatural act l Won first Turing award