CMPT 120 Lecture 33 – Unit 5 – Internet and Big Data

Slides:



Advertisements
Similar presentations
Order of complexity. Consider four algorithms 1.The naïve way of adding the numbers up to n 2.The smart way of adding the numbers up to n 3.A binary search.
Advertisements

Growth-rate Functions
College of Information Technology & Design
Introduction to Computer Science Theory
CSE Lecture 3 – Algorithms I
Computational Complexity 1. Time Complexity 2. Space Complexity.
Chapter 11 Sorting and Searching. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Examine the linear search and.
Sorting and Searching. Searching List of numbers (5, 9, 2, 6, 3, 4, 8) Find 3 and tell me where it was.
Wednesday, 11/25/02, Slide #1 CS 106 Intro to CS 1 Wednesday, 11/25/02  QUESTIONS??  Today:  More on sorting. Advanced sorting algorithms.  Complexity:
 2006 Pearson Education, Inc. All rights reserved Searching and Sorting.
Search Lesson CS1313 Spring Search Lesson Outline 1.Searching Lesson Outline 2.How to Find a Value in an Array? 3.Linear Search 4.Linear Search.
Abstract Data Types (ADTs) Data Structures The Java Collections API
CS 2430 Day 28. Announcements We will have class in ULR 111 on Monday Exam 2 next Friday (sample exam will be distributed next week)
(C) 2010 Pearson Education, Inc. All rights reserved. Java How to Program, 8/e.
1 Searching. 2 Searching Searching refers to the operation of finding an item from a list of items based on some key value. Two Searching Methods (1)
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Chapter 2 Array Data Structure Winter Array The Array is the most commonly used Data Storage Structure. It’s built into most Programming languages.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
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.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
Sorting.
CS 2430 Day 30. Announcements Quiz #5: 4/19 Agenda Big O Searching –Linear search.
Searching Topics Sequential Search Binary Search.
0 Introduction to asymptotic complexity Search algorithms You are responsible for: Weiss, chapter 5, as follows: 5.1 What is algorithmic analysis? 5.2.
 2006 Pearson Education, Inc. All rights reserved. 1 Searching and Sorting.
WHICH SEARCH OR SORT IS BETTER?. COMPARING ALGORITHMS Time efficiency refers to how long it takes an algorithm to run Space efficiency refers to the amount.
CMPT 120 Topic: Searching – Part 2 and Intro to Time Complexity (Algorithm Analysis)
John Levine, Computer and Information Sciences, Strathclyde University 1 Algorithms and Complexity 2: Complexity Notation.
Section 1.7 Comparing Algorithms: Big-O Analysis.
1 Algorithms Searching and Sorting Algorithm Efficiency.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
19 Searching and Sorting.
Growth of Functions & Algorithms
CMPT 120 Topic: Searching – Part 2
CMPT 120 Topic: Searching – Part 2
Algorithmic Efficency
COMP108 Algorithmic Foundations Algorithm efficiency
Last Class We Covered Sorting algorithms Searching algorithms
Big O notation Big O notation is used in Computer Science to describe the performance or complexity of an algorithm. Big O specifically describes the worst-case.
Lesson Objectives Aims Understand the following: The big O notation.
CMPT 120 Topic: Searching – Part 1
Search Lesson Outline Searching Lesson Outline
COMP 53 – Week Seven Big O Sorting.
Introduction to Algorithms
Sorting by Tammy Bailey
Teach A level Computing: Algorithms and Data Structures
Algorithm design and Analysis
CSC212 Data Structure - Section RS
Analysis of Bubble Sort and Loop Invariant
Binary Search and Intro to Sorting
MSIS 655 Advanced Business Applications Programming
Comparing Algorithms Unit 1.2.
Searching and Sorting 1-D Arrays
Analyzing an Algorithm Computing the Order of Magnitude Big O Notation
Algorithmic Complexity
Data Structures Sorted Arrays
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
CSC212 Data Structure - Section KL
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
Algorithmic complexity
CMPT 120 Lecture 30 – Unit 5 – Internet and Big Data
CMPT 120 Lecture 32 – Unit 5 – Internet and Big Data
Lecture 35 – Unit 6 – Under the Hood Binary Encoding – Part 1
Lecture 36 – Unit 6 – Under the Hood Binary Encoding – Part 2
Data Structures & Programming
CMPT 225 Lecture 16 – Heap Sort.
Presentation transcript:

CMPT 120 Lecture 33 – Unit 5 – Internet and Big Data Complexity Analysis of Searching and Sorting algorithms and Big O Notation

Review - A smart music app https://repl.it/repls/ShortEducatedSearchengine

Review – Linear Search Complexity How many comparison operations are performed in linear search? Test Case: # of Comparisons n (size of data) data = [1, 3, 4, 7, 9, 11, 12, 14, 21] target = 1 -> best case scenario target = 21 -> worst case scenario target = 34 -> worst case scenario 1 9 data = [1, 3, 4, 7, 9, 11, 12, 14, 21, 56, 67, 77, 82, 85, 91, 99, 100, 101] target = 101 -> worst case scenario target = 226 -> worst case scenario 18

Linear Search and Big O Notation So, as n increases linearly, so does the # of comparisons We say that the complexity of the linear search algorithm is Big O of n (or Order n) -> O(n)

Log2 n Pattern D Size of data in 1st iteration: n Binary Search Algorithm At each iteration: We compare the middle element with target and if target not found We partition the list in half, ignoring one half and searching the other Size of data in 1st iteration: n Size of data in 2nd iteration : n/2 D Size of data in 3rd iteration : n/4 Size of data in Tth iteration : 1

Review – Binary Search Complexity How many comparison operations are performed in binary search? Test Case: # of Comparisons n (size of data) data = [1, 3, 4, 7, 9, 11, 12, 14, 21] target = 9 -> best case scenario target = 1 9 Data

Linear Search and Big O Notation So, as n increases linearly, so does the # of comparisons, but not linearly, instead it increases in a logarithmic fashion We say that the complexity of the binary search algorithm is O(log2 n) But what does that mean?

What does Big O Notation tell us? What if I have 5 algorithms (or functions) that do the same thing, for example, extract red jelly beans from a bag of multicolour jelly beans Algorithm A -> O(1) Algorithm B -> O(n) Algorithm C -> O(log2 n) Algorithm D -> O(n log2 n) Algorithm E -> O(n!) Which one is the fastest?

What does Big O Notation tell us? # of comparisons Computing Scientists are interested in knowing how an algorithm performs as n gets large! https://en.wikipedia.org/wiki/Big_O_notation

Complexity of Selection Sort Selection Sort looks for the smallest element multiple times, by going through n elements, then n-1 elements, then n-2 elements, … The total number of comparisons is therefore = n + (n-1) + (n-2) + … + 3 + 2 + 1 = n (n + 1) 2 = n2 + n 2 2 Computing scientists mainly care about the highest order term. Therefore we consider selection sort to be quadratic -> O(n2)

Next Lecture We have already seen how computers deal with letters and characters … remember ASCII? We’ll have our Practice Exercise 8 So, bring your laptop!  Monday, we shall start our last unit Unit 6. Under The Hood We shall look at how the computer represents numbers Computers use 0 and 1 to represent everything Do you know why?