Topics since last test More invariants Pixmap Sorting & Templates

Slides:



Advertisements
Similar presentations
CS 206 Introduction to Computer Science II 04 / 28 / 2009 Instructor: Michael Eckmann.
Advertisements

CS 206 Introduction to Computer Science II 12 / 09 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 12 / 05 / 2008 Instructor: Michael Eckmann.
Quicksort.
1 An Extremely Short Introduction to Computer Programming Mike Scott.
Duke University Computer Science 1 Why Computer Science is Uglier and Prettier than Mathematics Owen Astrachan Duke University
Lecture No.01 Data Structures Dr. Sohail Aslam
CompSci Topics since midterm l Java  Methods  Sound  Graphics l Software design  Recursion  Arrays  Copyright issues l Computer systems.
CPS Topics since last test l Recursion l Software design  Object-oriented  Copyright issues l Computer systems  Hardware  Architecture  Operating.
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.
CS 61B Data Structures and Programming Methodology July 28, 2008 David Sun.
Genome Revolution: COMPSCI 006G 1.1 FOCUS COMPSCI 006G Genome Revolution Owen Astrachan
CompSci CompSci 6 Programming Design and Analysis I Dietolf (Dee) Ramm
CPS Topics since last test l Recursion l Sound l Graphics l Software design  Object-oriented  Copyright issues l Computer systems  Hardware 
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.
Quicksort CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
CompSci 100e 13.1 Topics l Data Structures  Arrays ArrayLists  Linked Lists Circular Doubly-linked  Binary Trees Binary Search Trees AVL Trees Heaps.
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.
ICS201 Lecture 21 : Sorting King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science Department.
CS 367 Introduction to Data Structures Lecture 11.
Duke University Computer Science 1 Topics since last test l More invariants l Pixmap l Sorting & Templates  Selection sort  Insertion sort  Quicksort.
CPS Topics since last test l Graphics l Software design  Recursion  Arrays  Copyright issues l Computer systems  Hardware  Architecture  Operating.
Recursion Riley Chapter 14 Sections 14.1 – 14.5 (14.6 optional)
Final Exam Review CS 3358.
Prof. U V THETE Dept. of Computer Science YMA
Conclusions on CS3014 David Gregg Department of Computer Science
CSC317 Selection problem q p r Randomized‐Select(A,p,r,i)
CSE 374 Programming Concepts & Tools
CS 215 Final Review Ismail abumuhfouz Fall 2014.
CompSci 6 Introduction to Computer Science
Big-O notation.
CS 326 Programming Languages, Concepts and Implementation
Simple Sorting Algorithms
CompSci 101 Introduction to Computer Science
Introduction to Algorithms
Quicksort
Chapter 1-4 CSc 212 Data Structures, Sec AB CCNY, Spring 2012
Quicksort "There's nothing in your head the sorting hat can't see. So try me on and I will tell you where you ought to be." -The Sorting Hat, Harry Potter.
Arrays in C.
Data Structures and Algorithms
EE 193: Parallel Computing
structures and their relationships." - Linus Torvalds
Quicksort 1.
Last Class We Covered Data representation Binary numbers ASCII values
2008/12/03: Lecture 20 CMSC 104, Section 0101 John Y. Park
CSC212 Data Structure - Section RS
Quicksort analysis Bubble sort
Lesson Objectives Aims
Unit-2 Divide and Conquer
LESSON 13 – INTRO TO ARRAYS
Last Class We Covered Dictionaries Hashing Dictionaries vs Lists
Derived Classes in C++ Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition,
Searching and Sorting Topics Sequential Search on an Unordered File
Sub-Quadratic Sorting Algorithms
Topics since last test More invariants Pixmap Sorting & Templates
Quicksort.
Hank Childs, University of Oregon
CSE 373 Data Structures and Algorithms
Algorithms: Design and Analysis
Data Structures & Algorithms
CSC212 Data Structure - Section KL
CSC 143 Java Sorting.
Data Structures & Algorithms
Quicksort.
CSE 332: Sorting II Spring 2016.
COMS 261 Computer Science I
Algorithms CSCI 235, Spring 2019 Lecture 36 P vs
structures and their relationships." - Linus Torvalds
Quicksort.
Chapter 1-4 CSc 212 Data Structures, Sec FG CCNY, 2009
Presentation transcript:

Topics since last test More invariants Pixmap Sorting & Templates Selection sort Insertion sort Quicksort Loop invariants Complexity Function templates Operator overloading Dynamic data Pointers The new and selector (->) operators Passing as parameters Sharing and copying Inheritance Extending another class “Is a” relationship Polymorphism Employee example

