VCE IT Theory Slideshows

Slides:



Advertisements
Similar presentations
Lesson 8 Searching and Sorting Arrays 1CS 1 Lesson 8 -- John Cole.
Advertisements

VCE IT Theory Slideshows By Mark Kelly Vceit.com Problem Solving Methodology 4 EVALUATION.
VCE IT Theory Slideshows - ITA By Mark Kelly Vceit.com Entity Relationship Diagrams (ERD)
VCE IT Theory Slideshows By Mark Kelly McKinnon Secondary College Vceit.com Power Websites CMS and CSS.
Searching and Sorting Topics  Sequential Search on an Unordered File  Sequential Search on an Ordered File  Binary Search  Bubble Sort  Insertion.
Search and Recursion CS221 – 2/23/09. List Search Algorithms Linear Search: Simple search through unsorted data. Time complexity = O(n) Binary Search:
Sorting and Searching. Searching List of numbers (5, 9, 2, 6, 3, 4, 8) Find 3 and tell me where it was.
Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement.
Searching Arrays Linear search Binary search small arrays
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.
VCE IT Theory Slideshows
IT Applications Theory Slideshows By Mark Kelly Vceit.com Types and contents of On-screen user documentation.
File Management Mark Kelly vceit.com.
VCE IT Theory Slideshows By Mark Kelly Vceit.com Characteristics of efficient and effective solutions.
VCE IT Theory Slideshows By Mark Kelly vceit.com Data Types 1 a.
1 Searching. 2 Searching Searching refers to the operation of finding an item from a list of items based on some key value. Two Searching Methods (1)
VCE IT Theory Slideshows By Mark Kelly Vceit.com Testing Network Security.
CSC 211 Data Structures Lecture 13
IT Applications Theory Slideshows By Mark Kelly Vceit.com Last modified : 6 Dec 2013 Databases II: Structure, naming, data types, data formats.
VCE IT Theory Slideshows By Mark Kelly Vceit.com Problem Solving Methodology 3 Development.
Review 1 Arrays & Strings Array Array Elements Accessing array elements Declaring an array Initializing an array Two-dimensional Array Array of Structure.
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.
VCE IT Theory Slideshows By Mark Kelly Vceit.com Arrays.
VCE IT Theory Slideshows by Mark Kelly study design By Mark Kelly, vceit.com, Begin.
VCE IT Theory Slideshows by Mark Kelly study design By Mark Kelly, vceit.com, Begin.
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.
Searching Topics Sequential Search Binary Search.
VCE IT Theory Slideshows by Mark Kelly study design By Mark Kelly, vceit.com, Begin.
VCE IT Theory Slideshows By Mark Kelly vceit.com Version 2 – updated for 2016 Data Types 1 a.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
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.
CMSC 104, Version 8/061L24Searching&Sorting.ppt Searching and Sorting Topics Sequential Search on an Unordered File Sequential Search on an Ordered File.
VCE IT Theory Slideshows
Copyright Prentice Hall Modified by Sana odeh, NYU
Searching Arrays Linear search Binary search small arrays
Searching and Sorting Searching algorithms with simple arrays
VCE IT Theory Slideshows
Searching and Sorting Arrays
Searching and Sorting Algorithms
VCE IT Theory Slideshows
Outline lecture Revise arrays Entering into an array
VCE IT Theory Slideshows – ITI Updated for 2016
VCE IT Theory Slideshows
IT Applications Theory Slideshows
Lesson Objectives Aims Understand the following “standard algorithms”:
CMPT 238 Data Structures Midterm Exam Review.
VCE IT Theory Slideshows by Mark Kelly study design
VCE IT Theory Slideshows by Mark Kelly study design
2008/12/03: Lecture 20 CMSC 104, Section 0101 John Y. Park
VCE IT Theory Slideshows by Mark Kelly study design
Searching and Sorting Topics Sequential Search on an Unordered File
VCE IT Theory Slideshows
Searching and Sorting Topics Sequential Search on an Unordered File
VCE IT Theory Slideshows by Mark Kelly study design Test Data
VCE IT Theory Slideshows
Searching and Sorting Arrays
Standard Version of Starting Out with C++, 4th Edition
VCE IT Theory Slideshows
Searching and Sorting 1-D Arrays
UMBC CMSC 104 – Section 01, Fall 2016
Search,Sort,Recursion.
VCE IT Theory Slideshows Updated for 2016
Searching and Sorting Topics Sequential Search on an Unordered File
Data Structures Sorted Arrays
VCE IT Theory Slideshows
VCE IT Theory Slideshows
Searching and Sorting Arrays
CMPT 120 Lecture 26 – Unit 5 – Internet and Big Data
Presentation transcript:

VCE IT Theory Slideshows Searching Techniques VCE IT Theory Slideshows By Mark Kelly mark@vceit.com Vceit.com

Contents (2016-2019) Linear search Binary search

When searching is required You have thousands of clients on file and you need to find one client’s record In a list of a thousand exam results, you need to find all those who failed and count them. You need to find the smallest value in a list. When processing surveys, you develop a list of unique responses. If the same response recurs, you just add 1 to its count. To do this, you need to search the list to see if it already exists.

Linear search Go to the first item in the list. Compare the list item with the target value. If it does not match, move to the next item. Go to step 2 unless the list is finished. PROS: easy to code; the only method in an unsorted list. CON: can be very slow (up to N comparisons needed to search a list of N items)

Linear Search Algorithm

Binary Search Data being searched must be sorted The sorting lets you know whether or not you have passed the value being sought

Binary Search Algorithm: Divide the data set in half Is the value being sought less than or greater than the half-way value? Throw away the wrong half. Repeat In only a few comparisons the value will be either found or proved not to be in the data set

Pros/Cons of Binary Search + Far faster – many fewer comparisons needed to find an item (rarely more than 5 or so) - Data must be sorted, which adds processing time

Binary Search Algorithm Found  false Start  index of first item End  index of last item While not found Halfway  (start + end) /2 Halfwayvalue  value of item at index halfway If ValueBeingSearched = Halfwayvalue then exit (value was found) Else if valuebeingsearched < halfwayvalue end  halfway ’ ignore top half of data set else start  halfway ’ ignore bottom half of data set end if if start >= end then exit (item does not exist in the data set) End if End while

A Practical Binary Search Demo Pick up a book with many pages Choose a page number at random (call it ‘n’) Use the binary search technique to find page n Count how many page number comparisons you make Compare with a linear search which would’ve taken n comparisons!

For example 1000 page book. We’re looking for page 296 Start = 1, End = 1000 Success in 6 comparisons. Linear search would have taken 296 comparisons PASS HALF WAY Test New Start Half End 1 500 296 < 500 250 2 296 > 250 375 3 296 < 275 312 4 296 < 312 281 5 296 > 281 296 6 296 = 296 End!

So, which to choose? If linear search was always worse than binary, it would no longer exist. The fact the it still exists means it has advantages. It’s much easier to program. Saves time. Data does not have to be always kept sorted. Saves processing. For small data sets, it’s quite adequate. If sorting time is not an issue, it’s quite adequate.

Quick Tip Do not confuse searching (linear, binary) with sorting (selection, quick) The exam often asks which search technique is better. Consider both the size of the dataset and the urgency of the search duration.

And because you’ve been good here’s a picture you can look at

VCE IT THEORY SLIDESHOWS By Mark Kelly mark@vceit.com vceit.com These slideshows may be freely used, modified or distributed by teachers and students anywhere on the planet (but not elsewhere). They may NOT be sold. They must NOT be redistributed if you modify them.