Sequential Search slides. Searching Searching : –Information retrieval is one of the most important application of computers. –EG: Looking for a Name.

Slides:



Advertisements
Similar presentations
CSE Lecture 3 – Algorithms I
Advertisements

Searching “It is better to search, than to be searched” --anonymous.
Data Structures: A Pseudocode Approach with C 1 Chapter 5 Contd... Objectives Explain the design, use, and operation of a linear list Implement a linear.
Searching Kruse and Ryba Ch and 9.6. Problem: Search We are given a list of records. Each record has an associated key. Give efficient algorithm.
Binary Search Visualization i j.
Previous Lecture Revision Previous Lecture Revision Hashing Searching : –The Main purpose of computer is to store & retrieve –Locating for a record is.
Searching Algorithms. Lecture Objectives Learn how to implement the sequential search algorithm Learn how to implement the binary search algorithm To.
Memory Management A memory manager should take care of allocating memory when needed by programs release memory that is no longer used to the heap. Memory.
Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement.
J. Michael Moore Searching & Sorting CSCE 110. J. Michael Moore Searching with Linear Search Many times, it is necessary to search an array to find a.
Searching Arrays Linear search Binary search small arrays
Searching Chapter 18 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Searching Chapter Chapter Contents The Problem Searching an Unsorted Array Iterative Sequential Search Recursive Sequential Search Efficiency of.
1 © 2006 Pearson Addison-Wesley. All rights reserved Searching and Sorting Linear Search Binary Search -Reading p
1 Search Algorithms Sequential Search (Linear Search) Binary Search Rizwan Rehman Centre for Computer Studies Dibrugarh University.
Searching Searching: –Mainly used for: Fetching / Retrieving the Information such as, –Select query on a database. –Important thing is: Retrieval of Information.
1 Introduction to Arrays Problem: –Input 5 scores, compute total, average –Input Example –test scores,employees,temperatures.
Week 11 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
CPT: Search/ Computer Programming Techniques Semester 1, 1998 Objectives of these slides: –to discuss searching: its implementation,
Computer Science: A Structured Programming Approach Using C1 8-5 Sorting One of the most common applications in computer science is sorting—the process.
(C) 2010 Pearson Education, Inc. All rights reserved. Java How to Program, 8/e.
Chapter 19 Searching, Sorting and Big O
Computer Science 101 Fast Searching and Sorting. Improving Efficiency We got a better best case by tweaking the selection sort and the bubble sort We.
Lecture 12. Searching Algorithms and its analysis 1.
Data Structures & Algorithms CHAPTER 4 Searching Ms. Manal Al-Asmari.
AL-HUSEEN BIN TALAL UNIVERSITY College of Engineering Department of Computer Engineering Algorithms and Data Structures Search Algorithms Course No.:
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.
Starting Out with C++, 3 rd Edition 1 Searching an Arrays.
 2005 Pearson Education, Inc. All rights reserved Searching and Sorting.
 Pearson Education, Inc. All rights reserved Searching and Sorting.
