24
Searching Lesson Plan - 6

Searching Lesson Plan - 6. Contents Evocation Objective Introduction Sequential Search Algorithm Variations on sequential search Mind map

Embed Size (px)

Citation preview

Page 1: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Searching

Lesson Plan - 6

Page 2: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Contents Evocation

Objective

Introduction

Sequential Search

Algorithm

Variations on sequential search

Mind map

Summary

Page 3: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

ANNEXURE-IEvocation

Page 4: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Evocation

Page 5: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Objective

To learn the basics of sequential search algorithm

To understand about the variations on sequential search

Page 6: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

ANNEXURE-II Introduction -Sequential Search

Searching is the process used to find location of target among a list of objects

Example: Table of Employee Record

Two basic searches for arrays are sequential search and binary search

Sequential search is used to locate items in any array Binary search requires an ordered list

Page 7: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Sequential Search Sequential search is used whenever list is not ordered Start searching for the target at the beginning of list and continue until

it finds the target or hits at the end of list

Search algorithm requires four parameters

• List we are searching

• Index to last element in list

• Target

• Address where the found element’s index location is to be stored

Page 8: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Successful Search of Unordered List

Page 9: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Unsuccessful Search of Unordered List

Page 10: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Sequential Search Algorithm

Page 12: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Yoga Breathing Mudra

• Enhances effortless breathing while gently balances five chakras

• Place your fingers in this position

• Thumb, middle, little finger gently pressed together (palm to palm)

• Both index fingers move behind the middle finger (don’t strain)

• Right ring finger in front of left (increases inhale in 80% of people)

• Left ring finger in front of right (increase exhale in 80% of people)

• Whenever you inhale or exhale change the position of your ring finger

• Now allow yourself to breathe into your abdomen first with the breath flowing like a wave opening up your chest

• Allow your shoulders to remain relaxed. As you exhale, smile

Page 13: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Optical illusionIs the center square of stars standing still or moving?

Page 14: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Logo identification

Page 15: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Hidden Picture Puzzles

Page 16: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Variations on Sequential Search Three useful variations in sequential search algorithm are• Sentinel search• Probability search• Ordered list search

Sentinel Search Knuth states, when inner loop of program test two or more conditions, we should try to reduce testing to just one

condition

Target is put in list by adding extra element at end of array and place the target in sentinel

Optimize the loop and determine after loop completes whether actual data found or sentinel

Page 17: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Variations on Sequential Search

Probability Search Data in array are arranged with most probable search elements at beginning of array and least probable at end

If probability ordering is correct over time, in each search exchange located element with element immediately before in array

Ordered list search Search ordered list sequentially, it is not necessary to search to end of list to determine the target is not in the list

Stop the target become less than or equal to current element we are testing

Page 18: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Sentinel Search Algorithm

int find(int* a, int l, int v){ a[l] = v; // add sentinel value for (i = 0; ; i++) if (a[i] == v) { if (i == l) // sentinel value, not real result return -1; return i; }}

Page 19: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Probability SearchINPUT: list[] : reference of interger array last : index of last item target: target to be found ref_locn: reference to the location of target OUT: If target is found location of target is stored in ref_locn found = 1 is returned target is moved up in priority

Else last is stored in ref_locn found = 0 is returned

Page 20: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Ordered List Search

Algorithm OrderedListSearch(list, last, target, locn)

if (target less than last element in list)

find first element less than or equal to target

set locn to index of elementelse set locn to lastend ifif (target in list) set found to trueelse set found to falseend ifreturn foundend OrderedListSearch

Page 21: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Search AlgorithmAdvantages• Easy algorithm to understand• Array can be any order• Easy to implement• Can be used on very small data sets• Not practical for searching large collections

Disadvantage• Inefficient (slow) for array of N elements, examine N/2 elements on average for value in array, N elements for value not in array

Page 22: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

ANNEXURE-IVMind Map

Sequential Search

Successful Search of

Unordered list

Unsuccessful Search of

Unordered list

AlgorithmVariations of

Sequential Search

Sentinel Search

Probability Search

Ordered List Search

Page 23: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

ANNEXURE-VSummary

• Searching is the process used to find location of target among a list of objects

• There are two basic methods for searching arrays: sequential search and binary search

• Sequential search is normally used when list is not sorted

• Starts at beginning of list and searches until it finds data or hits end of list

Page 24: Searching Lesson Plan - 6. Contents  Evocation  Objective  Introduction  Sequential Search  Algorithm  Variations on sequential search  Mind map

Summary

• In sentinel search, condition will end the search is reduced to only one by inserting target at end of list

• In probability search, list is sorted with most probable elements at beginning of list and least probable at end

• In order list search, it is not necessary to search to end of list to determine the target is not in the list