3.3 Fundamentals of data representation

Slides:



Advertisements
Similar presentations
Database Management Systems and Enterprise Software
Advertisements

Searching for Data Relationship between searching and sorting Simple linear searching Linear searching of sorted data Searching for string or numeric data.
Search and Recursion CS221 – 2/23/09. List Search Algorithms Linear Search: Simple search through unsorted data. Time complexity = O(n) Binary Search:
Search and Recursion pt. 2 CS221 – 2/25/09. How to Implement Binary Search Take a sorted data-set to search and a key to search for Start at the mid-point.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 9 Searching.
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.,
Database Management Systems. This lesson includes the following sections  Databases and Management Systems Working with a Database Enterprise Software.
 A databases is a collection of data organized to make it easy to search and easy to retrieve in a useful, usable form.
A Computer Science Tapestry 1 Recursion (Tapestry 10.1, 10.3) l Recursion is an indispensable technique in a programming language ä Allows many complex.
Array Processing Simple Program Design Third Edition A Step-by-Step Approach 7.
Recursion Chapter 7. Chapter Objectives  To understand how to think recursively  To learn how to trace a recursive method  To learn how to write recursive.
Chapter 12Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 12 l Basics of Recursion l Programming with Recursion Recursion.
Lecturer: Dr. AJ Bieszczad Chapter 11 COMP 150: Introduction to Object-Oriented Programming 11-1 l Basics of Recursion l Programming with Recursion Recursion.
Chapter 11Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
Database A database program is a piece of software to organize and sort information. It creates an electronic list of information that can be sorted very.
Microsoft ® Access ® 2010 Training Create Queries for a New Database If a yellow security bar appears at the top of the screen in PowerPoint, click Enable.
Copyright 2004 Scott/Jones Publishing Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 9 Searching Arrays.
DATA STRUCTURE & ALGORITHMS (BCS 1223) CHAPTER 8 : SEARCHING.
CSCI 130 Array Searching. Methods of searching arrays Linear –sequential - one at the time –set does not have to be ordered Binary –continuously cutting.
Lesson 1: Exploring Access Learning Objectives After studying this lesson, you will be able to: Start Access and identify elements of the application.
Databases. What is a database?  A database is used to store data. The word DATA is actually Latin for FACTS. A database is, therefore, a place, or thing.
Data Structures and Algorithms Lecture 1 Instructor: Quratulain Date: 1 st Sep, 2009.
What have we learned?. What is a database? An organized collection of related data.
Chapter 12. Recursion Basics of Recursion Programming with Recursion Computer Programming with JAVA.
1 Section 2.1 Algorithms. 2 Algorithm A finite set of precise instructions for performing a computation or for solving a problem.
Introduction to Loops For Loops. Motivation for Using Loops So far, everything we’ve done in MATLAB, you could probably do by hand: Mathematical operations.
Chapter 9 slide 1 Introduction to Search Algorithms Search: locate an item in a list (array, vector, table, etc.) of information Two algorithms (methods):
1 Lesson 18 Managing and Reporting Database Information Computer Literacy BASICS: A Comprehensive Guide to IC 3, 3 rd Edition Morrison / Wells.
Introduction to a Database Definition: A database is a collection of information held together in an organised manner. For example: A library could be.
Chapter 11Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 11 l Basics of Recursion l Programming with Recursion Recursion.
Lesson 13 Databases Unit 2—Using the Computer. Computer Concepts BASICS - 22 Objectives Define the purpose and function of database software. Identify.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Data Structures and Algorithms Searching Algorithms M. B. Fayek CUFE 2006.
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.
Repetition In today’s lesson we will look at: why you would want to repeat things in a program different ways of repeating things creating loops in Just.
Edexcel OnCourse Databases Unit 9. Edexcel OnCourse Database Structure Presentation Unit 9Slide 2 What is a Database? Databases are everywhere! Student.
From Chaos to Database. Part 1: From Chaos to Database.
© 2016 AQA. Created by Teachit for AQA Searching algorithms 1 Lesson.
N5 Databases Notes Information Systems Design & Development: Structures and links.
Component 1.6.
3.3 Fundamentals of data representation
Component 1 Logical operators.
Recursion Topic 5.
Lesson Objectives Aims Key Words
Microsoft Access 2013 Bobby Wan.
3.3 Fundamentals of data representation
IGCSE 6 Cambridge Effectiveness of algorithms Computer Science
Search Recall the employee database used in class examples: employeeRecordT workforce[5] = Given "Vance, Emelline", how can we find her salary? Name.
Database Systems Unit 16.
records Database Vocabulary It can be useful to collect information.
CS1371 Introduction to Computing for Engineers
3.3 Fundamentals of data representation
Databases Lesson 2.
Winter 2018 CISC101 12/2/2018 CISC101 Reminders
Scratch Where Are You Now?
MSIS 655 Advanced Business Applications Programming
4.1 Strings ASCII & Processing Strings with the Functions
Data Tables and Arrays.
Principles of Computing – UFCFA3-30-1
Basics of Recursion Programming with Recursion
A LESSON IN LOOPING What is a loop?
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science
Principles of Computing – UFCFA3-30-1
Cycle 3: Unit 27 Lessons 104 – 111.
Database Management Systems and Enterprise Software
Presentation transcript:

3.3 Fundamentals of data representation 3.1.3 Searching algorithms 2 Lesson

