© 2016 AQA. Created by Teachit for AQA 3.1.3 Searching algorithms 1 Lesson.

Slides:



Advertisements
Similar presentations
College of Information Technology & Design
Advertisements

BY: Ivan Lopez and Diego Hinojosa.  Chapter 8 Overview Lesson 8–1 The Essentials of a Database Lesson 8–2 Types of Database Programs Lesson 8–3 Database.
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.
CPSC 171 Introduction to Computer Science More Efficiency of Algorithms.
Sorting and Searching. Searching List of numbers (5, 9, 2, 6, 3, 4, 8) Find 3 and tell me where it was.
Searching/Sorting Introduction to Computing Science and Programming I.
1 A Introduction to Data Structures and Algorithm Analysis Data Structures Asst. Professor Kiran Soni.
Searching Given a collection and an element (key) to find… Output –Print a message (“Found”, “Not Found) –Return a value (position of key ) Don’t modify.
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.
Examples using Arrays. Summing Squares Problem: To compute the sum of the squares of N numbers N is given N values are also given These should be read.
L. Grewe.  An array ◦ stores several elements of the same type ◦ can be thought of as a list of elements: int a[8]
CSC 211 Data Structures Lecture 13
Review 1 Arrays & Strings Array Array Elements Accessing array elements Declaring an array Initializing an array Two-dimensional Array Array of Structure.
3.3 Complexity of Algorithms
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.
Recommendation Algorithms for E-Commerce. Introduction Millions of products are sold over the web. Choosing among so many options is proving challenging.
New Mexico Computer Science For All Search Algorithms Maureen Psaila-Dombrowski.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
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.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
CHAPTER 51 LINKED LISTS. Introduction link list is a linear array collection of data elements called nodes, where the linear order is given by means of.
CMPT 120 Topic: Searching – Part 2 and Intro to Time Complexity (Algorithm Analysis)
南昌大学自动化系胡凌燕 1 Charpter 1 The data structures and algorithms (p3) There are often many approaches to solving a problem. How do we choose between them? 
© 2016 AQA. Created by Teachit for AQA Boolean logic Lesson 3.
© 2016 AQA. Created by Teachit for AQA Boolean logic Lesson 1.
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
Copyright Prentice Hall Modified by Sana odeh, NYU
Searching Arrays Linear search Binary search small arrays
Algorithm Efficiency and Sorting
3.3 Fundamentals of data representation
Searching and Sorting Arrays
3.3 Fundamentals of data representation
Searching and Sorting Arrays
Outline lecture Revise arrays Entering into an array
Searching Given a collection and an element (key) to find… Output
Lecture 14 Searching and Sorting Richard Gesick.
Introduction to Search Algorithms
Chapter 9: Searching, Sorting, and Algorithm Analysis
Introduction to complexity
Lesson 5-15 AP Computer Science Principles
Introduction to Algorithms
Chapter 8 Arrays Objectives
Chapter Trees and B-Trees
Chapter Trees and B-Trees
Algorithms Chapter 3 With Question/Answer Animations
Algorithm An algorithm is a finite set of steps required to solve a problem. An algorithm must have following properties: Input: An algorithm must have.
Databases Lesson 2.
Chapter 8 Arrays Objectives
Lesson 15: Processing Arrays
Lecture 11 Searching and Sorting Richard Gesick.
Searching and Sorting Arrays
MSIS 655 Advanced Business Applications Programming
Hash Tables Chapter 12 discusses several ways of storing information in an array, and later searching for the information. Hash tables are a common.
Topic 1: Problem Solving
Linear Search Binary Search Tree
ITEC 2620M Introduction to Data Structures
Introduction to Data Structures
Hash Tables Chapter 12 discusses several ways of storing information in an array, and later searching for the information. Hash tables are a common.
Chapter 8 Arrays Objectives
Data Structures and Algorithm: SEARCHING TECHNIQUES
Searching and Sorting Arrays
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science
Sum this up for me Let’s write a method to calculate the sum from 1 to some n public static int sum1(int n) { int sum = 0; for (int i = 1; i
Binary Search Counting
Unit 2: Computational Thinking, Algorithms & Programming
WJEC GCSE Computer Science
Cycle 3: Unit 27 Lessons 104 – 111.
HUMAN COMPUTER INTERACTION. The main aims of the chapter are to: Explain the difference between good and poor interaction design. Describe what interaction.
Presentation transcript:

© 2016 AQA. Created by Teachit for AQA Searching algorithms 1 Lesson

© 2016 AQA. Created by Teachit for AQA Introduction to searching and sorting In this set of four lessons we will be looking at the basics of searching and sorting. Both of these techniques are heavily utilised in the processing of information and computers are used to automate each of these tasks.

© 2016 AQA. Created by Teachit for AQA What is meant by searching and sorting? Area Definition Searching The act of looking through a collection of data and locating a specific item of interest. Sorting The act of arranging a collection of data into an ordered fashion using one or more key fields to enforce the arranging of the data.

© 2016 AQA. Created by Teachit for AQA Four searching and sorting methods There are many other ways of carrying out searching and sorting. Searching LinearSimplest form of searching. BinaryMore complex algorithm for searching data. Sorting BubbleSimplest form of sorting data. MergeMore complex algorithm for sorting data.

© 2016 AQA. Created by Teachit for AQA Objective Understand and explain how the linear search algorithm works.

© 2016 AQA. Created by Teachit for AQA Introduction to linear searching The simplest type of search – a linear search – is defined as a search that looks through a list or collection of data one item at a time until the desired search object is located. We describe this type of search using an algorithm. The simpler the algorithm, the less efficient the search or sort operation is likely to be on very large numbers of records.

© 2016 AQA. Created by Teachit for AQA Examples that use searching Let’s think about some typical situations where we may want to use computers to automate a search through a large amount of data. Area Item of interestPossible magnitude School Look for an individual student’s name in a set of student records. Thousands of possible records in large secondary school or collee. Banking Look for a customer’s account number using a bank’s database. Hundreds of thousands or even millions of records for a well-known national UK bank.

© 2016 AQA. Created by Teachit for AQA Linear searching video youtube.com/watch?v=JQhciTuD3E8&nohtml5=False

© 2016 AQA. Created by Teachit for AQA Linear search algorithm Input ‘Search term’ Match = False, Record number <- 1 Do Compare Current record with Search term If matched then Match = True Record number <- Record number + 1 Until end-of-record set reached OR Match == True If Match == True Then print “Record found!” Else print “Record not found”

© 2016 AQA. Created by Teachit for AQA Using the algorithm 1 Let’s apply our algorithm to searching the following list for the term ‘Sheep’. [1][2][3][4][5][6][7][8] CatDogSheepGiraffeMouseElephantZebraCow Position of item in list Value of item [2]

© 2016 AQA. Created by Teachit for AQA Starting point Search term = ‘Sheep’ Match = False Record number <- 1 Input ‘Search term’ Match = False, Record number <- 1 Do Compare Current record with Search term If matched then Match = True Record number <- Record number + 1 Until end-of-record set reached OR Match == True If Match == True Then print “Record found!” Else print “Record not found” Using the algorithm 2 [1][2][3][4][5][6][7][8] CatDogSheepGiraffeMouseElephantZebraCow

© 2016 AQA. Created by Teachit for AQA First time in loop Record[1] = ‘Cat’ Search term = ‘Sheep’ Match = False Record number <- 2 Looks here first Input ‘Search term’ Match = False, Record number <- 1 Do Compare Current record with Search term If matched then Match = True Record number <- Record number + 1 Until end-of-record set reached OR Match == True If Match == True Then print “Record found!” Else print “Record not found” Using the algorithm 3 [1][2][3][4][5][6][7][8] CatDogSheepGiraffeMouseElephantZebraCow

© 2016 AQA. Created by Teachit for AQA Second time in loop Record[2] = ‘Dog’ Search term = ‘Sheep’ Match = False Record number <- 3 Looks here now Input ‘Search term’ Match = False, Record number <- 1 Do Compare Current record with Search term If matched then Match = True Record number <- Record number + 1 Until end-of-record set reached OR Match == True If Match == True Then print “Record found!” Else print “Record not found” Using the algorithm 4 [1][2][3][4][5][6][7][8] CatDogSheepGiraffeMouseElephantZebraCow

© 2016 AQA. Created by Teachit for AQA Third time in loop Record[3] = ‘Sheep’ Search term = ‘Sheep’ Match = True Record number <- 4 Looks here now Input ‘Search term’ Match = False, Record number <- 1 Do Compare Current record with Search term If matched then Match = True Record number <- Record number + 1 Until end-of-record set reached OR Match == True If Match == True Then print “Record found!” Else print “Record not found” Using the algorithm 5 [1][2][3][4][5][6][7][8] CatDogSheepGiraffeMouseElephantZebraCow

© 2016 AQA. Created by Teachit for AQA Linear search algorithm – problems How many times did we have to run the loop in the algorithm? For a very large list, it is not efficient at all. Next, we will look at the binary search algorithm which is more efficient than the linear search algorithm.

© 2016 AQA. Created by Teachit for AQA To round things off… Now try the worksheet on following a linear search algorithm.