General Computer Science for Engineers CISC 106 Lecture 08

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Quicksort
Advertisements

General Computer Science for Engineers CISC 106 Midterm 2 Review James Atlas Computer and Information Sciences 11/06/2009.
HST 952 Computing for Biomedical Scientists Lecture 9.
General Computer Science for Engineers CISC 106 Lecture 08 James Atlas Computer and Information Sciences 07/01/2009.
Computer Science 112 Fundamentals of Programming II Finding Faster Algorithms.
CPSC 171 Introduction to Computer Science More Efficiency of Algorithms.
Search algorithm In computer science, a search algorithm is an algorithm that takes a problem as input and returns a solution to the problem, usually after.
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 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:
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Insertion sort, Merge sort COMP171 Fall Sorting I / Slide 2 Insertion sort 1) Initially p = 1 2) Let the first p elements be sorted. 3) Insert the.
Recursion Chapter 11 Chapter 11.
General Computer Science for Engineers CISC 106 Lecture 19 Dr. John Cavazos Computer and Information Sciences 04/06/2009.
General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 10/23/2009.
June Searching CE : Fundamental Programming Techniques 16 Searching1.
General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 10/18/2009.
Merge sort, Insertion sort
Objectives Learn how to implement the sequential search algorithm Explore how to sort an array using the selection sort algorithm Learn how to implement.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (3) Recurrence Relation 11/11 ~ 11/14/2008 Yang Song.
1 Foundations of Software Design Fall 2002 Marti Hearst Lecture 20: Sorting.
Merge sort, Insertion sort. Sorting I / Slide 2 Sorting * Selection sort or bubble sort 1. Find the minimum value in the list 2. Swap it with the value.
General Computer Science for Engineers CISC 106 James Atlas Computer and Information Sciences 10/21/2009.
Sorting and Searching Arrays CSC 1401: Introduction to Programming with Java Week 12 – Lectures 1 & 2 Wanda M. Kunkle.
HOW TO SOLVE IT? Algorithms. An Algorithm An algorithm is any well-defined (computational) procedure that takes some value, or set of values, as input.
General Computer Science for Engineers CISC 106 Lecture 07 James Atlas Computer and Information Sciences 06/29/2009.
Chapter 16: Searching, Sorting, and the vector Type.
1 Lecture 16: Lists and vectors Binary search, Sorting.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
Searching and Sorting Topics Linear and Binary Searches Selection Sort Bubble Sort.
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.
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.
FASTER SORTING using RECURSION : QUICKSORT 2014-T2 Lecture 16 School of Engineering and Computer Science, Victoria University of Wellington COMP 103 Marcus.
Merge sort, Insertion sort. Sorting I / Slide 2 Sorting * Selection sort (iterative, recursive?) * Bubble sort.
CSC 211 Data Structures Lecture 13
By: Lokman Chan Recursive Algorithm Recursion Definition: A function that is define in terms of itself. Goal: Reduce the solution to.
CS 61B Data Structures and Programming Methodology July 21, 2008 David Sun.
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 and Sorting Recursion, Merge-sort, Divide & Conquer, Bucket sort, Radix sort Lecture 5.
1 Searching and Sorting Searching algorithms with simple arrays Sorting algorithms with simple arrays –Selection Sort –Insertion Sort –Bubble Sort –Quick.
General Computer Science for Engineers CISC 106 Lecture 2^4 Roger Craig Computer and Information Sciences 03/23/2009.
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.
 MergeSort is a sorting algorithm which is more on the advanced end.  It is very fast, but unfortunately uses up a lot of memory due to the recursions.