How many records might need to be searched through? Think about this… A software company is asked to create a program for searching through a database of mobile-phone records for everyone owning a phone in the UK so that any individual’s number can be retrieved. How many records might need to be searched through? It is reasonable to suggest that each individual in the UK probably owns at least one mobile phone or even two. Any answer between 50,000,000 to 200,000,000 records would be reasonable.   Using a linear search it would be easy to code, but using a linear search would be very inefficient/slow using such a huge database.

Objectives Understand and explain how the binary search algorithm works Compare and contrast linear and binary search algorithms

Introduction to binary searching We looked previously at performing a linear search and saw that it can be inefficient. A more efficient algorithm is the binary search.

Definition of a binary search A method for searching data that splits datasets into two components repeatedly until the search term is located. What is a dataset? A collection of data, e.g. a table in a database. Why do we use the word binary? Binary implies two states – here we talk about splitting a dataset into two.

Before we can start… A binary search can only work with an ordered list. An ordered list is one where the fields are sorted in a preferred order, e.g. by numerical or alphabetical order. Besides the list being sorted, we will also need to know its size to enable us to identify the middle of the list.

Watch this video youtube.com/watch?v=JQhciTuD3E8&nohtml5=False Continuation of the video from last lesson. Watch from 3:12 minutes to 6:31 minutes.

Binary search algorithm Store SearchTerm StartPointer <- 1 EndPointer <- DataSetSize Do MidPointer <- (StartPointer + EndPointer ) / 2 (round answer down) If Record[MidPointer] < SearchTerm Then StartPointer <- MidPointer + 1 End If If Record[MidPointer] > SearchTerm Then EndPointer <- MidPointer – 1 Until Record[MidPointer] = SearchTerm OR StartPointer = EndPointer Print this slide.

Comparing linear and binary searches A linear search has an algorithm that is easier to understand, whereas the binary search algorithm is more complex. The binary search will be much quicker than a linear search – particularly where the volume of data being searched is large. One frequently asked question is ‘why is the binary search algorithm better if it requires the data to be sorted first? Surely that is a time-consuming process?’ The answer here is that yes, sorting the data will incur a processing overhead but that you only need do the sort once, you can do as many searches as you want thereafter and in reality, that is what will happen. A linear search will always be slower by comparison.

To round things off… Recap with BBC Bitesize: bbc.co.uk/education/guides/zgr2mp3/revision/2

The ordered list we are going to search is shown below: Position of item in list [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] 3 4 5 7 8 9 11 15 17 18 19 26 29 43 45 47 49 67 78 99 The extension task starts here. Value of item [4]

Binary search algorithm Store SearchTerm StartPointer <- 1 EndPointer <- DataSetSize Do MidPointer <- (StartPointer + EndPointer ) / 2 (round answer down) If Record[MidPointer] < SearchTerm Then StartPointer <- MidPointer + 1 End If If Record[MidPointer] > SearchTerm Then EndPointer <- MidPointer – 1 Until Record[MidPointer] = SearchTerm OR StartPointer = EndPointer Extension task. A printable version is available in the accompanying Word document.

Data area covered during each loop Position [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] Loop #1 3 4 5 7 8 9 11 15 17 18 19 26 29 43 45 47 49 67 78 99 Loop #2 Loop #3 Loop #4 Loop #5 Extension task. A printable version is available in the accompanying Word document.

Trace table   DataSetSize SearchTerm StartPointer EndPointer MidPointer Record[MidPointer] < SearchTerm Record[MidPointer] > SearchTerm [END] Record[MidPointer] = SearchTerm OR StartPointer = EndPointer Only one of these conditions should be met for each iteration. Fixed 21 Input 43 Initial 1 Loop 1 12 (1 + 21 = 22)/2 = 11 18 < 43 Loop 2 15 (12 + 21 = 33)/2 = 16* 45 > 43 Loop 3 14 (12 + 15 = 27)/2 = 13* 26 < 43 Loop 4 (14 + 15 = 27)/2 = 14* 29 < 43 Loop 5 (15 + 15 = 30)/2 = 15* Met! Record[MidPointer] = SearchTerm * = Rounded down Extension task. A printable version is available in the accompanying Word document.

Following the binary search algorithm 1 Loop #1 – [On entering loop, StartPointer = 1, EndPointer = 21, Search term = 43] Midpoint <- Cell [11] = 18 Condition now met has requirement = Change StartPointer Start point <- 12 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] 3 4 5 7 8 9 11 15 17 18 19 26 29 43 45 47 49 67 78 99 Extension task. Please refer to printable version of slides 12–14 in the accompanying Word document.

Following the binary search algorithm 2 Loop #2 Midpoint <- Cell [16] = 45 Condition now met has requirement = Change EndPointer End point <- 15 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] 3 4 5 7 8 9 11 15 17 18 19 26 29 43 45 47 49 67 78 99 Extension task.

Following the binary search algorithm 3 Loop #3 Midpoint <- Cell [13] = 26 Condition has now met requirement = Change StartPointer Start point <- 14 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] 3 4 5 7 8 9 11 15 17 18 19 26 29 43 45 47 49 67 78 99 Extension task.

Following the binary search algorithm 4 Loop #4 Midpoint <- Cell [14] = 29 Condition has now met requirement = Change StartPointer Start point <- 15 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] 3 4 5 7 8 9 11 15 17 18 19 26 29 43 45 47 49 67 78 99 Extension task.

Following the binary search algorithm 5 Loop #5 Midpoint <- Cell [15] = 43 Condition met = Search term matched Exit program! [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] 3 4 5 7 8 9 11 15 17 18 19 26 29 43 45 47 49 67 78 99 Extension task.