Sequential Search slides

Slides:



Advertisements
Similar presentations
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.
Advertisements

Binary Search Visualization i j.
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.
Sequential Search slides. Searching Searching : –Information retrieval is one of the most important application of computers. –EG: Looking for a Name.
Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement.
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.
Computer Science: A Structured Programming Approach Using C1 8-5 Sorting One of the most common applications in computer science is sorting—the process.
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.:
Starting Out with C++, 3 rd Edition 1 Searching an Arrays.
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.
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.
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.
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 & 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.
New Mexico Computer Science For All Search Algorithms Maureen Psaila-Dombrowski.
Chapter Lists Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
Data Structures and Algorithms Searching Algorithms M. B. Fayek CUFE 2006.
CS212: DATASTRUCTURES Lecture 3: Searching 1. Lecture Contents  searching  Sequential search algorithm.  Binary search algorithm. 2.
1 Recursive algorithms Recursive solution: solve a smaller version of the problem and combine the smaller solutions. Example: to find the largest element.
Chapter 3: Sorting and Searching Algorithms 3.1 Searching Algorithms.
 Introduction to Search Algorithms  Linear Search  Binary Search 9-2.
CMPT 120 Topic: Searching – Part 2 and Intro to Time Complexity (Algorithm Analysis)
Searching and Sorting Copyright Prentice Hall (with additions / modifications by Evan Korth)
Copyright Prentice Hall Modified by Sana odeh, NYU
Searching Arrays Linear search Binary search small arrays
16 Searching and Sorting.
Outline lecture Revise arrays Entering into an array
CMPT 120 Topic: Searching – Part 2
Searching Given a collection and an element (key) to find… Output
Introduction to Search Algorithms
Search Recall the employee database used in class examples: employeeRecordT workforce[5] = Given "Vance, Emelline", how can we find her salary? Name.
Data Structures Interview / VIVA Questions and Answers
Adapted from slides by Marty Stepp and Stuart Reges
Topics discussed in this section:
Sorting Data are arranged according to their values.
Topics discussed in this section:
Adapted from Pearson Education, Inc.
CSc 110, Spring 2017 Lecture 39: searching.
CSC215 Lecture Algorithms.
Winter 2018 CISC101 12/2/2018 CISC101 Reminders
Sorting Data are arranged according to their values.
Searching and Sorting Arrays
MSIS 655 Advanced Business Applications Programming
Searching and Sorting 1-D Arrays
Searching: linear & binary
Search,Sort,Recursion.
Algorithm Analysis Bina Ramamurthy CSE116A,B.
Cs212: DataStructures Lecture 3: Searching.
Principles of Computing – UFCFA3-30-1
Data Structures: Searching
Topic 24 sorting and searching arrays
Given value and sorted array, find index.
Basics of Recursion Programming with Recursion
Arrays Week 2.
Search,Sort,Recursion.
Adapted from slides by Marty Stepp and Stuart Reges
Data Structures and Algorithm: SEARCHING TECHNIQUES
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science
Chapter 19 Searching, Sorting and Big O
Principles of Computing – UFCFA3-30-1
Data Structures Using C++ 2E
Applications of Arrays
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) 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” ID 456 60 80 A R R A Y

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 : 10 20 30 40 50 60 70 Find X = 20 (search value) low high 1. Mid = l+h/2 = 1+7/2 = 4 10 20 30 40 50 60 70 low h Mid high = mid -1

Binary search 10 20 30 40 50 60 70 low h mid = l +h/2 = 1+3/2 =2 l m h check x = a[mid] , yes matching so return index - ie 2