Unit 2: Computational Thinking, Algorithms & Programming

Slides:



Advertisements
Similar presentations
College of Information Technology & Design
Advertisements

Outline Polymorphic References Polymorphism via Inheritance Polymorphism via Interfaces Sorting Searching Event Processing Revisited File Choosers and.
HST 952 Computing for Biomedical Scientists Lecture 9.
D1: Binary Search. The binary search is the only algorithm you study in D1 that searches through data. The idea of the binary search is that once the.
Chapter 11 Sorting and Searching. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Examine the linear search and.
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.
Searching and Sorting Arrays
1 Sorting/Searching and File I/O Sorting Searching Reading for this lecture: L&L
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.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
CHAPTER 7: SORTING & SEARCHING Introduction to Computer Science Using Ruby (c) Ophir Frieder at al 2012.
Chapter 12 Recursion, Complexity, and Searching and Sorting
SEARCHING UNIT II. Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances.
Chapter 8 Searching and Sorting Arrays Csc 125 Introduction to C++ Fall 2005.
Starting Out with C++, 3 rd Edition 1 Searching an Arrays.
 2006 Pearson Education, Inc. All rights reserved Searching and Sorting.
Searching. Linear (Sequential) Search Search an array or list by checking items one at a time. Linear search is usually very simple to implement, and.
LAB#7. Insertion sort In the outer for loop, out starts at 1 and moves right. It marks the leftmost unsorted data. In the inner while loop, in starts.
1 Section 2.1 Algorithms. 2 Algorithm A finite set of precise instructions for performing a computation or for solving a problem.
Review 1 Arrays & Strings Array Array Elements Accessing array elements Declaring an array Initializing an array Two-dimensional Array Array of Structure.
Sorting and Searching. Selection Sort  “Search-and-Swap” algorithm 1) Find the smallest element in the array and exchange it with a[0], the first element.
ALGORITHMS.
1 Searching and Sorting Searching algorithms with simple arrays Sorting algorithms with simple arrays –Selection Sort –Insertion Sort –Bubble Sort –Quick.
New Mexico Computer Science For All Search Algorithms Maureen Psaila-Dombrowski.
Chapter 9 Sorting. The efficiency of data handling can often be increased if the data are sorted according to some criteria of order. The first step is.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
1. Searching The basic characteristics of any searching algorithm is that searching should be efficient, it should have less number of computations involved.
Sorting & Searching Geletaw S (MSC, MCITP). Objectives At the end of this session the students should be able to: – Design and implement the following.
 2006 Pearson Education, Inc. All rights reserved. 1 Searching and Sorting.
CMPT 120 Topic: Searching – Part 2 and Intro to Time Complexity (Algorithm Analysis)
Exam practice. Exam 1  Describe how a Boolean expression can control the operation of a loop  Describe the difference between a while loop and for loop.
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.
Algorithms and Flowcharts
OCR A Level F453: Data structures and data manipulation Data structures and data manipulation a. explain how static data structures may be.
Searching and Sorting Arrays
19 Searching and Sorting.
Searching and Sorting Algorithms
Tips and tools for creating and presenting wide format slides
CMSC201 Computer Science I for Majors Lecture 23 – Sorting
Introduction to Search Algorithms
Sorting Algorithms.
Lesson Objectives Aims Understand the following “standard algorithms”:
Standard Algorithms Higher Computing.
Teach A level Computing: Algorithms and Data Structures
Saturday, 10 November 2018 Binary
Teaching Computing to GCSE
CS 3343: Analysis of Algorithms
Binary Search Back in the days when phone numbers weren’t stored in cell phones, you might have actually had to look them up in a phonebook. How did you.
Last Class We Covered Data representation Binary numbers ASCII values
Standard Algorithms Input validation Finding the minimum
Teaching Computing to GCSE
Searching and Sorting Arrays
Last Class We Covered Dictionaries Hashing Dictionaries vs Lists
Standard Version of Starting Out with C++, 4th Edition
25 Searching and Sorting Many slides modified by Prof. L. Lilien (even many without an explicit message indicating an update). Slides added or modified.
Search,Sort,Recursion.
24 Searching and Sorting.
Principles of Computing – UFCFA3-30-1
Basics of Recursion Programming with Recursion
Searching and Sorting Arrays
Search,Sort,Recursion.
Searching and Sorting Arrays
CPS120: Introduction to Computer Science
CPS120: Introduction to Computer Science
Sorting Algorithms 2.1 – Algorithms.
Binary Search Counting
Principles of Computing – UFCFA3-30-1
Searching.
Presentation transcript:

Unit 2: Computational Thinking, Algorithms & Programming Search Algorithms 2.1 - Algorithms

Saturday, 18 May 2019 Search Algorithms Unit 2: Computational Thinking, Algorithms & Programming Saturday, 18 May 2019 Search Algorithms Learning Objective: To be able to demonstrate an understanding of the algorithms that are used to search for information in large amounts of data. Success Criteria: I can list the steps in a binary search algorithm. I can use the binary search algorithm to search for items in an ordered list. I can list the steps in a linear search algorithm. I can use the linear search algorithm to search for items in an unordered list.

Unit 2: Computational Thinking, Algorithms & Programming Search Algorithms When searching for information within large amounts of data, a computer uses algorithms in order to do this. There are 2 simple methods that you need to be aware of: Binary Search Algorithm (ordered lists) Linear Search Algorithm (unordered lists)

Unit 2: Computational Thinking, Algorithms & Programming Binary Search A binary search looks for items in an ordered list. Steps in a binary search are: Put the list into order (if it is not already) Find the middle item in the ordered list. If this is the item you’re looking for, then stop the search – you’ve found it. If not, compare the item you’re looking for to the middle item. If it comes before the middle item, get rid of the second half of the list. If it comes after the middle item, get rid of the first half of the list. You’ll be left with a list that is half the size of the original list. Repeat steps 1-3 on this smaller list to get an even smaller one. Keep going until you find the item you’re looking for. To find the middle item in a list of n items do (n+1) ÷2 and round up if necessary.

Binary Search Example: Unit 2: Computational Thinking, Algorithms & Programming Binary Search Example: We are going to use the binary search algorithm to find the number 99 in the following list: 7 21 52 59 68 92 94 99 133 There are 9 items in the list so the middle item is the (9+1) ÷ 2 = 5th item. The 5th item is 68 and 68 <99 so get rid of the first half of the list to leave: There are 4 items left so the middle item is the (4+1) ÷ 2 = 2.5 = 3rd item. The 3rd item is 99. You’ve found the item you’re looking for so the search is complete. 92 94 99 133 Exam Tip: You will need to show the steps in a question like this. You are likely to get asked a 4-6 mark question on one of these!

Unit 2: Computational Thinking, Algorithms & Programming Task: Binary Search Use the binary search algorithm to: Find the number 23 from the list. 2. Find the number 145 from the list. 2 15 20 23 30 34 45 50 51 25 45 60 85 100 115 135 145 160

Unit 2: Computational Thinking, Algorithms & Programming Linear Search A linear search can be used on an Unordered list. A linear search checks each item of the list in turn to see if it’s the correct one, it stops when it either finds the item it’s looking for or has checked every item. A linear search is much simpler than a binary search but less efficient. A linear search can be used on any type of list, it doesn’t have to be ordered. Due to it being inefficient, it is often only used on small lists.

Linear Search: The Steps Unit 2: Computational Thinking, Algorithms & Programming Linear Search: The Steps Look at the first item in the unordered list. If this is the item you’re looking for, then stop the search – you’ve found it! If not, then look at the next item in the list. Repeat steps 2 and 3 until you find the item that you’re looking for or you’ve checked every item. Lets look at an example….

Linear Search: Example Unit 2: Computational Thinking, Algorithms & Programming Linear Search: Example Use the linear search to find the number 99 from the previous list… 7 21 52 59 68 92 94 99 133 Check the first item: 7 ≠ 99 Look at the next item: 21 ≠ 99 52 ≠ 99 59 ≠ 99 68 ≠ 99 92 ≠ 99 94 ≠ 99 99 = 99 ≠ means NOT You’ve found the item you’re looking for so the search is complete.

Unit 2: Computational Thinking, Algorithms & Programming Task: Linear Search Use the linear search algorithm to: Find the number 23 from the list. 2. Find the number 145 from the list. 2 15 20 23 30 34 45 50 51 25 45 60 85 100 115 135 145 160

Exam Style Questions: Linear Unit 2: Computational Thinking, Algorithms & Programming Exam Style Questions: Linear Describe an algorithm expressed in pseudocode to ask a user for a search item and carry out a linear search on data stored in an array to find that item. [6 marks]

Exam Style Questions: Binary Unit 2: Computational Thinking, Algorithms & Programming Exam Style Questions: Binary Describe the stages in applying a binary search to the following list to find the number 17. 3, 5, 9, 14, 17, 21, 27, 31, 35, 37, 39, 40, 42. [4 marks]