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
Chapter 4 Computation Bjarne Stroustrup
Advertisements

Announcements You survived midterm 2! No Class / No Office hours Friday.
ECS 15 if and random. Topic  Testing user input using if statements  Truth and falsehood in Python  Getting random numbers.
A Computer Science Tapestry 1.1 What is Computer Science? What is it that distinguishes it from the separate subjects with which it is related? What is.
Chapter 2: Algorithm Discovery and Design
Tirgul 8 Universal Hashing Remarks on Programming Exercise 1 Solution to question 2 in theoretical homework 2.
1 CSC241: Object Oriented Programming Lecture No 07.
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 100E 7.1 Solving Problems: Anagrams/Jumbles  How do humans solve puzzles like that at  Is it important to get computers.
Compsci 101, Spring COMPSCI 101, Spring 2012 Introduction to Computer Science Owen Astrachan
1 CSC 221: Introduction to Programming Fall 2012 course overview  What did you set out to learn?  What did you actually learn?  Where do you go from.
CPS 100, Fall COMPSCI 100, Fall 2011 Owen Astrachan w/ Michael Hewner
Object Oriented Data Structures
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.
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 17, 2013 Carolyn Seaman University of Maryland, Baltimore County.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Recursion, Complexity, and Searching and Sorting By Andrew Zeng.
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
Compsci 06/101, Fall COMPSCI 06/101, Fall 2010 Owen Astrachan Robert Duvall
Invitation to Computer Science, Java Version, Second Edition.
Algorithms and their Applications CS2004 ( ) Dr Stephen Swift 1.2 Introduction to Algorithms.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Chapter 13 Recursion. Learning Objectives Recursive void Functions – Tracing recursive calls – Infinite recursion, overflows Recursive Functions that.
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
CSIS 123A Lecture 9 Recursion Glenn Stevenson CSIS 113A MSJC.
Genome Revolution: COMPSCI 006G 1.1 FOCUS COMPSCI 006G Genome Revolution Owen Astrachan
CompSci CompSci 6 Programming Design and Analysis I Dietolf (Dee) Ramm
CompSci 100E 1.1 CompSci 100E Dietolf (Dee) Ramm Robert A. Wagner
Software Design 14.1 CPS 108 l Object oriented design and programming of medium-sized projects in groups using modern tools and practices in meaningful.
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.
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
CompSci Analyzing Algorithms  Consider three solutions to SortByFreqs, also code used in Anagram assignment  Sort, then scan looking for changes.
Complexity & Computability. Limitations of computer science  Major reasons useful calculations cannot be done:  execution time of program is too long.
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.
Chapter 10 Algorithmic Thinking. Learning Objectives Explain similarities and differences among algorithms, programs, and heuristic solutions List the.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
INVITATION TO Computer Science 1 11 Chapter 2 The Algorithmic Foundations of Computer Science.
Compsci 06/101, Spring COMPSCI 06/101, Spring 2011 Introduction to Computer Science Owen Astrachan
CPS What's a pointer, why good, why bad? l Pointer is a memory address, it's an indirect reference to memory or an object.  Rather than say we.
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 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 Searching, Maps, Tables l Searching is a fundamentally important operation ä We want to do these operations quickly ä Consider searching using.
CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014 Design and Analysis of Algorithms.
Winter 2016CISC101 - Prof. McLeod1 CISC101 Reminders Assignment 5 is posted. Exercise 8 is very similar to what you will be doing with assignment 5. Exam.
Data Structures and Algorithm Analysis Dr. Ken Cosh Linked Lists.
CPS Searching, Maps, Tables (hashing) l Searching is a fundamentally important operation  We want to search quickly, very very quickly  Consider.
CompSci Toward understanding data structures  What can be put in a TreeSet?  What can be sorted?  Where do we find this information?  How do.
Welcome to Software Engineering
Java Arrays Fixed size, once created
CompSci 100 Dietolf (Dee) Ramm
Announcements HW6 due this Wednesday
CompSci 6 Introduction to Computer Science
Anagrams/Jumbles How do humans solve puzzles like that at
Lecture 2 of Computer Science II
Announcements Final Exam on August 17th Wednesday at 16:00.
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
Announcements Final Exam on August 19th Saturday at 16:00.
Announcements HW6 due this Wednesday
Algorithm Discovery and Design
From practice to theory and back again
Announcements Final Exam on December 25th Monday at 16:00.
CSC 321: Data Structures Fall 2018
Program Design and Analysis II Professor: Jeffrey Forbes
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 Why is programming fun? What delights may its practitioner expect as a reward? First is the sheer joy of making things Second is the pleasure of making things that are useful Third is the fascination of fashioning complex puzzle-like objects of interlocking moving parts Fourth is the joy of always learning Finally, there is the delight of working in such a tractable medium. The programmer, like the poet, works only slightly removed from pure thought- stuff. Fred Brooks

CPS Efficient Programming l Designing and building efficient programs efficiently requires knowledge and practice  Hopefully the programming language helps, it’s not intended to get in the way  Object-oriented concepts, and more general programming concepts help in developing programs  Knowledge of data structures and algorithms helps l Tools of the engineer/scientist/programmer/designer  A library or toolkit is essential, STL or wheel re-invention?  Programming: art, science, engineering? None or All?  Mathematics is a tool  Design Patterns are a tool

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 l If you gotta ask, you’ll never know  Louis Armstrong: “What’s Jazz?” l If you gotta ask, you ain’t got it  Fats Waller: “What’s rhythm?” l What questions did you ask today?  Arno Penzias

