Duke University Computer Science 1 Topics since last test l More invariants l Pixmap l Sorting & Templates  Selection sort  Insertion sort  Quicksort.

Slides:



Advertisements
Similar presentations
CSE 160 – Lecture 9 Speed-up, Amdahl’s Law, Gustafson’s Law, efficiency, basic performance metrics.
Advertisements

CS 106 Introduction to Computer Science I 02 / 29 / 2008 Instructor: Michael Eckmann.
21/3/00SEM107- Kamin & ReddyClass 15 - Recursive Sorting - 1 Class 15 - Recursive sorting methods r Processing arrays by recursion r Divide-and-conquer.
CS 206 Introduction to Computer Science II 04 / 28 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 12 / 09 / 2009 Instructor: Michael Eckmann.
@ Zhigang Zhu, CSC212 Data Structure - Section FG Lecture 19 Searching Instructor: Zhigang Zhu Department of Computer Science City College.
CS 206 Introduction to Computer Science II 12 / 05 / 2008 Instructor: Michael Eckmann.
Reviews for Exam 1 Chapter 1-4 CS 211 Data Structures MHC, 2007.
Quicksort. Quicksort I To sort a[left...right] : 1. if left < right: 1.1. Partition a[left...right] such that: all a[left...p-1] are less than a[p], and.
Quicksort.
CS 206 Introduction to Computer Science II 12 / 03 / 2008 Instructor: Michael Eckmann.
Quicksort
Algorithms and Efficiency of Algorithms February 4th.
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
CS 206 Introduction to Computer Science II 12 / 08 / 2008 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 10 / 15 / 2007 Instructor: Michael Eckmann.
1 An Extremely Short Introduction to Computer Programming Mike Scott.
(c) , University of Washington
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.
1 Data Structures and Algorithms Sorting. 2  Sorting is the process of arranging a list of items into a particular order  There must be some value on.
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
A Computer Science Tapestry 1 Recursion (Tapestry 10.1, 10.3) l Recursion is an indispensable technique in a programming language ä Allows many complex.
CompSci Topics since midterm l Java  Methods  Sound  Graphics l Software design  Recursion  Arrays  Copyright issues l Computer systems.
Computer Science Searching & Sorting.
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.
COMP Recursion, Searching, and Selection Yi Hong June 12, 2015.
CS 61B Data Structures and Programming Methodology July 28, 2008 David Sun.
Lesson Objective: Understand what an algorithm is and be able to use them to solve a simple problem.
CompSci 100e Program Design and Analysis II April 26, 2011 Prof. Rodger CompSci 100e, Spring20111.
Parallel Processing Sharing the load. Inside a Processor Chip in Package Circuits Primarily Crystalline Silicon 1 mm – 25 mm on a side 100 million to.
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 What can be computed l What class of problems can be solved? ä Google Datacenter, Desktop computer, Cell phone, pencil? ä Alan Turing proved.
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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Data Structures - CSCI 102 Selection Sort Keep the list separated into sorted and unsorted sections Start by finding the minimum & put it at the front.
ICS201 Lecture 21 : Sorting King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science Department.
Quicksort Quicksort is a well-known sorting algorithm that, in the worst case, it makes Θ(n 2 ) comparisons. Typically, quicksort is significantly faster.
CS 367 Introduction to Data Structures Lecture 11.
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.
Hardware Trends CSE451 Andrew Whitaker. Motivation Hardware moves quickly OS code tends to stick around for a while “System building” extends way beyond.
Hardware Trends CSE451 Andrew Whitaker. Motivation Hardware moves quickly OS code tends to stick around for a while “System building” extends way beyond.
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)
CSC317 Selection problem q p r Randomized‐Select(A,p,r,i)
CS 215 Final Review Ismail abumuhfouz Fall 2014.
CompSci 6 Introduction to Computer Science
Introduction to Algorithms
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.
Data Structures and Algorithms
EE 193: Parallel Computing
Quicksort 1.
2008/12/03: Lecture 20 CMSC 104, Section 0101 John Y. Park
Sub-Quadratic Sorting Algorithms
Topics since last test More invariants Pixmap Sorting & Templates
Quicksort.
CSE 373 Data Structures and Algorithms
Algorithms: Design and Analysis
Topics since last test More invariants Pixmap Sorting & Templates
CSC 143 Java Sorting.
Data Structures & Algorithms
Quicksort.
CSE 332: Sorting II Spring 2016.
Quicksort.
Presentation transcript:

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

Duke University Computer Science 2 The exam l Saturday, May 4, 9am-12 noon in White Lecture Hall l Almost half multiple choice l Cumulative l 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

Duke University Computer Science 3 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

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

Duke University Computer Science 5 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

Duke University Computer Science 6 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

Duke University Computer Science 7 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

Duke University Computer Science 8 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

Duke University Computer Science 9 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

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

Duke University Computer Science 11 The Selection Problem l In a list of N ordered items, find the k th smallest  Highest salary, median, 90%, …  Solve the problem, then solve it efficiently double Select(tvector & 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); }

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

Duke University Computer Science 13 Partition: the code int Partition(tvector & 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

Duke University Computer Science 14 Quicksort, the code void QuickSort(tvector & 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); } l Why is this fast? When is it slow?  Invented in 1960, hard to understand, why?  Usable in mission critical applications? Introsort in 1998

Duke University Computer Science 15 Practice with invariants l Remove zeros from an array, leave order of non- zeros unchanged (AP exam, 1987) l Sketch/write a solution  Make it run, make it right, make it fast non-zeros ? ? ? (ignored) k lnz

Duke University Computer Science 16 Laws governing computer science l Moore’s Law (1965)  The number of transistors per area on a chip double every 18 months  Density of transistors => more functionality and speed l How about multiple computers? l 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

Duke University Computer Science 17 What are computers for? l Simulation l Communication among people  Storage = communication across time l Control  Get physical  Get real (time)  Get mobile

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

Duke University Computer Science 19 What’s next l CPS 100  Data structures  Efficiency  Larger programs l After that?  Anything!