CSSE221: Software Dev. Honors Day 20 Announcements Announcements Homework 7 due beginning of next class. Homework 7 due beginning of next class. 6 short.

Slides:



Advertisements
Similar presentations
CSE 373: Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III 1.
Advertisements

CS50 SECTION: WEEK 3 Kenny Yu. Announcements  Watch Problem Set 3’s walkthrough online if you are having trouble.  Problem Set 1’s feedback have been.
CSSE221: Software Dev. Honors Day 12 Announcements Announcements No baby yet… No baby yet… Fifteen done. Fifteen done. Please read Class Announcements.
Scott Grissom, copyright 2004 Chapter 5 Slide 1 Analysis of Algorithms (Ch 5) Chapter 5 focuses on: algorithm analysis searching algorithms sorting algorithms.
Wednesday, 11/25/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 11/25/02  QUESTIONS??  Today:  More on sorting. Advanced sorting algorithms.  Complexity:
CSSE221: Software Dev. Honors Day 16 Announcements Announcements Markov due Wednesday 11:59 pm Markov due Wednesday 11:59 pm Homework 6 due next Tuesday,
CSSE221: Software Dev. Honors Day 25 Announcements: Announcements: Now returning programming mini-exam feedback, HW7, and some capsule quizzes. Now returning.
CSSE221: Software Dev. Honors Day 2 Announcements Announcements Homework due now Homework due now Any problems committing JavaEyes to Subversion? Any problems.
CSSE221: Software Dev. Honors Day 5 Announcements Announcements Homework 2 written portion due now Homework 2 written portion due now You survived the.
CSSE221: Software Dev. Honors Day 13 Announcements Announcements Contractions throughout the night… Contractions throughout the night… Late day assignments.
CSSE221: Software Dev. Honors Day 23 Announcements: Announcements: Pass in yesterday’s capsule quiz Pass in yesterday’s capsule quiz Homework 7 electronic.
Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement.
CSSE221: Software Dev. Honors Day 7 Announcements Announcements HW2 and inheritance quiz returned now. HW2 and inheritance quiz returned now. Solutions.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (3) Recurrence Relation 11/11 ~ 11/14/2008 Yang Song.
CSSE221: Software Dev. Honors Day 22 Announcements Announcements No written part to Homework 8 No written part to Homework 8 You can focus on Simulation.
CSSE221: Software Dev. Honors Day 14 Announcements Announcements Pass in Homework 5 now Pass in Homework 5 now Questions on Cars, Trucks, Trains? Questions.
Searching Arrays Linear search Binary search small arrays
CSSE221: Software Dev. Honors Day 18 Announcements Announcements Markov, some capsules coming back Markov, some capsules coming back Due this week: Due.
CS 280 Data Structures Professor John Peterson. Test #1 We’ll do a test next week on Wednesday. It will take the entire period. You can have 1 page of.
Searching1 Searching The truth is out there.... searching2 Serial Search Brute force algorithm: examine each array item sequentially until either: –the.
CSSE221: Software Dev. Honors Day 17 Announcements Announcements Fifteen and CarsTrucksTrains coming back Fifteen and CarsTrucksTrains coming back Note:
1 © 2006 Pearson Addison-Wesley. All rights reserved Searching and Sorting Linear Search Binary Search -Reading p
Search Lesson CS1313 Spring Search Lesson Outline 1.Searching Lesson Outline 2.How to Find a Value in an Array? 3.Linear Search 4.Linear Search.
1 Search Algorithms Sequential Search (Linear Search) Binary Search Rizwan Rehman Centre for Computer Studies Dibrugarh University.
Seattle Preparatory School Advanced Placement Computer Science Seattle Preparatory School Advanced Placement Computer Science LESSON 62 FEBRUARY 12, 2015.
MA/CSSE 473 Day 13 Permutation Generation. MA/CSSE 473 Day 13 HW 6 due Monday, HW 7 next Thursday, Student Questions Tuesday’s exam Permutation generation.
Building Java Programs Chapter 13 Searching reading: 13.3.
(C) 2010 Pearson Education, Inc. All rights reserved. Java How to Program, 8/e.
Chapter 19 Searching, Sorting and Big O
Chapter 11Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
SEARCHING UNIT II. Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances.
1 Searching and Sorting Linear Search Binary Search.
P-1 University of Washington Computer Programming I Lecture 15: Linear & Binary Search ©2000 UW CSE.
Searching. RHS – SOC 2 Searching A magic trick: –Let a person secretly choose a random number between 1 and 1000 –Announce that you can guess the number.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
CS 162 Intro to Programming II Searching 1. Data is stored in various structures – Typically it is organized on the type of data – Optimized for retrieval.
SEARCHING.  This is a technique for searching a particular element in sequential manner until the desired element is found.  If an element is found.
Ch 18 – Big-O Notation: Sorting & Searching Efficiencies Our interest in the efficiency of an algorithm is based on solving problems of large size. If.
CSC 211 Data Structures Lecture 13
Data Structures Using C++ 2E Chapter 9 Searching and Hashing Algorithms.
Intro to Sorting Intro to Computer Science CS1510 Dr. Sarah Diesburg.
SORTING 2014-T2 Lecture 13 School of Engineering and Computer Science, Victoria University of Wellington COMP 103 Marcus Frean.
1 Section 2.1 Algorithms. 2 Algorithm A finite set of precise instructions for performing a computation or for solving a problem.
Searching Algorithms Sequential Search – inspects every items in a sequential manner. Example, in an array, all values in the array are checked from index.
Sorting.
CS Class 22 Today  A word from the Real World What happens when software goes bad…  Binary Search Announcements  Exam 3 – Nov. 25 th in class.
1 5. Abstract Data Structures & Algorithms 5.6 Algorithm Evaluation.
1 Searching and Sorting Searching algorithms with simple arrays Sorting algorithms with simple arrays –Selection Sort –Insertion Sort –Bubble Sort –Quick.
E.G.M. PetrakisAlgorithm Analysis1  Algorithms that are equally correct can vary in their utilization of computational resources  time and memory  a.
Searching & Sorting. Algorithms Step by step recipe to do a task…
Spring 2006CISC101 - Prof. McLeod1 Announcements Assn 4 is posted. Note that due date is the 12 th (Monday) at 7pm. (Last assignment!) Final Exam on June.
Search Algorithms Written by J.J. Shepherd. Sequential Search Examines each element one at a time until the item searched for is found or not found Simplest.
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.
Unit 2 Day 11 FOCS – Human Computer Interaction. Tower Building Presentation Explain your solution.
MA/CSSE 473 Day 12 Amortization (growable Array) Knuth interview Brute Force Examples.
WHICH SEARCH OR SORT IS BETTER?. COMPARING ALGORITHMS Time efficiency refers to how long it takes an algorithm to run Space efficiency refers to the amount.
Algorithm Analysis with Big Oh ©Rick Mercer. Two Searching Algorithms  Objectives  Analyze the efficiency of algorithms  Analyze two classic algorithms.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
Intro to Data Structures Concepts ● We've been working with classes and structures to form linked lists – a linked list is an example of something known.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Sorting by Tammy Bailey
Intro to Recursion.
Binary Search and Intro to Sorting
Intro to Computer Science CS1510 Dr. Sarah Diesburg
MSIS 655 Advanced Business Applications Programming
Searching & Sorting.
MSIS 655 Advanced Business Applications Programming
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science
Presentation transcript:

CSSE221: Software Dev. Honors Day 20 Announcements Announcements Homework 7 due beginning of next class. Homework 7 due beginning of next class. 6 short written problems on data structures 6 short written problems on data structures Sierpinski gasket Sierpinski gasket Fibonacci exercise on recursion and tail recursion Fibonacci exercise on recursion and tail recursion

This week: Simulation Project Monday: Monday: Planning for Simulation Project Planning for Simulation Project Tuesday: Tuesday: Intro to searching algorithms and their efficiency (last round 2 capsule) Intro to searching algorithms and their efficiency (last round 2 capsule) Threads (capsule) Threads (capsule) Thursday: Thursday: Animation (capsule) Animation (capsule) Advanced GUIs (capsule) Advanced GUIs (capsule)

Search I’m thinking of a number between 1 and 100. I’m thinking of a number between 1 and 100. When you guess incorrectly, I’ll say higher or lower When you guess incorrectly, I’ll say higher or lower What’s your strategy? What’s your strategy? How does your strategy change when your only feedback is yes/no? How does your strategy change when your only feedback is yes/no?

Search Efficiency I’m thinking of a number between 1 and 100 and say “higher” or “lower” if you are incorrect. I’m thinking of a number between 1 and 100 and say “higher” or “lower” if you are incorrect. How many guesses does it take in the best case? Worst-case? (Exact numbers) How many guesses does it take in the best case? Worst-case? (Exact numbers) Get with a partner and devise scenarios for each Get with a partner and devise scenarios for each How does this change if the feedback is in the form yes/no? How does this change if the feedback is in the form yes/no?

Sequential search int indexOf(int n, int[] ar) { int indexOf(int n, int[] ar) { for (int i = 0; i < ar.length; i++) { for (int i = 0; i < ar.length; i++) { if (n == ar[i]) return i; if (n == ar[i]) return i; } return -1; return -1; } Is the best you can do? Is the best you can do? No, but only on one condition… No, but only on one condition… The data must be sorted. The data must be sorted.

Binary Search Divide-and-conquer Divide-and-conquer Useful only when the data is sorted (objects must be Comparable). Useful only when the data is sorted (objects must be Comparable). Guess the middle position. Guess the middle position. If it’s correct, return that position If it’s correct, return that position If it’s too small, then recurse on the first half of the array If it’s too small, then recurse on the first half of the array If it’s too big, then recurse on the second half of the array. If it’s too big, then recurse on the second half of the array.

Demo

Analysis of Search Time Sequential search: n/2 = O(n) each time Sequential search: n/2 = O(n) each time Binary Search: O(nlog(n)) once to sort + O(log n) each time Binary Search: O(nlog(n)) once to sort + O(log n) each time Which is faster if we had an array with 1M elements and we wanted to search it 1M times? Which is faster if we had an array with 1M elements and we wanted to search it 1M times?

Searching and sorting are ubiquitous In the classic book series The Art of Computer Programming, Donald Knuth devotes a whole volume (about 700 pages) to sorting and searching. In the classic book series The Art of Computer Programming, Donald Knuth devotes a whole volume (about 700 pages) to sorting and searching. Claims that about 70% of all CPU time is spent on these activities. Claims that about 70% of all CPU time is spent on these activities.