Seattle Preparatory School Advanced Placement Computer Science Seattle Preparatory School Advanced Placement Computer Science LESSON 62 FEBRUARY 12, 2015.

Slides:



Advertisements
Similar presentations
Garfield AP Computer Science
Advertisements

The Efficiency of Algorithms
HST 952 Computing for Biomedical Scientists Lecture 9.
© 2006 Pearson Addison-Wesley. All rights reserved10-1 Chapter 10 Algorithm Efficiency and Sorting CS102 Sections 51 and 52 Marc Smith and Jim Ten Eyck.
June Searching CE : Fundamental Programming Techniques 16 Searching1.
CHAPTER 11 Sorting.
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.
Data Structures Review Session 1
Analysis of Algorithm.
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
 2006 Pearson Education, Inc. All rights reserved Searching and Sorting.
Simple Sorting Algorithms. 2 Bubble sort Compare each element (except the last one) with its neighbor to the right If they are out of order, swap them.
SIGCSE Tradeoffs, intuition analysis, understanding big-Oh aka O-notation Owen Astrachan
Liang, Introduction to Java Programming, Seventh Edition, (c) 2009 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Week 11 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
1 Chapter 24 Developing Efficient Algorithms. 2 Executing Time Suppose two algorithms perform the same task such as search (linear search vs. binary search)
ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 2620a.htm Office: TEL 3049.
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.
Copyright © 2013 by John Wiley & Sons. All rights reserved. SORTING AND SEARCHING CHAPTER Slides by Rick Giles 14.
Chapter 12 Recursion, Complexity, and Searching and Sorting
Chapter 19: Searching and Sorting Algorithms
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
 Pearson Education, Inc. All rights reserved Searching and Sorting.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
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.
Big Oh Algorithms are compared to each other by expressing their efficiency in big-oh notation Big O notation is used in Computer Science to describe the.
Sorting and Searching Pepper. Common Collection and Array Actions Sort in a certain order ◦ Max ◦ Min Shuffle Search ◦ Sequential (contains) ◦ Binary.
Data Structure Introduction.
CS261 Data Structures Ordered Bag Dynamic Array Implementation.
Sort Algorithms.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
3 – SIMPLE SORTING ALGORITHMS
Sorting and Searching. Selection Sort  “Search-and-Swap” algorithm 1) Find the smallest element in the array and exchange it with a[0], the first element.
Lecture #9: Sorting Algorithms خوارزميات الترتيب Dr. Hmood Al-Dossari King Saud University Department of Computer Science 22 April 2012.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Selection Sort Sorts an array by repeatedly finding the smallest.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 23 Algorithm Efficiency.
Data Structures - CSCI 102 Selection Sort Keep the list separated into sorted and unsorted sections Start by finding the minimum & put it at the front.
M180: Data Structures & Algorithms in Java Sorting Algorithms Arab Open University 1.
Course Code #IDCGRF001-A 5.1: Searching and sorting concepts Programming Techniques.
Searching Topics Sequential Search Binary Search.
Algorithm Analysis Lakshmish Ramaswamy. Formal Definitions Big-Oh: T(N) is O(F(N)) if there exists positive constants N 0 and c such that T(N) N 0 Big-Omega:
Computer Science 1620 Sorting. cases exist where we would like our data to be in ascending (descending order) binary searching printing purposes selection.
Search Algorithms Written by J.J. Shepherd. Sequential Search Examines each element one at a time until the item searched for is found or not found Simplest.
Chapter 9: Sorting1 Sorting & Searching Ch. # 9. Chapter 9: Sorting2 Chapter Outline  What is sorting and complexity of sorting  Different types of.
Sorting Algorithms Written by J.J. Shepherd. Sorting Review For each one of these sorting problems we are assuming ascending order so smallest to largest.
 2006 Pearson Education, Inc. All rights reserved. 1 Searching and Sorting.