The exam Saturday, May 4, 9am-12 noon in White Lecture Hall Almost half multiple choice Cumulative By Monday, April 28 at 9am: All grades up All solutions out Grade problems: submit_cps006 problems issues.txt Final grades up Sunday May 6 at noon

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

Computer Science vs. Engineering Describe Explain Engineering Build “An engineer can do for a dime what any fool can do for a dollar” Today, CS is mostly engineering

Essential concepts There is beauty at all levels of sophistication and all levels of abstraction. David A. Blackwell If life were really fair, algebra would actually come in handy Amstel Light commercial

On programming and deadlines Observe that for the programmer, as the chef, the urgency of the patron may govern the scheduled completion of task, but it cannot govern the actual completion. An omelette, promised in two minutes, may appear to be progressing nicely. But when it has not set in two minutes, the customer has two choices -- wait or eat it raw. Software customers have the same choices.. Fred Brooks We don’t have time to stop for gas -- we’re already late. Old software project planning proverb via Mike Cleron I love deadlines. I like the whooshing sound they make as they fly by. Douglas Adams

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

On education The college you attend does not determine the scope and possibility of your life’s achievements. It will have some influence, no doubt. What is more important is the encouragement that we, as parents and friends, offer these prospective students as they explore their own educational trail. In the end, the experiences they encounter and the depth of character they build along the way will mean far more than the name of the institution on their diploma. John Hennesy Education is not filling a bucket but lighting a fire. William Yeats

On education An education isn’t how much you have committed to memory, or even how much you know. It’s being able to differentiate between what you know and what you don’t. Anatole France The best way to have a good idea is to have lots of ideas. Linus Pauling If there is no struggle, there is no progress Frederick Douglass The ability to quote is a serviceable substitute for wit. W. Somerset Maugham

The selection problem In a list of N ordered items, find the kth smallest Highest salary, median, 90%, … Solve the problem, then solve it efficiently Suppose we can re-arrange the items Where is kth smallest? It’s x It’s before x It’s after x x <= x > x

The Selection Problem In a list of N ordered items, find the kth smallest Highest salary, median, 90%, … Solve the problem, then solve it efficiently double Select(tvector<double> & a, int left, int right, int k) // pre: left <= right // post: return k-th smallest in a[left..right] { if (left == right) return a[left]; int p = Partition(a, left, right); // re-arrange a int size = p – left + 1; // left sublist if (k <= size) return Select(a, left, p, k); else return Select(a, p+1, right, k-size); }

Partition, the picture and invariant x <= x > x The desired state, where we want to go x ? ? ? The initial state x <= x > x ?? p The intermediate state, and invariant

Partition: the code int Partition(tvector<int> & a, int left, int right) // pre: left <= right, and legal indices for a // post: return index and re-arrange elements in a // so a[left..index] <= a[index+1..right] { int p=left; int k; for(k=left+1; k <= right; k++) if (a[k] <= a[left]) p++; Swap(a[k], a[p]); } Swap(a[left],a[p]); return p; x <= x > x ?? p

Quicksort, the code Why is this fast? When is it slow? void QuickSort(tvector<int> & a, int left, int right) // pre: left <= right, and legal indices for a // post: a[left] <= … <= a[right] { if (left <= right) int p = Partition(a,left,right); QuickSort(a,left, p-1); QuickSort(a, p+1, right); } Why is this fast? When is it slow? Invented in 1960, hard to understand, why? Usable in mission critical applications? Introsort in 1998

Practice with invariants Remove zeros from an array, leave order of non-zeros unchanged (AP exam, 1987) Sketch/write a solution Make it run, make it right, make it fast 2 5 1 4 8 2 8 1 5 4 non-zeros ? ? ? (ignored) k lnz

Laws governing computer science Moore’s Law (1965) The number of transistors per area on a chip double every 18 months Density of transistors => more functionality and speed How about multiple computers? Amdahl’s Law (1967) Given: fraction (s) of work to be done is serial (i.e. isn’t parallelizable) Maximum speedup with infinite number of processors is 1/s

What are computers for? Simulation Communication among people Storage = communication across time Control Get physical Get real (time) Get mobile

Application Simulation Models of the real world (e.g. planets, cities, molecules) Communication among people Information at your fingertips Telepresence Home Control Robots Software agents

What’s next CPS 100 Data structures Efficiency Larger programs After that? Anything!