CS100J Nov 04, 2003 Arrays. Reading: 8

Slides:



Advertisements
Similar presentations
CS 1031 Recursion (With applications to Searching and Sorting) Definition of a Recursion Simple Examples of Recursion Conditions for Recursion to Work.
Advertisements

SEARCHING AND SORTING HINT AT ASYMPTOTIC COMPLEXITY Lecture 9 CS2110 – Spring 2015 We may not cover all this material.
1 CS100J 13 March 2006 Arrays. Reading: Secs 8.1, 8.2, 8.3. Listen to the following lectures on loops on your Plive CD. They are only 2-3 minutes long,
CS100J Nov 04, 2003 Arrays --sorting. Reading: 8.5 Please punctuate this: Dear John, I want a man who knows what love is all about you are generous kind.
1 CS100J 27 March 2007 Algorithms on arrays Reading: 8.3–8.5 Please punctuate this: Dear John, I want a man who knows what love is all about you are generous.
1 CS100J October 06, 2005 For Loops Reading: Secs Quote for the Day: Perhaps the most valuable result of all education is the ability to make yourself.
CS 1110 Prelim III: Review Session 1. Info My name: Bruno Abrahao – We have two other TA’s in the room to help you individually Beibei Zhu Suyong Zhao.
1 Teaching the development of algorithms Teach skill, not only facts David Gries Computer Science Department Cornell University November 2004 DrJava is.
CS 106 Introduction to Computer Science I 03 / 07 / 2008 Instructor: Michael Eckmann.
1 Recitation 7. Developing loops Introduction. This recitation concerns developing loops using their invariants and bound functions. Your recitation instructor.
1 Assignment 6. Developing Loops Due on Tuesday, 30 October, by midnight (submitted electronically). Note that each question will be graded on the following.
1 CS100J 25 October 2006 Arrays. Reading: Secs 8.1, 8.2, 8.3. Listen to the following lectures on loops on your Plive CD. They are only 2-3 minutes long,
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
1 CS100J 29 March 2007 Arrays: searching & sorting. Reading: 8.5 Why did I get a Christmas Card on Halloween? Searching and sorting algorithms are on the.
Reading and Writing Mathematical Proofs
1 CS100J 31 October 2006 Arrays: searching & sorting. Reading: 8.5 Merry Christmas!! On Halloween? Searching and sorting algorithms are on the course website.
1 On (computational) simplicity We are trying to teach not just Java, but how to think about problem solving. Computer science has its field called computational.
CS November 2010 Developing array algorithms. Reading: Haikus (5-7-5) seen on Japanese computer monitors Yesterday it worked. Today it is.
1 CS April 2010 binary search, linear search insertion sort, selection sort, quick sort Do exercises on pp to get familiar with concepts.
Dr. Naveed Riaz Design and Analysis of Algorithms 1 1 Formal Methods in Software Engineering Lecture # 26.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
1 CS April 2009 Sorting: insertion sort, selection sort, quick sort Do exercises on pp to get familiar with concepts and develop skill.
1 CS1110 Lecture 16, 26 Oct 2010 While-loops Reading for next time: Ch (arrays) Prelim 2: Tu Nov 9 th, 7:30-9pm. Last name A-Lewis: Olin 155 Last.
Lecture 2 What is a computational problem? What is an instance of a problem? What is an algorithm? How to guarantee that an algorithm is correct? What.
Chapter 3: Sorting and Searching Algorithms 3.1 Searching Algorithms.
CS100A, Fall Review of loops 1 CS100A, Fall 1998, Review of Loops and Loop Invariants Some students are still having trouble understanding loop invariants.
CORRECTNESS ISSUES AND LOOP INVARIANTS Lecture 8 CS2110 – Fall 2014.
1 CS April 2010 insertion sort, selection sort, quick sort Do exercises on pp to get familiar with concepts and develop skill. Practice.
CORRECTNESS ISSUES AND LOOP INVARIANTS Lecture 8 CS2110 – Fall 2015.
1 CS Oct 2008 Arrays. Reading: Secs 8.1, 8.2, 8.3 Listen to the following lectures on loops on your Plive CD. They are only 2-3 minutes long, and.
1 CS100J 21 March 2006 Arrays: searching & sorting. Reading: 8.5 Please punctuate this: Dear John, I want a man who knows what love is all about you are.
[ 8.00 ] [ Today’s Date ] [ Instructor Name ]
SWEN421 – Lecture 4 Contracts and Correctness
Correctness issues and Loop invariants
Midterm Review.
Recitation 13 Searching and Sorting.
CS100J 30 October 2007 Algorithms on arrays Reading: 8.3–8.5
Lesson 5-15 AP Computer Science Principles
Siti Nurbaya Ismail Senior Lecturer
Developing Loops from Invariants
Announcements P2 is due tomorrow Prelim on Monday
User Interface Design and Development
CS 220: Discrete Structures and their Applications
Introduction to Sorting Topic 21
CSE 331 Software Design and Implementation
"Organizing is what you do before you do something, so that when you do it, it is not all mixed up." ~ A. A. Milne Sorting Lecture 11 CS2110 – Fall 2018.
CS100A Lecture 15, 17 22, 29 October 1998 Sorting
Binary Search Binary search. Given value and sorted array a[], find index i such that a[i] = value, or report that no such index exists. Invariant.
Augmented Data Structures and the Test
Given value and sorted array, find index.
Asymptotic complexity Searching/sorting
"Organizing is what you do before you do something, so that when you do it, it is not all mixed up." ~ A. A. Milne Sorting Lecture 11 CS2110 – Spring 2019.
How students learn Build on previously learned materials
Binary Search and Loop invariants
Asymptotic complexity
CS100J Lecture 16 Previous Lecture This Lecture Programming concepts
CS November 2010 Developing array algorithms. Reading:
Jeff West - Quiz Section 16
Searching and Sorting Hint at Asymptotic Complexity
Intro to Programming 2/23/2016 Review Sections 1-3
CS100A Lecture 15, 17 22, 29 October 1998 Sorting
Searching and Sorting Hint at Asymptotic Complexity
Developing loops from invariants
CS100J Lecture 16 Previous Lecture This Lecture Programming concepts
Linear and Binary Search
Developing Loops from Invariants
CSE 326: Data Structures Lecture #14
Searching and Sorting Hint at Asymptotic Complexity
Searching and Sorting Hint at Asymptotic Complexity
Fractions and Division
Presentation transcript:

CS100J Nov 04, 2003 Arrays. Reading: 8 CS100J Nov 04, 2003 Arrays. Reading: 8.5 We look at standard algorithms on arrays The website has about 30 exercises dealing with loops, with answers. Have your worked on assignment A6 yet? Don’t procrastinate! Quiz on Thursday, on three algorithms that we present today. More than anything else, mathematics is Method. Morris Kline.

Quiz on Thursday I will ask you to write either linear search, finding the minimum, or binary search. Based simply on that, you write the precondition (if any), postcondition, and invariant, and then develop the algorithm, using the four loopy questions. You don’t memorize the code. Instead, you memorize what the algorithm does (given by the pre- and post-conditions) and develop it invariant and the Java code from there. To practice for the quiz, practice writing it all down! Don’t just read, do. Get a blank piece of paper and go through the whole process. Write the pre- and post-conditions, develop the invariant, and develop the code. AT THE END OF THESE SLIDE, WE SUMMARIZE THE THREE ALGORITHMS.

• The rest of the lecture will use the blackboard, because that is the easiest way to present the ideas. Pictures of arrays are easier to draw there. Moreover, programming is a dynamic activity, and the sense of development is easier to achieve on the blackboard. • If you have trouble with this material, listen also to the lectures on the CD!

• Linear search.Vague spec.: find first occurrence of v in b[h..k]. Better spec.: Store an integer in i to truthify: postcondition: (0) v is not in b[h..i-1] (1) Either i= k or v = b[k] invariant: v is not in b[h..i-1] • Finding the min. Vague spec.: Find the minimum of b[h..k] Better spec.: Precondition: h <= k (because an empty set of values has no minimum) Store in I to truthify: postcondition: b[m] is the minimum of b[h..k] (and it is the first occurrence of the minimum) invariant: b[m] is the minimum of b[h..t-1] (and it is the first occurrence of the minimum) • Binary search: Vague spec: Look for v in sorted array segment b[h..k]. Better spec: Precondition: b[h..k] is sorted (in ascending order). Store in i to truthify: postcondition: b[h..i] <= v and v < b[i+1..k] invariant: b[h..i] <= v and v < b[j..k]