ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: Tel 3049.

Slides:



Advertisements
Similar presentations
Zabin Visram Room CS115 CS126 Searching
Advertisements

Chapter 3 Brute Force Brute force is a straightforward approach to solving a problem, usually directly based on the problem’s statement and definitions.
Garfield AP Computer Science
Topic 24 sorting and searching arrays "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."
HST 952 Computing for Biomedical Scientists Lecture 9.
Chapter 7 Sorting Part I. 7.1 Motivation list: a collection of records. keys: the fields used to distinguish among the records. One way to search for.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 11: Sorting and Searching  Searching Linear Binary  Sorting.
Binary Search Visualization i j.
Chapter 11 Sorting and Searching. Topics Searching –Linear –Binary Sorting –Selection Sort –Bubble Sort.
Sorting and Searching. Searching List of numbers (5, 9, 2, 6, 3, 4, 8) Find 3 and tell me where it was.
Searching Algorithms. Lecture Objectives Learn how to implement the sequential search algorithm Learn how to implement the binary search algorithm To.
CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement.
CS 106 Introduction to Computer Science I 03 / 07 / 2008 Instructor: Michael Eckmann.
1 Searching Algorithms Overview  What is Searching?  Linear Search and its Implementation.  Brief Analysis of Linear Search.  Binary Search and its.
CHAPTER 11 Searching. 2 Introduction Searching is the process of finding a target element among a group of items (the search pool), or determining that.
Searching/Sorting Introduction to Computing Science and Programming I.
Searching Arrays Linear search Binary search small arrays
1 Search Algorithms Sequential Search (Linear Search) Binary Search Rizwan Rehman Centre for Computer Studies Dibrugarh University.
Searching Algorithms. The Search Problem Problem Statement: Given a set of data e.g., int [] arr = {10, 2, 7, 9, 7, 4}; and a particular value, e.g.,
Chapter 5 Ordered List. Overview ● Linear collection of entries  All the entries are arranged in ascending or descending order of keys.
Search - CIS 1068 Program Design and Abstraction Zhen Jiang CIS Dept. Temple University SERC 347, Main Campus 19/23/2015.
ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 2620a.htm Office: TEL 3049.
ITEC 2620A Introduction to Data Structures
1 Searching. 2 Searching Searching refers to the operation of finding an item from a list of items based on some key value. Two Searching Methods (1)
Lecture 12. Searching Algorithms and its analysis 1.
P-1 University of Washington Computer Programming I Lecture 15: Linear & Binary Search ©2000 UW CSE.
Arrays.
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. Vocabulary List A collection of heterogeneous data (values can be different types) Dynamic in size Array A collection of homogenous data (values.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Searching Course Lecture Slides 28 May 2010 “ Some things Man was never.
SEARCHING.  This is a technique for searching a particular element in sequential manner until the desired element is found.  If an element is found.
COMP Recursion, Searching, and Selection Yi Hong June 12, 2015.
ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 2620a.htm Office: TEL 3049.
1 Today’s Material Iterative Sorting Algorithms –Sorting - Definitions –Bubble Sort –Selection Sort –Insertion Sort.
Lecture1 introductions and Tree Data Structures 11/12/20151.
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: TEL 3049.
CS261 Data Structures Ordered Bag Dynamic Array Implementation.
CHAPTER 8 SEARCHING CSEB324 DATA STRUCTURES & ALGORITHM.
Chapter 8 Search and Sort ©Rick Mercer. Outline Understand how binary search finds elements more quickly than sequential search Sort array elements Implement.
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.
Lecture on Binary Search and Sorting. Another Algorithm Example SEARCHING: a common problem in computer science involves storing and maintaining large.
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.
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: Tel 3049.
Data Structures and Algorithms Searching Algorithms M. B. Fayek CUFE 2006.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 14 Searching and Sorting.
CS212: DATASTRUCTURES Lecture 3: Searching 1. Lecture Contents  searching  Sequential search algorithm.  Binary search algorithm. 2.
Data Structures Arrays and Lists Part 2 More List Operations.
CMPT 120 Topic: Sorting Algorithms – Part 1. Last Lectures Searching algorithms and their time efficiency Linear search is of order n -> O(n) i.e., has.
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: TEL 3049.
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 20m.htm Office: TEL 3049.
 Introduction to Search Algorithms  Linear Search  Binary Search 9-2.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 8A Binary Search (Concepts)
CMPT 120 Topic: Searching – Part 2 and Intro to Time Complexity (Algorithm Analysis)
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: TEL 3049.
Searching/Sorting. Searching Searching is the problem of Looking up a specific item within a collection of items. Searching is the problem of Looking.
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.
ITEC 2620M Introduction to Data Structures
Searching CSCE 121 J. Michael Moore.
Algorithm design and Analysis
ITEC 2620M Introduction to Data Structures
ITEC 2620M Introduction to Data Structures
ITEC 2620M Introduction to Data Structures
ITEC 2620M Introduction to Data Structures
ITEC 2620M Introduction to Data Structures
Topic 24 sorting and searching arrays
ITEC 2620M Introduction to Data Structures
Searching.
Presentation transcript:

ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: Tel 3049

Searching

3 Key Points of this Lecture Searching arrays –Linear search –Binary search –Best, average, and worst cases

4 Searching in General “A query for the existence and location of an element in a set of distinct elements” Elements have searchable keys associated with a stored record –search on keys – e.g. name –to find an element – e.g. phone number Two goals of searching –existence  does the person exist? –location  where are they in the phone book? Isolate searching for “keys” – all keys have the same data type

5 Definition Suppose k 1, k 2, …, k n are distinct keys, and that we have a collection T of n records of the form (k 1, I 1 ), (k 2, I 2 ), …, (k n, I n ), where I j is information associated with key k j. Given a particular key value K, the search problem is to locate the record (k j, I j ) in T such that k j = K. Exact-match query Range query

6 Review of Array Algorithms Write a static method that determines the range (the difference between the largest and smallest element) for a fully populated array of ints. How is the above example similar to searching? –find the largest/smallest value in a set of elements Searching  find a given value in a set of elements

7 Searching Arrays Write a static method that determines the location (the array index) for a given value in a fully populated array of ints, return “–1” if the value is not in the array Example

8 Binary Search Make your first guess in the middle of the range If not the target element, determine which sub-range you have to search Make your next guess in the middle of this sub-range Repeat Example

9 Best, Worst and Average What’s the best case for search? –Linear  first element  1 compare –Binary  middle element  1 compare What’s the worst case for search? –Linear  not there  n compares –Binary  not there  logn compares What’s the average case for search? –Linear  middle element  n/2 compares –Binary  50/50…  logn - 1 compares

10 What’s the difference? Toronto phone book  2 million names –Avg. Linear  1 million compares –Avg. Binary  20 compares For 2 million records, binary search is 50,000 times faster on average What’s the cost –To do binary search, we need a sorted array –Sorting…next lecture!