Lecture 14 Searching and Sorting Richard Gesick.
Warmup What is an abstract class?
Simple Sorting Algorithms
Teach A level Computing: Algorithms and Data Structures
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Big-Oh and Execution Time: A Review
Sorting Algorithms Written by J.J. Shepherd.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Algorithm design and Analysis
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Quicksort analysis Bubble sort
Lecture 11 Searching and Sorting Richard Gesick.
MSIS 655 Advanced Business Applications Programming
24 Searching and Sorting.
14 SORTING AND SEARCHING CHAPTER
Algorithmic Complexity
Searching and Sorting Arrays
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Sum this up for me Let’s write a method to calculate the sum from 1 to some n public static int sum1(int n) { int sum = 0; for (int i = 1; i
Algorithm Efficiency and Sorting
Applications of Arrays
Presentation transcript:

Seattle Preparatory School Advanced Placement Computer Science Seattle Preparatory School Advanced Placement Computer Science LESSON 62 FEBRUARY 12, 2015 Quiz Review and MBCS Ch 4 Consider this method: public int mystery(int a, int b) { return a * mystery(a, b-1); } 1.What does the method do? 2.The method has a bug in it – what is it? 3.How could you fix it?

Seattle Preparatory School Advanced Placement Computer Science Quiz Review

Seattle Preparatory School Advanced Placement Computer Science Seattle Preparatory School Advanced Placement Computer Science 1. Describe sequential search It will examine each element in array A in order until X is found. If it reaches the end of the array without finding X, it will return -1.

Seattle Preparatory School Advanced Placement Computer Science Seattle Preparatory School Advanced Placement Computer Science 2. What is the complexity of sequential search? O(N) This is because if X is the last element in array A, then sequential search will have to examine N elements in an array A of size N.

Seattle Preparatory School Advanced Placement Computer Science Seattle Preparatory School Advanced Placement Computer Science 3. Describe binary search It will divide the sorted array A in half, and check if X is greater than or less than the midpoint to determine if it should take the right or left side. Once a side is selected, it will repeat the process with that side, until an array of length 1 is found. That position will contain X and be returned, or if it does not contain X, the search will return -1.

Seattle Preparatory School Advanced Placement Computer Science Seattle Preparatory School Advanced Placement Computer Science 4. What is the complexity of binary search? O(logN) This is because the array of length N is split in half repeatedly until there us an array of length 1. Remember that big O logs are base 2.

Seattle Preparatory School Advanced Placement Computer Science Seattle Preparatory School Advanced Placement Computer Science 5. Name three sorting algorithms You could have named three of any of the following: Bubble Insertion Radix Selection Merge Quick

Seattle Preparatory School Advanced Placement Computer Science Seattle Preparatory School Advanced Placement Computer Science 6. What is the complexity of selection sort? O(N 2 ) This is because selection sort scans the unsorted part of the array of length N once to find the next element for each element in the array.

Seattle Preparatory School Advanced Placement Computer Science Seattle Preparatory School Advanced Placement Computer Science 7. Suppose we have a program that takes N/10 milliseconds to process an array of size N. What is the complexity of the program? O(N) When using big O notation, we remove constant factors (1/10) and reduce summations to the term with the largest growth rate (N as 100 never changes).

Seattle Preparatory School Advanced Placement Computer Science Seattle Preparatory School Advanced Placement Computer Science 8. How long can one expect the algorithm to take on an array of size 2000? 4 seconds Because a quadratic equation is exponential, if you double the base by two, it will case the time to increase by that to the power of 2.

Seattle Preparatory School Advanced Placement Computer Science Seattle Preparatory School Advanced Placement Computer Science 9. What is the complexity of finding the largest element? Why? O(n) because you have no way of knowing where the largest element is in the array, so worse case scenario you have to check each element in the array once.

Seattle Preparatory School Advanced Placement Computer Science Seattle Preparatory School Advanced Placement Computer Science 10. What is the complexity of finding the largest element? Why? O(1) because if the array is sorted, then you already know that the smallest is at one end and the largest is at the other.

Seattle Preparatory School Advanced Placement Computer Science Seattle Preparatory School Advanced Placement Computer Science Extra Credit public static in findNumberOfDuplicates(int[] a, int x) { int count = 0; for(int position = 0; position < a.length; position++) { int currentValue = a[position]; if(currentValue == x) { count++; } return count; }

Seattle Preparatory School Advanced Placement Computer Science Seattle Preparatory School Advanced Placement Computer Science MBCS Chapter 4 – Different types of Fish Due Thursday Quiz a week from Tuesday Four more DAT files on Haiku When it asks you to save a file, please make sure you turn that in with your answers. When it asks you to write code, please make sure to turn in that code as well as any analysis you do with the code.