Linear Search Linear Search is a fundamental search algorithm. Linear search, also known as sequential search, is a process that checks every element in.

Slides:



Advertisements
Similar presentations
Logical Operations on Images Boolean logic is a system of logical operations defined by George Boole in the mid 19th century to apply algebraic operations.
Advertisements

Welcome This is a document to explains the chosen concept to the animator. This will take you through a 5 section process to provide the necessary details.
High Boost filtering In image processing, it is often desirable to emphasize high frequency components representing the image details without eliminating.
Global System for Mobile communication GSM is a cellular network, which means that mobile phones connect to it by searching for cells in the immediate.
Ver. 1.0 Session 5 Data Structures and Algorithms Objectives In this session, you will learn to: Sort data by using quick sort Sort data by using merge.
Searching and Sorting Copyright Prentice Hall (with modifications by Evan Korth)
Searching and Sorting 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.
CS 106 Introduction to Computer Science I 10 / 16 / 2006 Instructor: Michael Eckmann.
Hamming Code A Hamming code is a linear error-correcting code named after its inventor, Richard Hamming. Hamming codes can detect up to two bit errors,
SDS-PAGE gel analysis SDS-PAGE analysis is done to study the expression of a protein from the control and the sample, to detect the molecular weight of.
Chapter 8 ARRAYS Continued
Syndrome Decoding of Linear Block Code
Binary Exponential Backoff Binary exponential backoff refers to a collision resolution mechanism used in random access MAC protocols. This algorithm is.
Document that explains the chosen concept to the animator.
Starting Out with C++, 3 rd Edition 1 Searching an Arrays.
 Pearson Education, Inc. All rights reserved Searching and Sorting.
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.
DATA STRUCTURE & ALGORITHMS (BCS 1223) CHAPTER 8 : SEARCHING.
SEARCHING. Vocabulary List A collection of heterogeneous data (values can be different types) Dynamic in size Array A collection of homogenous data (values.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Searching Course Lecture Slides 28 May 2010 “ Some things Man was never.
CSC 211 Data Structures Lecture 13
Welcome This is a document to explains the chosen concept to the animator. This will take you through a 5 section process to provide the necessary details.
Review 1 Arrays & Strings Array Array Elements Accessing array elements Declaring an array Initializing an array Two-dimensional Array Array of Structure.
Chapter 9 slide 1 Introduction to Search Algorithms Search: locate an item in a list (array, vector, table, etc.) of information Two algorithms (methods):
Logic Gates Part – III : Combinational Logic Gates Combinational Logic Circuits are made up from basic logic NAND, NOR or NOT gates that are "combined"
ID template 5.0 for creating learning objects Created by OSCAR team October 2011 INSTRUCTIONS SLIDE: DO NO EDIT.
Electrical Resistivity in Superconductors The electrical resistivity of many metals and alloys drops suddenly to zero when the specimen is cooled to a.
Sorting and Searching by Dr P.Padmanabham Professor (CSE)&Director
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.
CHAPTER EIGHT ARRAYS © Prepared By: Razif Razali1.
Crystal Structure Author Sachin Patil ‘Basis and Lattice ’ The basic building blocks of Crystalline state ‏ ‏
Line Coding Schemes ‏Line coding is the process of converting binary data, a sequence of bits to a digital signal. Authors Phani Swathi Chitta Mentor Prof.
Convolutional Coding In telecommunication, a convolutional code is a type of error- correcting code in which m-bit information symbol to be encoded is.
Isothermal reversible ideal gas system The concepts deals with system in which the temperature of the system is constant With the help of this animation.
Edge Detection using Laplacian of Gaussian Edge detection is a fundamental tool in image processing and computer vision. It identifies points in a digital.
CSMA/CA Simulation  Course Name: Networking Level(UG/PG): UG  Author(s) : Amitendu Panja, Veedhi Desai  Mentor: Aruna Adil *The contents in this ppt.
Welcome This is a document to explains the chosen concept to the animator. This will take you through a 5 section process to provide the necessary details.
Gaussian Smoothing Gaussian Smoothing is the result of blurring an image by a Gaussian function. It is also known as Gaussian blur.  Course Name: Digital.
CSMA/CD Simulation Carrier Sense Multiple Access (CSMA), although more efficient than ALOHA or slotted ALOHA, still has one glaring inefficiency: When.
Median Filtering In signal processing, it is often desirable to be able to perform some kind of noise reduction on an image or signal. The median filter.
Electrical Resistivity in Superconductors The electrical resistivity of many metals and alloys drops suddenly to zero when the specimen is cooled to a.
Go-Back-N ARQ (Sliding Window Protocol) Go-Back-N is an instance of the Automatic Repeat-request (ARQ) Protocol, in which the sending process continues.
Document that explains the chosen concept to the animator 1.
Document that explains the chosen concept to the animator 1.
Process Scheduling In multiprogramming systems, when there is more than one ready process, the operating system must decide which one to activate. The.
Welcome This is a document to explains the chosen concept to the animator. This will take you through a 5 section process to provide the necessary details.
Document that explains the chosen concept to the animator
Learning Objectives After interacting with this Learning Object, the learner will be able to: Explain the process of collision detection in CSMA/CD.
Document that explains the chosen concept to the animator
Prof. Saravanan Vijayakumaran
Standard Version of Starting Out with C++, 4th Edition
Welcome 1 This is a document to explains the chosen concept to the animator. This will take you through a 5 section process to provide the necessary details.
Dilation The basic morphological operations applied to either grayscale or binary images are Erosion and Dilation. Erosion shrinks image objects while.
Closing One of the important morphological operations applied to either grayscale or binary images is Closing. It is derived from the fundamental operations.
Erosion The basic morphological operations applied to either grayscale or binary images are Erosion and Dilation. Erosion shrinks image objects while.
Virtual Memory Virtual memory is a technique which gives an application program the impression that it has contiguous working memory, while in fact it.
Binary Search A binary search algorithm finds the position of a specified value within a sorted array. Binary search is a technique for searching an ordered.
Sorted Linked List A linked list is a data structure that consists of a sequence of data records such that in each record there is a field that contains.
Prof. Saravanan Vijayakumaran
Document that explains the chosen concept to the animator
Discrete Convolution of Two Signals
Continuous Time Convolution
Welcome 1 This is a document to explains the chosen concept to the animator. This will take you through a 5 section process to provide the necessary details.
Document that explains the chosen concept to the animator
Principles of Computing – UFCFA3-30-1
Party Problem The simplest example of Ramsey theory. It is also known as the ‘Maximum Clique Problem’. A clique of a graph is a complete sub graph of the.
Opening One of the important morphological operations applied to either grayscale or binary images is Opening. It is derived from the fundamental operations.
Image Sharpening using Laplacian
Presentation transcript:

Linear Search Linear Search is a fundamental search algorithm. Linear search, also known as sequential search, is a process that checks every element in the list sequentially until the desired element is found.  Course Name: Design and Analysis of Algorithms Level(UG/PG): UG  Author : Phani Swathi Chitta  Mentor : Aruna Adil *The contents in this ppt are licensed under Creative Commons Attribution-NonCommercial-ShareAlike 2.5 India license

Learning Objectives After interacting with this Learning Object, the learner will be able to: Explain how to find an element in an array using “Linear Search”

Definitions of the components/Keywords: This algorithm is suitable for searching a list of data for a particular value. Linear search can be done in either a sorted or an unsorted array. In the Linear search, each element of an array is sequentially compared with the desired element to find the location of the desired element. Desired element / Item / Search value: An element that is being searched for in the array.  Process to find the desired element using Linear search: 1. Length of the array is defined. 2. A counter will be initialized (say i = 0) and its value is compared with the length of the array. 3. If i is less than the length of the array, desired element is compared with the i th element of the array i. The i th element in the array is compared with the desired element. If the element matches the desired element, the location of desired element (i) is returned ii. If the element doesn’t match, the counter i is incremented to i+1 4. If i is greater than the length of the array, it means the end of the array has been reached. 5. Repeat steps 3-5 until the desired element is found or end of the array is reached

Definitions of the components/Keywords: The advantage of linear search is its simplicity: concept is easy to understand and implementation is straight-forward. The main disadvantage of linear search is that it has a very poor efficiency. The complexity of any searching method is determined from the number of comparisons performed among the elements of the list in order to find the element. The time required for a search operation depends on the complexity of the searching algorithm. The general complexity of Linear search is O(n) For a list with n items, the best case is when the value is equal to the first element of the list, in which case only one comparison is needed The worst case is when the value is not in the list (or occurs only once at the end of the list), in which case n comparisons are needed.

Master Layout Give START, PAUSE and STOP buttons Give a STEPPER button that allows the user to follow the simulation procedure step by step. After every step the simulation pauses until the STEPPER button is pressed Give a text area to display the status of the simulation Give a slider bar to control the speed of animation Fig. A Simulation Area Current Index: Give the value of the Index at that particular time Legend: Array Desired element Desired element Match Current Index Array or list Index ** For animator: All digits written in white in the array are “elements” or “values at index n “(n refers to index number ex. value at index 4 = 14).

Step 1: Case - 1 I nstruction for the animator T ext to be displayed in the working area (DT) When the user clicks START, show the figure in master layout without labeling. Display array with its values inside and numbers above it. Then show the box in violet and the text “ Current Index: 0” In parallel show the text and arrow in red as shown in figure. Then blink the orange box and blue box to which red arrow is pointing to. While blinking, a text box saying “ Comparing 21 and 8” must be appeared. If the values in those 2 boxes doesn’t match, the text and the arrow in red should move rightwards. Always update the value in violet box accordingly. The text in DT should appear in parallel to the figure Array of 8 elements with indices Current index is i=0 The desired element to search for in the array is is compared with the element at i=0 21 ≠ 8 Therefore i is incremented to i+1 The incremented i is compared with the length of the array < 8 TRUE so will go for next comparison 21 i= Legend: Array Desired element Desired element Match Current Index Current index: Comparing 21 and 8 21 Search Value:

Step 2: I nstruction for the animator T ext to be displayed in the working area (DT) show the box in violet and the text “ Current Index: 1” In parallel show the text and arrow in red as shown in figure. Then blink the orange box and blue box to which red arrow is pointing to. While blinking, a text box saying “ Comparing 21 and 48” must be appeared. If the values in those 2 boxes doesn’t match, the text and the arrow in red should move rightwards. Always update the value in violet box accordingly. The text in DT should appear in parallel to the figure Current index is i=1 The desired element to search for in the array is is compared with the element at i=1 21 ≠ 48 Therefore i is incremented to i+1 The incremented i is compared with the length of the array < 8 TRUE so will go for next comparison i= Current index: 1 Legend: Array Desired element Desired element Match Current Index Comparing 21 and Search Value:

Step 3: I nstruction for the animator T ext to be displayed in the working area (DT) show the box in violet and the text “ Current Index: 2” In parallel show the text and arrow in red as shown in figure. Then blink the orange box and blue box to which red arrow is pointing to. While blinking, a text box saying “ Comparing 21 and 35” must be appeared. If the values in those 2 boxes doesn’t match, the text and the arrow in red should move rightwards. Always update the value in violet box accordingly. The text in DT should appear in parallel to the figure Current index is i=2 The desired element to search for in the array is is compared with the element at i=2 21 ≠ 35 Therefore i is incremented to i+1 The incremented i is compared with the length of the array < 8 TRUE so will go for next comparison i= Current index: 2 Legend: Array Desired element Desired element Match Current Index Comparing 21 and Search Value:

Step 4: I nstruction for the animator T ext to be displayed in the working area (DT) show the box in violet and the text “ Current Index: 3” In parallel show the text and arrow in red as shown in figure. Then blink the orange box and blue box to which red arrow is pointing to. While blinking, a text box saying “ Comparing 21 and 60” must be appeared. If the values in those 2 boxes doesn’t match, the text and the arrow in red should move rightwards. Always update the value in violet box accordingly. The text in DT should appear in parallel to the figure Current index is i=3 The desired element to search for in the array is is compared with the element at i=3 21 ≠ 60 Therefore i is incremented to i+1 The incremented i is compared with the length of the array < 8 TRUE so will go for next comparison i= Current index: 3 Legend: Array Desired element Desired element Match Current Index Comparing 21 and Search Value:

Step 5: I nstruction for the animator T ext to be displayed in the working area (DT) show the box in violet and the text “ Current Index: 4” In parallel show the text and arrow in red as shown in figure. Then blink the orange box and blue box to which red arrow is pointing to. While blinking, a text box saying “ Comparing 21 and 14” must be appeared. If the values in those 2 boxes doesn’t match, the text and the arrow in red should move rightwards. Always update the value in violet box accordingly. The text in DT should appear in parallel to the figure Current index is i=4 The desired element to search for in the array is is compared with the element at i=4 21 ≠ 14 Therefore i is incremented to i+1 The incremented i is compared with the length of the array < 8 TRUE so will go for next comparison i= Current index: 4 Legend: Array Desired element Desired element Match Current Index Comparing 21 and Search Value:

Step 6: I nstruction for the animator T ext to be displayed in the working area (DT) show the box in violet and the text “ Current Index: 5” In parallel show the text and arrow in red as shown in figure. Then blink the orange box and blue box to which red arrow is pointing to. While blinking, a text box saying “ Comparing 21 and 52” must be appeared. If the values in those 2 boxes doesn’t match, the text and the arrow in red should move rightwards. Always update the value in violet box accordingly. The text in DT should appear in parallel to the figure Current index is i=5 The desired element to search for in the array is is compared with the element at i=5 21 ≠ 52 Therefore i is incremented to i+1 The incremented i is compared with the length of the array < 8 TRUE so will go for next comparison i= Current index: 5 Legend: Array Desired element Desired element Match Current Index Comparing 21 and Search Value:

Step 7: I nstruction for the animator T ext to be displayed in the working area (DT) show the box in violet and the text “ Current Index: 6” In parallel show the text and arrow in red as shown in figure. Then blink the orange box and blue box to which red arrow is pointing to. While blinking, a text box saying “ Comparing 21 and 21” must be appeared. Now the values in those 2 boxes match. Once the values match change the color of both the boxes to green. Display the location of desired element. With the text “ Element found at location 6” Always update the value in violet box accordingly. The text in DT should appear in parallel to the figure Current index is i=6 The desired element to search for in the array is is compared with the element at i=6 21 = 21 The desired element is found at location i= Current index: 6 Legend: Array Desired element Desired element Match Current Index Comparing 21 and Search Value: Element found at location 6

Step 8: Case - 2 I nstruction for the animator T ext to be displayed in the working area (DT) When the user clicks START, show the figure in master layout without labeling. Display array with its values inside and numbers above it. Then show the box in violet and the text “ Current Index: 0” In parallel show the text and arrow in red as shown in figure. Then blink the orange box and blue box to which red arrow is pointing to. While blinking, a text box saying “ Comparing 30 and 8” must be appeared. If the values in those 2 boxes doesn’t match, the text and the arrow in red should move rightwards. Always update the value in violet box accordingly. The text in DT should appear in parallel to the figure Array of 8 elements with indices Current index is i=0 The desired element to search for in the array is is compared with the element at i=0 30 ≠ 8 Therefore i is incremented to i+1 The incremented i is compared with the length of the array < 8 TRUE so will go for next comparison 30 i= Legend: Array Desired element Desired element Match Current Index Current index: Comparing 30 and 8 30 Search Value:

Step 9: I nstruction for the animator T ext to be displayed in the working area (DT) show the box in violet and the text “ Current Index: 1” In parallel show the text and arrow in red as shown in figure. Then blink the orange box and blue box to which red arrow is pointing to. While blinking, a text box saying “ Comparing 30 and 48” must be appeared. If the values in those 2 boxes doesn’t match, the text and the arrow in red should move rightwards. Always update the value in violet box accordingly. The text in DT should appear in parallel to the figure Current index is i=1 The desired element to search for in the array is is compared with the element at i=1 30 ≠ 48 Therefore i is incremented to i+1 The incremented i is compared with the length of the array < 8 TRUE so will go for next comparison i= Current index: 1 Legend: Array Desired element Desired element Match Current Index Comparing 30 and Search Value:

Step 10: 10: I nstruction for the animator T ext to be displayed in the working area (DT) show the box in violet and the text “ Current Index: 2” In parallel show the text and arrow in red as shown in figure. Then blink the orange box and blue box to which red arrow is pointing to. While blinking, a text box saying “ Comparing 30 and 35” must be appeared. If the values in those 2 boxes doesn’t match, the text and the arrow in red should move rightwards. Always update the value in violet box accordingly. The text in DT should appear in parallel to the figure Current index is i=2 The desired element to search for in the array is is compared with the element at i=2 30 ≠ 35 Therefore i is incremented to i+1 The incremented i is compared with the length of the array < 8 TRUE so will go for next comparison i= Current index: 2 Legend: Array Desired element Desired element Match Current Index Comparing 30 and Search Value:

Step 11: I nstruction for the animator T ext to be displayed in the working area (DT) show the box in violet and the text “ Current Index: 3” In parallel show the text and arrow in red as shown in figure. Then blink the orange box and blue box to which red arrow is pointing to. While blinking, a text box saying “ Comparing 30 and 60” must be appeared. If the values in those 2 boxes doesn’t match, the text and the arrow in red should move rightwards. Always update the value in violet box accordingly. The text in DT should appear in parallel to the figure Current index is i=3 The desired element to search for in the array is is compared with the element at i=3 30 ≠ 60 Therefore i is incremented to i+1 The incremented i is compared with the length of the array < 8 TRUE so will go for next comparison i= Current index: 3 Legend: Array Desired element Desired element Match Current Index Comparing 30 and Search Value:

Step 12: I nstruction for the animator T ext to be displayed in the working area (DT) show the box in violet and the text “ Current Index: 4” In parallel show the text and arrow in red as shown in figure. Then blink the orange box and blue box to which red arrow is pointing to. While blinking, a text box saying “ Comparing 30 and 14” must be appeared. If the values in those 2 boxes doesn’t match, the text and the arrow in red should move rightwards. Always update the value in violet box accordingly. The text in DT should appear in parallel to the figure Current index is i=4 The desired element to search for in the array is is compared with the element at i=4 30 ≠ 14 Therefore i is incremented to i+1 The incremented i is compared with the length of the array < 8 TRUE so will go for next comparison i= Current index: 4 Legend: Array Desired element Desired element Match Current Index Comparing 30 and Search Value:

Step 13: I nstruction for the animator T ext to be displayed in the working area (DT) show the box in violet and the text “ Current Index: 5” In parallel show the text and arrow in red as shown in figure. Then blink the orange box and blue box to which red arrow is pointing to. While blinking, a text box saying “ Comparing 30 and 52” must be appeared. If the values in those 2 boxes doesn’t match, the text and the arrow in red should move rightwards. Always update the value in violet box accordingly. The text in DT should appear in parallel to the figure Current index is i=5 The desired element to search for in the array is is compared with the element at i=5 30 ≠ 52 Therefore i is incremented to i+1 The incremented i is compared with the length of the array < 8 TRUE so will go for next comparison i= Current index: 5 Legend: Array Desired element Desired element Match Current Index Comparing 30 and Search Value:

Step 14: I nstruction for the animator T ext to be displayed in the working area (DT) show the box in violet and the text “ Current Index: 6” In parallel show the text and arrow in red as shown in figure. Then blink the orange box and blue box to which red arrow is pointing to. While blinking, a text box saying “ Comparing 30 and 21” must be appeared. If the values in those 2 boxes doesn’t match, the text and the arrow in red should move rightwards. Always update the value in violet box accordingly. The text in DT should appear in parallel to the figure Current index is i=6 The desired element to search for in the array is is compared with the element at i=6 30 ≠ 21 Therefore i is incremented to i+1 The incremented i is compared with the length of the array < 8 TRUE so will go for next comparison i= Current index: 6 Legend: Array Desired element Desired element Match Current Index Comparing 30 and Search Value:

Step 15: I nstruction for the animator T ext to be displayed in the working area (DT) show the box in violet and the text “ Current Index: 6” In parallel show the text and arrow in red as shown in figure. Then blink the orange box and blue box to which red arrow is pointing to. While blinking, a text box saying “ Comparing 30 and 16” must be appeared. If the values in those 2 boxes doesn’t match, the text and the arrow in red should move rightwards. Always update the value in violet box accordingly. After the end of the array display the text “Element not found” The text in DT should appear in parallel to the figure Current index is i=7 The desired element to search for in the array is is compared with the element at i=7 30 ≠ 16 Therefore i is incremented to i+1 The incremented i is compared with the length of the array < 8 FALSE implies end of the array The desired element is not found in the array i= Current index: 7 Legend: Array Desired element Desired element Match Current Index Comparing 30 and Search Value: Element not found

Introduction Credits 21 Definitions Test your understanding (questionnaire) ‏ Lets Sum up (summary) ‏ Want to know more… (Further Reading) ‏ Try it yourself Interactivity: Analogy Slide 1 Slide 3 Slide Slide 27 Electrical Engineering Give a dropdown to select the array size from Place an input box and an ENTER button to enter the values in the array. After ENTER is pressed, show the array with indices on the top in the simulation area. Give another input box to enter the desired element value After the desired element value is entered, show the value in the simulation area. After desired element value is shown, enable START button. Once the animation is started, then enable PAUSE and RESET buttons. Array Size :Values in the array: : In the input box the user will input all the numerical values that he/she wants to be in the array. Desired element Value :

Questionnaire 1.Which of the following are TRUE about Linear search? I. It is a sequential search II. Its complexity is O(n) III. Its efficiency is poor Answers: a) I and II b) Only I c) II and III d) I, II and III

Questionnaire 2. The Worst case occurs in linear search algorithm when Answers: a) Item is somewhere in the middle of the array b) Item is not in the array at all c) Item is the last element in the array d) Item is the last element in the array or is not there at all

Questionnaire 3. For a searching operation to be done using linear search, the array can be Answers: a) Sorted b) Unsorted c) either sorted or unsorted

Questionnaire 4. How many maximum comparisons can be done on an array of 10 elements using linear search? Answers: a) 5 b) 10 c) 20 d) None of the above

Questionnaire 5. I.The time required for a search operation depends on complexity. II. Linear search is difficult to understand which of the above are TRUE? Answers: a) I and II b) Only I c) Only II d) None

Links for further reading Reference websites: Books: “Introduction to Algorithm” Thomas H. Coremen