CPS Tradeoffs l This course is about all kinds of tradeoffs: programming, structural, algorithmic  Programming: simple, elegant, quick to run/to program Tension between simplicity and elegance?  Structural: how to structure data for efficiency What issues in efficiency? Time, space, programmer-time  Algorithmic: similar to structural issues l How do we decide which choice to make, what tradeoffs are important?

CPS See readwords.cpp l This reads words, how can we count different/unique words? tvector list; string filename,word; cin >> filename; ifstream input(filename.c_str()); CTimer timer; timer.Start(); while (input >> word) { list.push_back(word); } timer.Stop(); cout << "read " << list.size() << " words in "; cout << timer.ElapsedTime() << " seconds" << endl;

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)  We must search to see if the word has been read before  We must process the word (bump a count, store the word)  Are there fundamental limits on any of these operations? Where should we look for data structure and algorithmic improvements?

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? PIII, G4, ???

CPS Tradeoffs in reading and counting l Read words, then sort, determine # unique words?  frog, frog, frog, rat, tiger, tiger, tiger, tiger l If we look up words as we're reading them and bump a counter if we find the 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? l What's one function spec & implememtation to count # unique words in a list/vector of words  See readwords3.cpp

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

CPS Review/Preview: Anagrams/Jumbles l Brute-force approach to finding anagrams/solving Jumbles  Brute-force often thought of as “lack of thought”  What if the better way requires too much thought?  What if there’s nothing better? l nelir,nelri, neilr, neirl, nerli, neril, nleir, nleri, nlier, nlire, nlrei, nlrie, nielr, nierl, niler, nilre, nirel, … lenir, lenri, leinr, leirn, lerni, lerin, liner  What’s the problem here?  Is there a better method?

CPS Brute force? permana.cpp // find anagram of word in wordSource // list is a vector [0, 1, 2, …, n] Permuter p(list); int count = 0; string copy(word);// makes copy the right length for(p.Init(); p.HasMore(); p.Next()) { p.Current(list); for(k=0; k < list.size(); k++) { copy[k] = word[list[k]]; } if (wordSource.contains(copy)) { cout << "anagram of " << copy << endl; break; // find first anagram only }

CPS Quantifying brute force for anagrams l On one machine make/test a word takes seconds/word  9! is 362,880: how long does this take?  What about a ten-letter word? l We’re willing to do some pre-processing to make the time to find anagrams quicker  Often find that some initialization/up-front time or cost saves in the long run  We need a better method than trying all possible permutations  What properties do words share that are anagrams?

CPS Toward a faster anagram finder l Words that are anagrams have the same letters; use a letter fingerprint or signature/histogram to help find anagrams  Count how many times each letter occurs: “teacher” “cheater” l Store words, but use fingerprint for comparison when searching for an anagram  How to compare fingerprints using operator ==  How to compare fingerprints using operator < l How do we make client programmers unaware of fingerprints? Should we do this?

CPS Another anagram method l Instead of fingerprint/histogram idea, use sorted form of word  “gable” and “bagel” both yield “abegl”  Anagrams share same sorted form l Similarities/differences to histogram/fingerprint idea?  Both use canonical or normal/normalized form  Normalized form used for comparison, not for printing  When should this normal form be created? l When is one method preferred over the other?  Big words, little words? Different alphabets? DNA vs English?

CPS OO and C++ features we’ll use l We’ll use an adapter or wrapper class called Anaword instead of a string  Clients can treat Anaword objects like strings, but the objects are better suited for finding anagrams than strings  The Anaword for “bear” prints as “bear” but compares to other Anaword objects as l C++ allows us to overload operators to help, not necessary but good cosmetically  Relational operators == and < What about other operators: >, =, and !=  Stream operator << l How should we implement overloaded operators?

CPS Overloaded operators l In C++ we can define what operator == and operator < mean for an object (and many other operators as well)  This is syntactically convenient when writing code  C++ details can be cumbersome (see Tapestry Howto E) In anaword.h there are four overloaded operators  What about > and >= ; what about != ; others?  What about printing, can we overload operator << ?  How do we access private data for printing? Comparing? l Overloaded operators are not necessary, syntactic sugar.

CPS Overloaded operators (continued) l Typically operators need access to internal state of an object  Relational operators for Date, string, BigInt?  Where is “internal state”? l For technical reasons sometimes operators should not be member functions: BigInt b = enterBigValue(); if (b < 2) … if (2 > b) …  We’d like to use both if statements, only the first can be implemented using BigInt::operator < (why?) l Use helper member functions: equals, less, toString  Implement overloaded operators using helpers

CPS Anaword objects with options l Can we use different canonical forms in different contexts?  Could have Anaword, FingerPrintAnaword, SortAnaword  What possible issues arise? What behavior is different in subclasses? If there’s no difference in behavior, don’t have subclasses l Alternative, make canonical/normalize method a class  Turn a function/idea into a class, then let the class vary to encapsulate different methods  Normalization done at construction time or later  Where is normalizer object created? When?