1.1 Data Structure and Algorithm Lecture 1 Array Record Sequential Search Binary Search Bubble Sort Recursion Complexity Topics.

Slides:



Advertisements
Similar presentations
Recursion.
Advertisements

HST 952 Computing for Biomedical Scientists Lecture 9.
Chapter 7 Sorting Part I. 7.1 Motivation list: a collection of records. keys: the fields used to distinguish among the records. One way to search for.
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.
Analysis of Recursive Algorithms What is a recurrence relation? Forming Recurrence Relations Solving Recurrence Relations Analysis Of Recursive Factorial.
1 CSE1301 Computer Programming Lecture 31: List Processing (Search)
1 ICS103 Programming in C Lecture 14: Searching and Sorting.
Problem Solving #6: Search & Sort ICS Outline Review of Key Topics Review of Key Topics Problem 1: Recursive Binary Search … Problem 1: Recursive.
Searching Algorithms. Lecture Objectives Learn how to implement the sequential search algorithm Learn how to implement the binary search algorithm To.
 2003 Prentice Hall, Inc. All rights reserved. 1 Sorting Arrays Sorting data –Important computing application –Virtually every organization must sort.
1 Section 3.5 Recursive Algorithms. 2 Sometimes we can reduce solution of problem to solution of same problem with set of smaller input values When such.
1 Searching Algorithms Overview  What is Searching?  Linear Search and its Implementation.  Brief Analysis of Linear Search.  Binary Search and its.
Searching Arrays Linear search Binary search small arrays
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
Chapter 8 ARRAYS Continued
1 Introduction to Arrays Problem: –Input 5 scores, compute total, average –Input Example –test scores,employees,temperatures.
Array operations II manipulating arrays and measuring performance.
Part 2. Searching Arrays Looking for a specific element in an array E.g., whether a certain score (85) is in a list of scores Linear search Binary search.
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 10 Scott Marino.
Building Java Programs Chapter 13 Searching reading: 13.3.
CPT: Search/ Computer Programming Techniques Semester 1, 1998 Objectives of these slides: –to discuss searching: its implementation,
EENG212 Algorithms and Data Structures
1 Lecture 5: Part 1 Searching Arrays Searching Arrays: Linear Search and Binary Search Search array for a key value Linear search  Compare each.
Chapter 2 Array Data Structure Winter Array The Array is the most commonly used Data Storage Structure. It’s built into most Programming languages.
SEARCHING (Linear/Binary). Searching Algorithms  method of locating a specific item of information in a larger collection of data.  two popular search.
CSE1301 Computer Programming: Lecture 26 List Processing (Search)
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
February 4, 2005 Searching and Sorting Arrays. Searching.
CS 162 Intro to Programming II Searching 1. Data is stored in various structures – Typically it is organized on the type of data – Optimized for retrieval.
Searching Dr. Jose Annunziato. Linear Search Linear search iterates over an array sequentially searching for a matching element int linearSearch(int haystack[],
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Searching Course Lecture Slides 28 May 2010 “ Some things Man was never.
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.
SEARCHING.  This is a technique for searching a particular element in sequential manner until the desired element is found.  If an element is found.
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.
Searching Damian Gordon. Google PageRank Damian Gordon.
1 ICS103 Programming in C Lecture 14: Searching and Sorting.
“Enthusiasm releases the drive to carry you over obstacles and adds significance to all you do.” – Norman Vincent Peale Thought for the Day.
Data Structures Using C++ 2E Chapter 9 Searching and Hashing Algorithms.
Chapter 12 Binary Search and QuickSort Fundamentals of Java.
Week # 2: Arrays.  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently  Types of data.
STARTING OUT WITH STARTING OUT WITH Class 3 Honors.
Searching Algorithms Sequential Search – inspects every items in a sequential manner. Example, in an array, all values in the array are checked from index.
Objectives At the end of the class, students are expected to be able to do the following: Understand the searching technique concept and the purpose of.
Sorting & Searching Review. Selection Sort 1. Find the smallest element 2. Move to the front of the array (swap with front) 3. Repeat Steps 1&2, but ignoring.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Data Structures and Algorithms Searching Algorithms M. B. Fayek CUFE 2006.
Lecture 9COMPSCI.220.FS.T Lower Bound for Sorting Complexity Each algorithm that sorts by comparing only pairs of elements must use at least 
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
Chapter 10: Class Vector and String, and Enumeration Types Java Programming: Program Design Including Data Structures Program Design Including Data Structures.
CS212: DATASTRUCTURES Lecture 3: Searching 1. Lecture Contents  searching  Sequential search algorithm.  Binary search algorithm. 2.
Higher Computing Science 2016 Prelim Revision. Topics to revise Computational Constructs parameter passing (value and reference, formal and actual) sub-programs/routines,
Data Structure and Algorithms
1 11/30/05CS150 Introduction to Computer Science 1 Structs.
Chapter 3: Sorting and Searching Algorithms 3.1 Searching Algorithms.
ARRAYS Lecture void reverse (int x[], int size) { int i; for (i=0; i< (size/2); i++) temp = x[size-i-1] ; x[size-1-1] = x[i] ; x[i] = temp;
Binary Search Manolis Koubarakis Data Structures and Programming Techniques 1.
Sorting Algorithms. Sorting Sorting is a process that organizes a collection of data into either ascending or descending order. public interface ISort.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 6 Arrays.
Introduction to Programming Lecture 12. Today’s Lecture Includes Strings ( character arrays ) Strings ( character arrays ) Algorithms using arrays Algorithms.
Searching Arrays Linear search Binary search small arrays
ICS103 Programming in C Lecture 14: Searching and Sorting
Chapter 7 Single-Dimensional Arrays
Sorting Data are arranged according to their values.
Recursive Binary Search
Selection Sort Find the smallest value in the array. Put it in location zero. Find the second smallest value in the array and put it in location 1. Find.
Sorting Data are arranged according to their values.
Cs212: DataStructures Lecture 3: Searching.
Exercise 5 1. We learned bubble sort during class. This problem requires you to modify the code for bubble sorting method to implement the selection sorting.
ㅎㅎ Fourth step for Learning C++ Programming Call by value
Presentation transcript:

1.1 Data Structure and Algorithm Lecture 1 Array Record Sequential Search Binary Search Bubble Sort Recursion Complexity Topics

1.2 Data Structure and Algorithm Array An array is a sequence of elements. All the elements of an array must be of the same type (e.g. integer). Each elements can be selected by specifying its position index int list[10] Dhaka index char city[5]

1.3 Data Structure and Algorithm Record A record/structure is a collection of one or more variables, possibly of different types. An array is a sequence of elements all having the same type and size, whereas a record or structure is a sequence of elements having different types and sizes. Each element of a record is its member. Employee: Record name:char[20] address:char[50] salary: real struct employee{ char name[20]; char address[50]; float salary; }; Fig: C Convention

1.4 Data Structure and Algorithm Sequential Search [ Find the location where list array keeps the value of k ] sequential_search(k) returns integer Begin i = 0 while i k do i = i+1 if i<array_size then return i else return -1 End

1.5 Data Structure and Algorithm “C” implementation of Sequential Search #include int list[10] = {5,6,1,3,4,1,7,2,0,3}; int array_size = 10; int sequential_search(int k){ int i = 0; while ( (i<array_size) && ( list[i] != k) ) i++; if (i<array_size) return i; else return -1; } void main(){ int pos = sequential_search(2); printf(“The position is:%d”,pos); }

1.6 Data Structure and Algorithm Binary Search [ Find the location where sorted table array keeps the value of k ] binary_search(k): returns integer BEGIN l = 0 h = array_size found = 0; while l<h and found = 0 do m= (l+h)/2 //find the middle element xm = table[m] case xm<k: l = m+1 xm>k: h = m-1 xm=k: found = 1 if found then return m else return -1 END

1.7 Data Structure and Algorithm “C” Implementation of Binary Search #include int table[10] = {1,5,8,12,15,20,34,40,55,67}; int array_size = 10; int binary_search(int k){ int l =0; int h = array_size; int found =0,m,xm; while ( (l<h) && (found == 0) ){ m = (l+h)/2; xm = table[m]; if (xm<k) l = m+1; else if (xm>k) h = m-1; else found = 1; } if (found) return m; else return -1; } void main(){ int pos = binary_search(20); printf("The position is:%d",pos); }

1.8 Data Structure and Algorithm Recursive Binary Search [ Find the location where sorted table array keeps the value of k ] binary_search(l,h,k) BEGIN if l>h index = -1 else m= (l+h)/2 //find the middle element xm = table[m] case xm<k: binary_search(m+1,h) xm>k: binary_search(l,m-1) xm=k: index=m END

1.9 Data Structure and Algorithm Bubble Sort For i=0 to n-2 do BEGIN For j = i+1 to n-1 do BEGIN if list[i] > x[j] then swap list[i] and list[j] END

1.10 Data Structure and Algorithm Complexity Generally the complexity of an algorithm is measured by the two factors:  Time complexity  Space complexity Sequential search : O(n) Binary search: O(log 2 n) Bubble sort: O(n 2 )