Searching and Sorting Techniques 1. To learn and appreciate the following concepts Searching Technique  Linear Search Sorting Technique  Bubble Sort.

Slides:



Advertisements
Similar presentations
Chapter 3 Brute Force Brute force is a straightforward approach to solving a problem, usually directly based on the problem’s statement and definitions.
Advertisements

Operations on Arrays. Operation on Array Data Structures  Traversal  Selection  Searching  Insertion  Deletion  Sorting.
Copyright © 2012 Pearson Education, Inc. Chapter 8: Searching and Sorting Arrays.
Sorting Techniques –Selection Sort –Bubble Sort. Selection Sort Working : “SELECT” an Element and Put in PROPER PLACE Description : 1. From position 0,
Binary Search Visualization i j.
Arrays Arrays are data structures consisting of data items of the same type. Arrays are ‘static’ entities, in that they remain the same size once they.
1 ICS103 Programming in C Lecture 14: Searching and Sorting.
Searching Algorithms. Lecture Objectives Learn how to implement the sequential search algorithm Learn how to implement the binary search algorithm To.
Insertion Sorting Lecture 21. Insertion Sort Start from element 2 of list location 1 –In first iteration: Compare element 1 with all of its elements to.
Searches & Sorts V Deena Engel’s class Adapted from W. Savitch’s text An Introduction to Computers & Programming.
1 Lecture 23:Applications of Arrays Introduction to Computer Science Spring 2006.
Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement.
Understanding BubbleSort CS-502 (EMC) Fall Understanding BubbleSort CS-502, Operating Systems Fall 2009 (EMC) (Slides include materials from Modern.
Searching Arrays Linear search Binary search small arrays
Sorting 2 An array a is sorted (ascending order) if: for all i a[i]  a[j] Probably the most well-studied algorithmic problem in Computer Science There.
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.
Algorithms and Data Structures Sorting and Selection.
Fundamental in Computer Science Sorting. Sorting Arrays (Basic sorting algorithms) Use available main memory Analyzed by counting #comparisons and #moves.
- SEARCHING - SORTING.  Given:  The array  The search target: the array element value we are looking for  Algorithm:  Start with the initial array.
CS212: DATASTRUCTURES Lecture 3: Searching 1. Search Algorithms Sequential Search It does not require an ordered list. Binary Search It requires an ordered.
1 Search Algorithms Sequential Search (Linear Search) Binary Search Rizwan Rehman Centre for Computer Studies Dibrugarh University.
Fall 2013 Instructor: Reza Entezari-Maleki Sharif University of Technology 1 Fundamentals of Programming Session 17 These.
One Dimensional Arrays (Part2) Sorting Algorithms Searching Algorithms Character Strings The string Class. 1.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 8: Searching and Sorting Arrays.
Copyright © 2012 Pearson Education, Inc. Chapter 8: Searching and Sorting Arrays.
Computer Science: A Structured Programming Approach Using C1 8-5 Sorting One of the most common applications in computer science is sorting—the process.
Lecture 5 Searching and Sorting Richard Gesick. The focus Searching - examining the contents of the array to see if an element exists within the array.
Lecture 12. Searching Algorithms and its analysis 1.
Computer Science Searching & Sorting.
Passing Other Objects Strings are called immutable which means that once a String object stores a value, it never changes –recall when we passed a message.
Chapter 8 Searching and Sorting Arrays Csc 125 Introduction to C++ Fall 2005.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 8: Searching and Sorting Arrays.
Chapter Searching and Sorting Arrays 8. Introduction to Search Algorithms 8.1.
Arrays.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Topics to be covered  Introduction to array Introduction to array  Types of array Types of array  One dimensional array One dimensional array  Declaration.
PRESENTATION ON SEARCHING SEARCHING Searching is the method to find element from the list of the elements. If element is found then it.
+ ARRAYS - SEARCHING - SORTING Dr. Soha S. Zaghloul updated by Rasha M. AL_Eidan 2015.
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.
Data Structures & Algorithms Week 4. CHAPTER 3: SEARCHING TECHNIQUES 1. LINEAR (SEQUENTIAL) SEARCH 2.BINARY SEARCH 3. COMPLEXITY OF ALGORITHMS.
Sorting Dr. Yingwu Zhu. Sorting Consider list x 1, x 2, x 3, … x n We seek to arrange the elements of the list in order Ascending or descending Some O(n.
LAB#6. 2 Overview Before we go to our lesson we must know about : 1. data structure. 2.Algorithms. data structure is an arrangement of data in a computer.
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.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
Sorting & Searching Geletaw S (MSC, MCITP). Objectives At the end of this session the students should be able to: – Design and implement the following.
Chapter 3: Sorting and Searching Algorithms 3.1 Searching Algorithms.
RECURSIONL27-L28. To learn and the following concepts To design a recursive algorithm To solve problems using recursion To understand the relationship.
Basic Sorting Algorithms Dr. Yingwu Zhu. Sorting Problem Consider list x 1, x 2, x 3, … x n Goal: arrange the elements of the list in order Ascending.
 Introduction to Search Algorithms  Linear Search  Binary Search 9-2.
CSC 142 Q 1 CSC 142 Sorting [Reading: chapter 11].
Arrays Department of Computer Science. C provides a derived data type known as ARRAYS that is used when large amounts of data has to be processed. “ an.
Sorting and Searching Bubble Sort Linear Search Binary Search.
SORTING Sorting is storage of data in some order, it can be in ascending or descending order. The term Sorting comes along-with the term Searching. There.
Array Sort. Sort Pass 1 Sort Pass 2 Sort Pass 3.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 8: Searching and Sorting Arrays.
SORTING Sorting is the process of rearranging a set of objects in a specific order. Internal sorting (sorting of arrays) External sorting (sorting of sequential.
Sorting Algorithms. Sorting Sorting is a process that organizes a collection of data into either ascending or descending order. public interface ISort.
Searching and Sorting Arrays
Arrays (Operations on Arrays)
Topics discussed in this section:
Sorting Data are arranged according to their values.
ARRAYS.
searching Concept: Linear search Binary search
Sorting Data are arranged according to their values.
Searching and Sorting Arrays
Sorting Techniques Selection Sort Bubble Sort.
Linear search A linear search sequentially moves through your list looking for a matching value. 1. The element is found, i.e. a[i] = x. 2. The entire.
Lecture 9-2 : Array Examples : Bubble Sort and Binary Search
Passing Arrays to functions
Searching and Sorting Arrays
Presentation transcript:

Searching and Sorting Techniques 1

To learn and appreciate the following concepts Searching Technique  Linear Search Sorting Technique  Bubble Sort Objectives 2

Searching refers to finding whether a data item is present in the set of items or not. Sorting refers to the arrangement of data in a particular order. Sorting and searching have many applications in the area of computers. Searching & Sorting 3

Linear search The Linear Search is applied on the set of items that are not arranged in any particular order. In linear search, the searching process starts from the first item. The searching is continued till either the item is found or the end of the list is reached indicating that the item is not found. 4

Linear search- Example 1 5

Linear search- Example-2 6

void main() { int a[100],i,n,key,found=0; cout<<"enter no of elements"; cin>>n; for(i=0;i<n;i++) cin>>a[i]; cout<<"enter the element to be searched"; cin>>key; WAP to search an element in an array using linear search for(i=0; i<n; i++) { if(a[i]==key) { found=1; break; } } if(found==1) cout<<“Element is found ; else cout<<“Element is not found“; } 7

Bubble Sort Algorithm 8

Bubble Sort- Illustration 9

10

int main() { int a[10],i,j,temp,n; cout<<"Enter no of elements\n"; cin>>n; cout<<"Enter array elements\n"; for(i=0;i<n;i++) { cin>>a[i]; } cout<<"The elements of array are:\n"; for(i=0;i<n;i++) cout<<a[i]<<"\t"; 11 To arrange the array elements in ascending/descending order using Bubble sort for(i=0;i<n-1;i++) { for(j=0;j<n-i-1;j++) { if(a[j]>a[j+1]) // a[j]<a[j+1] { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } cout<<"\nThe elements of array after sorting are:\n"; for(i=0;i<n;i++) cout<<a[i]<<"\t"; }