Eamonn Keogh eamonn@cs.ucr.edu CS005 Introduction to Programming: Matlab Eamonn Keogh eamonn@cs.ucr.edu.

Slides:



Advertisements
Similar presentations
CS1020 Week 13: 16 th April Contents  Sit-in Lab #4 2.
Advertisements

Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 5.
CIS 101: Computer Programming and Problem Solving Lecture 7 Usman Roshan Department of Computer Science NJIT.
Spring R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Where we areWhere we are Strings and TextStrings and Text ConditionalsConditionals.
General Computer Science for Engineers CISC 106 Final Exam Review Dr. John Cavazos Computer and Information Sciences 05/18/2009.
CS146 Overview. Problem Solving by Computing Human Level  Virtual Machine   Actual Computer Virtual Machine Level L0.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Welcome to CS 115! Introduction to Programming. Class URL
Complexity of algorithms Algorithms can be classified by the amount of time they need to complete compared to their input size. There is a wide variety:
Welcome to CS 115! Introduction to Programming. Class URL Write this down!
CompSci 6 Introduction to Computer Science Sept. 20, 2011 Prof. Rodger CompSci 6 Fall
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Midterm 2 Review Notes on the CS 5 midterm Take-home exam due by 5:00 pm Sunday evening (11/14) Hand in your solutions under the door of my office, Olin.
CS 100Lecture 201 Announcements P5 due Thursday Final exam: Tuesday August 10th, 8AM, Olin 155, 2 hours Tomorrow, Wednesday: C, pointers Thursday, Friday:
Searching Arrays Linear search Binary search small arrays
Eamonn Keogh CS005 Introduction to Programming: Matlab Eamonn Keogh
Eamonn Keogh CS005 Introduction to Programming: Matlab Eamonn Keogh
Eamonn Keogh CS005 Introduction to Programming: Matlab Eamonn Keogh
Introduction to EGR115 Welcome! Your instructors Class format
Eamonn Keogh CS005 Introduction to Programming: Matlab Eamonn Keogh
CS005 Introduction to Programming
CS005 Introduction to Programming
CMSC201 Computer Science I for Majors Lecture 22 – Searching
Unit-1 Introduction to Java
Eamonn Keogh CS005 Introduction to Programming: Matlab Eamonn Keogh
CS005 Introduction to Programming:
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Introduction to Programming Spring 2016
CompSci 101 Introduction to Computer Science
CMSC201 Computer Science I for Majors Lecture 27 – Final Exam Review
CS005 Introduction to Programming
Introduction to MATLAB
Eamonn Keogh CS005 Introduction to Programming: Matlab Eamonn Keogh
CS005 Introduction to Programming
Lecture 3 MATLAB programming (1)
CS 2308 Exam I Review.
Labs, etc. 19-Nov-18.
CS 2308 Exam I Review.
Eamonn Keogh CS005 Introduction to Programming: Matlab Eamonn Keogh
Lesson 6 Wrap-Up.
CS005 Introduction to Programming
CprE 185: Intro to Problem Solving (using C)
CS005 Introduction to Programming: Matlab Eamonn Keogh
Eamonn Keogh CS005 Introduction to Programming: Matlab Eamonn Keogh
Introduction to Programming Using C++
Eamonn Keogh CS005 Introduction to Programming: Matlab Eamonn Keogh
CS1110 Lec Oct 2010 More on Recursion
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Title of Session Presentation Here
CS 111 Digital Image Processing
CS005 Introduction to Programming: Matlab
CEV208 Computer Programming
Logical Operations In Matlab.
Eamonn Keogh CS005 Introduction to Programming: Matlab Eamonn Keogh
Twenty Questions Subject: Time.
CMSC201 Computer Science I for Majors Lecture 25 – Final Exam Review
CS 1430: Programming in C++.
Locations for CS 115 Activities
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
CS 336/536: Computer Network Security Fall 2014 Nitesh Saxena
Chengyu Sun California State University, Los Angeles
Principles of Imperative Computation
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
Javascript data structures
Test Notes: 1. You must take the test with class you are registered for. 2. Test is 65-70% multiple choice. 3. Test covers Chapters 19, 20, 21, 22.
Caches and Blocking 26th February 2018.
Self Service Time and Attendance (SSTA) Contract Employees
Presentation transcript:

Eamonn Keogh eamonn@cs.ucr.edu CS005 Introduction to Programming: Matlab Eamonn Keogh eamonn@cs.ucr.edu

e a m o n 'abcdefg' 'eamonn' NaN 5 A Write a function that searches a string for repeated, consecutive characters. If there are non, return NaN, otherwise, return the index of the first letter of the first occurrence. A e a m o n 'abcdefg' 'eamonn' FindRepeatedChars FindRepeatedChars NaN 5

e a m o n function Repeated = FindRepeatedChars(A) for i = 1 : length(A) - 1 disp([A(i), A(i+1)]) end EDU>> FindRepeatedChars('eamonn') ea am mo on nn A e a m o n

e a m o n function Repeated = FindRepeatedChars(A) Repeated = NaN; for i = 1 : length(A) - 1 if A(i) == A(i+1) Repeated = i; break; end EDU>> FindRepeatedChars('eamonn') ans = 5 EDU>> FindRepeatedChars('abababab') NaN A e a m o n

'uncopyrightable' 'aqua' 2 NaN Write a function that searches a string for duplicate characters, which may be non consecutive If there are non, return NaN, otherwise, return the index of the first letter of the first occurrence. 'uncopyrightable' 'aqua' HasDuplicate HasDuplicate 2 NaN

Clever solution: Sort the strings, then use the FindRepeatedChars function we just wrote! EDU>> sort('uncopyrightable') ans = abceghilnoprtuy EDU>> sort('aqua') aaqu

a q u A function DuplicateLoc = HasDuplicate(A) for i = 1 : length(A) disp(A(i)); end >> HasDuplicate('aqua') a q u A a q u

a q u a q u a q u a q u function DuplicateLoc = HasDuplicate(A) for i = 1 : length(A) disp(A(i)); end >> HasDuplicate('aqua') a q u a q u i loop i is 1 a q u i loop i is 2 a q u i loop i is 3 a q u i loop i is 4

a q u a q u a q u a q u a q u a q u a q u a q u a q u i loop i is 1

a a q u a q u a a q u a a a q u q a q u q a q u q a q u q a q u u a q i loop i is 1 k loop k is 1 a a q u i loop i is 2 a q u k loop k is 1 a i loop i is 3 a q u k loop k is 1 a i loop i loop i is 4 a a q u k loop k is 1 i loop i is 1 q a q u k loop k is 2 i loop i is 2 q a q u k loop k is 2 i loop i is 3 q a q u k loop k is 2 i loop i loop i is 4 q a q u k loop k is 2 i loop i is 1 u a q u k loop k is 3

function DuplicateLoc = HasDuplicate(A) for k = 1 : length(A) for i = 1 : length(A) disp( [A(i) A(k) ]); end EDU>> HasDuplicate('aqua') aa qa ua aq qq uq au qu uu

function DuplicateLoc = HasDuplicate(A) for k = 1 : length(A) for i = 1 : length(A) if i ~=k disp([A(i) A(k) ]); else disp(['comparing with self ',A(i) A(k) ]); end EDU>> HasDuplicate('aqua') comparing with self aa qa ua aa aq comparing with self qq uq au qu comparing with self uu

function DuplicateLoc = HasDuplicate(A) DuplicateLoc = NaN; for k = 1 : length(A) for i = 1 : length(A) if i ~=k if A(i) ==A(k) DuplicateLoc = i; break; end EDU>> HasDuplicate('uncopyrightable') ans = NaN EDU>> HasDuplicate('aqua') 1

End Game Review session on Wed, Lead by TA Exam on Friday, During class time Bring scantron, like last time Lab on Friday afternoon Dr. Keogh will not be here from Wed morning till late Thursday. If you want office hours, get them before then, or ask the TA.