CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall 645-4739

Slides:



Advertisements
Similar presentations
Recursion.
Advertisements

College of Information Technology & Design
College of Information Technology & Design
CSE Lecture 3 – Algorithms I
CS0007: Introduction to Computer Programming Array Algorithms.
Week 5 - Associative Containers: sets and maps. 2 2 Main Index Main Index Content s Content s Container Types Sequence Containers Adapter Containers Associative.
CSE111: Great Ideas in Computer Science Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE116: Introduction to Computer Science 2 Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Sorting and Searching. Searching List of numbers (5, 9, 2, 6, 3, 4, 8) Find 3 and tell me where it was.
Monday, 12/9/02, Slide #1 CS 106 Intro to CS 1 Monday, 12/9/02  QUESTIONS??  On HW #5 (Due 5 pm today)  Today:  Recursive functions  Reading: Chapter.
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
CS 206 Introduction to Computer Science II 11 / 12 / 2008 Instructor: Michael Eckmann.
Searching Arrays Linear search Binary search small arrays
Sorting and Searching Arrays CSC 1401: Introduction to Programming with Java Week 12 – Lectures 1 & 2 Wanda M. Kunkle.
1 Search Algorithms Sequential Search (Linear Search) Binary Search Rizwan Rehman Centre for Computer Studies Dibrugarh University.
Week 11 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
CS 2430 Day 28. Announcements We will have class in ULR 111 on Monday Exam 2 next Friday (sample exam will be distributed next week)
ITEC 2620A Introduction to Data Structures
Information and Computer Sciences University of Hawaii, Manoa
Chapter 10 Strings, Searches, Sorts, and Modifications Midterm Review By Ben Razon AP Computer Science Period 3.
Lecture 12. Searching Algorithms and its analysis 1.
Data Structures & Algorithms CHAPTER 4 Searching Ms. Manal Al-Asmari.
Chapter 11 Arrays Continued
P-1 University of Washington Computer Programming I Lecture 15: Linear & Binary Search ©2000 UW CSE.
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.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Searching Course Lecture Slides 28 May 2010 “ Some things Man was never.
COMP Recursion, Searching, and Selection Yi Hong June 12, 2015.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington ArraySet and Binary Search.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall
Week 6 - Monday.  What did we talk about last time?  Exam 1!  Before that:  Recursion.
1 Section 2.1 Algorithms. 2 Algorithm A finite set of precise instructions for performing a computation or for solving a problem.
Chapter 9 slide 1 Introduction to Search Algorithms Search: locate an item in a list (array, vector, table, etc.) of information Two algorithms (methods):
Searching & Sorting Programming 2. Searching Searching is the process of determining if a target item is present in a list of items, and locating it A.
Sorting & Searching Review. Selection Sort 1. Find the smallest element 2. Move to the front of the array (swap with front) 3. Repeat Steps 1&2, but ignoring.
1 Searching and Sorting Searching algorithms with simple arrays Sorting algorithms with simple arrays –Selection Sort –Insertion Sort –Bubble Sort –Quick.
1 Principles of Computer Science I Honors Section Note Set 5 CSE 1341.
Chapter 9 Hashing Dr. Youssef Harrath
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Searching When we maintain a collection of data,
Chapter 9 Sorting. The efficiency of data handling can often be increased if the data are sorted according to some criteria of order. The first step is.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 14 Searching and Sorting.
1. Searching The basic characteristics of any searching algorithm is that searching should be efficient, it should have less number of computations involved.
Data Structures Arrays and Lists Part 2 More List Operations.
 Introduction to Search Algorithms  Linear Search  Binary Search 9-2.
ISOM MIS 215 Module 1 – Ordered Lists. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
Chapter 16: Searching, Sorting, and the vector Type.
1 compares each element of the array with the search key. works well for small arrays or for unsorted arrays works for any table slow can put more commonly.
Searching Arrays Linear search Binary search small arrays
Applied Discrete Mathematics Week 2: Functions and Sequences
Data Structures I (CPCS-204)
Data Searching and Sorting algorithms
Searching Given a collection and an element (key) to find… Output
Binary Search one reason that we care about sorting is that it is much faster to search a sorted list compared to sorting an unsorted list the classic.
Searching CSCE 121 J. Michael Moore.
Algorithm design and Analysis
searching Concept: Linear search Binary search
Linear Search Binary Search Tree
ITEC 2620M Introduction to Data Structures
COMPUTER 2430 Object Oriented Programming and Data Structures I
Collections Framework
Sorting and Searching -- Introduction
Module 8 – Searching & Sorting Algorithms
Presentation transcript:

CSE115: Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall

Exam 3 Monday (12/5) Exam 3 review Wednesday (12/7) Exam 3 Friday (12/9) Final exam review

This week Linear and binary search Friday – maybe lab 8 discussion

Goal: determine whether a target item is in a given collection. Use ArrayList for examples for now. In 116 we’ll see how to write a more general solution (one that’s not only for Integers). Search

ArrayList Allows for efficient index operations get(int index) method returns the value at the specified index

Linear search Search for target value starting at index 0, continuing to index size()-1 public boolean linearSearch(ArrayList list, Integer target) { for (int i=0; i<list.size(); i=i+1) { if (target.equals(list.get(i))) { return true; } return false; }

An example of a linear search for 79. Starting at index 0, the target value (79) is compared to the value at each index. Each row in the table denotes a different stage in the search; the top row (under the “index” row) shows the sequence of values prior to starting the search. Each subsequent row shows the values removed from consideration (shaded) at each iteration of the algorithm. index 0index 1index 2index 3index 4index 5index 6index

Binary search (assume data is sorted, smallest to largest) Search for target value starting at middle index; search in left or right partition based on result of comparison. public boolean binarySearch(ArrayList list, Integer target) { int L = 0; int R = list.size(); int M; while ( L != R ) { M = (L+R)/2; if ( target.equals(list.get(M)) ) { return true; } if ( target.intValue() < list.get(M).intValue() ) { R = M; } else { L = M+1; } } return false; }

An example of a binary search for 24. Starting at middle index, the target value (79) is compared to the value stored there. Each row in the table denotes a different stage in the search; the top row (under the “index” row) shows the sequence of values prior to starting the search. Each subsequent row shows the values removed from consideration (shaded) at each iteration of the algorithm. index 0index 1index 2index 3index 4index 5index 6index