CSE1301 Computer Programming: Lecture 26 List Processing (Search)
DATA STRUCTURE & ALGORITHMS (BCS 1223) CHAPTER 8 : SEARCHING.
1 Data Structures Searching Techniques Namiq Sultan.
Advance Data Structure 1 College Of Mathematic & Computer Sciences 1 Computer Sciences Department م. م علي عبد الكريم حبيب.
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.
SEARCHING.  This is a technique for searching a particular element in sequential manner until the desired element is found.  If an element is found.
L. Grewe.  An array ◦ stores several elements of the same type ◦ can be thought of as a list of elements: int a[8]
CS261 – Recitation 5 Fall Outline Assignment 3: Memory and Timing Tests Binary Search Algorithm Binary Search Tree Add/Remove examples 1.
CSC 211 Data Structures Lecture 13
A first look an ADTs Solving a problem involves processing data, and an important part of the solution is the careful organization of the data In order.
Data Structure Introduction.
CHAPTER 8 SEARCHING CSEB324 DATA STRUCTURES & ALGORITHM.
Review 1 Arrays & Strings Array Array Elements Accessing array elements Declaring an array Initializing an array Two-dimensional Array Array of Structure.
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 Algorithms Sequential Search – inspects every items in a sequential manner. Example, in an array, all values in the array are checked from index.
Searching Chapter 13 Objectives Upon completion you will be able to:
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.
Objectives At the end of the class, students are expected to be able to do the following: Understand the searching technique concept and the purpose of.
New Mexico Computer Science For All Search Algorithms Maureen Psaila-Dombrowski.
Chapter Lists Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Winter 2006CISC121 - Prof. McLeod1 Stuff No stuff today!
Data Structures and Algorithms Searching Algorithms M. B. Fayek CUFE 2006.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
CS212: DATASTRUCTURES Lecture 3: Searching 1. Lecture Contents  searching  Sequential search algorithm.  Binary search algorithm. 2.
Searching Topics Sequential Search Binary Search.
1 Recursive algorithms Recursive solution: solve a smaller version of the problem and combine the smaller solutions. Example: to find the largest element.
CS 241 Discussion Section (12/1/2011). Tradeoffs When do you: – Expand Increase total memory usage – Split Make smaller chunks (avoid internal fragmentation)
Chapter 3: Sorting and Searching Algorithms 3.1 Searching Algorithms.
 2006 Pearson Education, Inc. All rights reserved. 1 Searching and Sorting.
 Introduction to Search Algorithms  Linear Search  Binary Search 9-2.
CMPT 120 Topic: Searching – Part 2 and Intro to Time Complexity (Algorithm Analysis)
Searching Given a collection and an element (key) to find… Output
Topics discussed in this section:
Sorting Data are arranged according to their values.
Topics discussed in this section:
Sorting Data are arranged according to their values.
MSIS 655 Advanced Business Applications Programming
Sequential Search slides
Presentation transcript:

Sequential Search slides

Searching Searching : –Information retrieval is one of the most important application of computers. –EG: Looking for a Name by giving the telephone number. –We give one piece of information (KEY) and we are asked to find a record that contains other information associated with the key

Searching Searching for the keys that locate records is the most time consuming action in a program Two Types of Searching are there, 1) external searching Searching in external storage devices (Disk,Tapes etc..) 2) internal searching Searching within the computer memory

Searching Sequential Search : –Start at the first piece of data and look at it and if it no then keep going until you find what you are looking for or until you have reached the last. –EG : –Analysis : –When to Use?

Sequential search Find the marks of the students from the Data structures and algorithms course using an array. ( Key - ID) ID ARRAYARRAY array name is ‘ a ‘ // create For ( I =0; I < size; I++) { if a[I].id == ‘123’ cout << a[I].id<<a[I].mark1; found = true } if (found !=true) cout << “Not in the List”

Sequential Search Algorithm2: cin >>target; found = 0; I =0; while(I<n) &&(found==0) if (array[I]==target) found =1; Prev Alg: Depends on n But this one depends not only on n but also the position of the target

Sequential Search Two Kinds of result 1) Successful 2) UnSuccessful Best Case - 1st element O(1) (456) Worst Case - nth element O(n) (last)

Sequential search 1)It is useful for limited sized data sets as it is simple and does not require data to be structured in any way 2)when the data to be searched is constantly changing Dis : time consuming (large list) Any there other suitable data structures? This algorithm is well suited for implementation with linked list - follow ‘next’ pointer until we find or until we have reached the last adv: addition/deletion is easy

Binary Search How it works? Binary - two. List is broken down to two parts and searched working : Compare the target with the one in the center of the list and then restrict our attention to only the first or second half depending on whether the target comes before or after the central one. ( we reduce the length to be searched by half)

Binary Search Rule - numbers must be in sorted order Steps : 1. L = Low ( first index) 2. H = High (last index) 3. M = Mid ( ( l + h )/ 2 ) 1. mark l & h 2. Find Mid

Binary search 3. Check whether mid = x if so return index 4. If not, check whether x is > then bring low to mid +1 and carry on the same process 5. If < then bring high to mid-1 and carry on the same process 6. Until you find the value or if low and high cross each other

Binary search EG : Find X = 20 (search value) low high 1. Mid = l+h/2 = 1+7/2 = low h Mid high = mid -1

Binary search low h mid = l +h/2 = 1+3/2 = l m h check x = a[mid], yes matching so return index - ie 2