M180: Data Structures & Algorithms in Java Sorting Algorithms Arab Open University 1.
8.1 8 Algorithms Foundations of Computer Science  Cengage Learning.
Lecture 4 1 Advance Analysis of Algorithms. Selection Sort 2 Summary of Steps Find the smallest element in the array Exchange it with the element in the.
ICS201 Lecture 21 : Sorting King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science Department.
Sorting. Sorting Sorting is important! Things that would be much more difficult without sorting: –finding a telephone number –looking up a word in the.
Lecture # 6 1 Advance Analysis of Algorithms. Divide-and-Conquer Divide the problem into a number of subproblems Similar sub-problems of smaller size.
General Computer Science for Engineers CISC 106 Lecture 06 James Atlas Computer and Information Sciences 06/24/2009.
General Computer Science for Engineers CISC 106 Lecture 14 James Atlas Computer and Information Sciences 08/10/2009.
Merge Sort Presentation By: Justin Corpron. In the Beginning… John von Neumann ( ) Stored program Developed merge sort for EDVAC in 1945.
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 20m.htm Office: TEL 3049.
CMPT 120 Topic: Searching – Part 2 and Intro to Time Complexity (Algorithm Analysis)
Chapter 16: Searching, Sorting, and the vector Type.
INTRO2CS Tirgul 8 1. Searching and Sorting  Tips for debugging  Binary search  Sorting algorithms:  Bogo sort  Bubble sort  Quick sort and maybe.
Exam practice. Exam 1  Describe how a Boolean expression can control the operation of a loop  Describe the difference between a while loop and for loop.
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.
Searching and Sorting Searching algorithms with simple arrays
Sorting Chapter 14.
Chapter 16: Searching, Sorting, and the vector Type
Sorting Mr. Jacobs.
COP 3503 FALL 2012 Shayan Javed Lecture 15
Lesson 5-15 AP Computer Science Principles
Sorting by Tammy Bailey
Algorithm design and Analysis
2008/12/03: Lecture 20 CMSC 104, Section 0101 John Y. Park
Mergesort Based on divide-and-conquer strategy
Searching and Sorting Topics Sequential Search on an Unordered File
Presentation transcript:

General Computer Science for Engineers CISC 106 Lecture 08 James Atlas Computer and Information Sciences 07/01/2009

Lecture Overview Review Linear Search Binary Search Sorting

Iterative strategy Given [5 4 2 10 6 7] find which position 6 occupies Alternatively, does the array contain the number 6?

Recursive strategy Split array in half Search each half of array

Binary Search Now, what if the array is sorted, can we search it faster?

Binary Search Find N in list Pick a number X halfway between the start and end of the list If X == N we are done else if X < N search top half of list else search bottom half of list

Let’s do this in Matlab Recursive solution

Binary Search Flowchart diagram of the algorithm Note the two stopping conditions (Exits) Note the one loop (Note: flowchart is equivalent to pseudocode) How much faster is this than linear search? If linear search takes roughly n steps for n things, Then binary search takes roughly log2(n) steps for n things. This is because we divide the n things by 2 each time.

Sorting If we draw a hand of cards how do we sort it from least to greatest?

Sorting Selection Sort Merge Sort

Selection Sort Find the minimum value in the list Swap it with the value in the first position Repeat the steps above for the remainder of the list Starting at the second position and advancing each time

Selection Sort: Iterative ssort.m

Group Sort Now group up with 3-4 neighbors and combine your cards How can we sort these?

Merge Sort If the list is of length 0 or 1, then it is already sorted. Otherwise: Divide the unsorted list into two sublists of about half the size. Sort each sublist recursively by re-applying merge sort. Merge the two sublists back into one sorted list.

Merge Sort Recursive mergesort.m

Project 1 On Sakai/course website Shark and goldfish simulator Teams of 3-5 Form team by July 6, 9:00pm Complete project due July 20 Functions that need to be implemented are listed

Shark (X) vs Goldfish (O) ---------- ---------O ---O------ -----O---- --O------- ----X----- --------O-

Each team has 3 members designated as librarian, recorder, and team leader. Grading: 1/3 individual work, 1/3 team accomplishments (with blind rating), 1/3 questions on midterm/exam about the project