Compsci 06/101, Spring 2011 8.1 Compsci 6/101: PFTW, Feb 28-March 4 l Algorithms and Data Structures  Sets and how they are used in Python (data structure)

Slides:



Advertisements
Similar presentations
"The State of the Python Union" Python10 - Alexandria, VA - February 7, 2002 Guido van Rossum Director, PythonLabs at Zope Corporation
Advertisements

Why I Invented Python EuroPython – June 27, 2005 Guido van Rossum Elemental Security, Inc.
§3 Compare the Algorithms 〖 Example 〗 Given (possibly negative) integers A 1, A 2, …, A N, find the maximum value of Max sum is 0 if all the integers.
Tirgul 8 Universal Hashing Remarks on Programming Exercise 1 Solution to question 2 in theoretical homework 2.
Algorithms. Problems, Algorithms, Programs Problem - a well defined task. –Sort a list of numbers. –Find a particular item in a list. –Find a winning.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Jonathan Huelman CSC 415 – Programming Languages
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Introduction to Python (for C++ programmers). Background Information History – created in December 1989 by Guido van Rossum Interpreted Dynamically-typed.
Abstract Data Types (ADTs) Data Structures The Java Collections API
Intro to Python Programming (Resources) Pamela A. Moore Zenia C. Bahorski Eastern Michigan University March 7, 2012 A language to swear by, not at. 1.
SIGCSE Tradeoffs, intuition analysis, understanding big-Oh aka O-notation Owen Astrachan
CS223 Algorithms D-Term 2013 Instructor: Mohamed Eltabakh WPI, CS Introduction Slide 1.
Chapter 13 Recursion. Topics Simple Recursion Recursion with a Return Value Recursion with Two Base Cases Binary Search Revisited Animation Using Recursion.
Modules and Decomposition UW CSE 190p Summer 2012 download examples from the calendar.
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
CSC 205 Java Programming II Algorithm Efficiency.
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.
CSS446 Spring 2014 Nan Wang.  Java Collection Framework ◦ Set ◦ Map 2.
Java Programming: Guided Learning with Early Objects Chapter 11 Recursion.
Compsci 6/101, Spring More on Python, Tools, Compsci 101 l APTs, Assignments, Tools  APT: Algorithmic Problem-solving and Testing  How to get.
Compsci 6/101, Spring PFTW: Sequences aka Strings&Lists l From Return values to Random-ness [aka two R's]  What power does random provide? 
Compsci 101.2, Fall Plan for FFWOO l Programming in the small and in the large  Making one function work correctly, especially in the context.
Chapter 2 Computational Complexity. Computational Complexity Compares growth of two functions Independent of constant multipliers and lower-order effects.
Efficiency of Algorithms. Node - data : Object - link : Node + createNode() + getData() + setData() + getLink() + setLink() + addNodeAfter() + removeNodeAfter()
CS404 Design and Analysis of Algorithms BBy DDr. M V S Peri Sastry BB.E, PhD(BITS-Pilani)
CompSci Analyzing Algorithms  Consider three solutions to SortByFreqs, also code used in Anagram assignment  Sort, then scan looking for changes.
8 January 2016Birkbeck College, U. London1 Introduction to Programming Lecturer: Steve Maybank Department of Computer Science and Information Systems
Compsci 101.2, Fall Plan for FWON l Review current assignments and APTs  Review Dictionaries and how to use them  Code and APT walk-through.
Compsci 101.2, Fall Plan for October 29 l Review dictionaries and their use  Very efficient, easy to use  Efficiency doesn't matter much for.
Python  Monty or Snake?. Monty?  Spam, spam, spam and eggs  Dead parrots  Eric Idle, John Cleese, Michael Palin, etc.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Array Lists Array Lists Dale.
Compsci 101.2, Fall Plan for eleven-four l Thinking about APTs and test problems  How do you choose: list, string, set, dictionary  Experience?
Searching Topics Sequential Search Binary Search.
Compsci 06/101, Fall Programming Equations l Algorithms + Data Structures = Programs  Niklaus Wirth, old view of programming and compsci l How.
Compsci 101.2, Fall Plan for WEFWOO l Review for exam, studying and practicing for exams and APTs in Compsci 101  Why memorization doesn't help.
Compsci 101.2, Fall Plan for October l Structuring Data and Code for Efficiency  Computer time, how expensive is it?  Data storage, how.
CSCI 125 & 161 Lecture 12 Martin van Bommel. Prime Numbers Prime number is one whose only divisors are the number 1 and itself Therefore, number is prime.
“Sense shines with a double luster when it is set in humility. An able and yet humble man is a jewel worth a kingdom.” – William Penn Thought for the Day.
Compsci 06/101, Spring This week in Compsci 6/101 l From sets to dictionaries  Incredibly powerful in solving problems  Power in Perl, Python,
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
CompSci 101 Introduction to Computer Science January 15, 2015 Prof. Rodger 1.
CMPT 120 Topic: Searching – Part 2 and Intro to Time Complexity (Algorithm Analysis)
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
Programming In Python. Starter Using the internet… Find what a programming language is.
Compsci 6/101, Spring Why is sorting data important? l Guess a number in [1,100] --- I'll tell you yes or no  How many guesses needed worst-case?
Quiz 4 Topics Aid sheet is supplied with quiz. Functions, loops, conditionals, lists – STILL. New topics: –Default and Keyword Arguments. –Sets. –Strings.
Introduction toData structures and Algorithms
Greatest Common Divisor
Greatest Common Divisor
Analysis of Algorithms
OBJECT ORIENTED PROGRAMMING II LECTURE 23 GEORGE KOUTSOGIANNAKIS
Algorithmic complexity: Speed of algorithms
What is a Literary Fingerprint?
Analysis of Algorithms
Compsci 201 Recursion, Recurrences, & Trees
Compsci 6/101: PFTW What is Python? What is a programming language?
Programming Tips GS540 January 10, 2011.
Courtsey & Copyright: DESIGN AND ANALYSIS OF ALGORITHMS Courtsey & Copyright:
CompSci 101 Introduction to Computer Science
CompSci 101 Introduction to Computer Science
Winter 2018 CISC101 12/1/2018 CISC101 Reminders
Algorithm Efficiency, Big O Notation, and Javadoc
Programming Tips GS540 January 10, 2011.
Analysis of Algorithms
Algorithmic complexity: Speed of algorithms
Algorithmic complexity: Speed of algorithms
Hash Maps Implementation and Applications
Analysis of Algorithms
Presentation transcript:

Compsci 06/101, Spring Compsci 6/101: PFTW, Feb 28-March 4 l Algorithms and Data Structures  Sets and how they are used in Python (data structure)  Algorithms, solving problems, understanding trade-offs l Transforms and modules  Transforming data and then untransforming it  How do you send a.jpg via … , text, copy/paste  How do you write programs in more than one.py file? l Writing code and understanding "costs"  Cost of calling a function? It depends!

Compsci 06/101, Spring Algorithm l What, where, when, who, why?   From Euclid to Google? l Instructions, rules, list  task, function, …  effective, finite, mechanizable? l Choose the best website for 'teaching python'  How does this work? l How to search a list of strings…

Compsci 06/101, Spring Programming Equations l Algorithms + Data Structures = Programs  Niklaus Wirth, old view of programming and compsci  Different view: functional, object-oriented, extreme/agile l How old are algorithms?  Euclid: find greatest common divisor, GCD (56, 217)  Who cares? You do! l A few basic idioms and algorithms go a long way  log one-million much less than one-million (binary search)  Don't do the same thing more than once

Compsci 06/101, Spring Tim Peters: Zen of Python l Beautiful is better than ugly. l Explicit is better than implicit. l Simple is better than complex. l Complex is better than complicated. l Flat is better than nested. l Readability counts. l Special cases aren't special enough to break the rules. l In the face of ambiguity, refuse the temptation to guess.

Compsci 06/101, Spring Designing Algorithms and Programs l Designing algorithms to be correct and efficient  The most important of these is _______________  When do we need to worry about efficiency?  Example: finding a number between 1 and 1000 High, Low, Correct: how many guesses? Same algorithm can find an element in a sorted list l Python searching in dictionary, set, list  How can we find an element?  How long does it take?  if x in collection :

Compsci 06/101, Spring Comparing Algorithms l Searching a list of N elements for a specific value  Worst case is …. l Doing binary search (guess a number), sorted list  Worst case is … l Finding the most frequently occurring element:  Strings? ints? does it matter? (toward Python dictionary) l Where do proteins occur in a genome?  Leveraging a previously solved APT

Compsci 06/101, Spring Revisiting cgratio APT l 'cost' of finding likely sources of protein in DNA def cgratio(strand): cg = 0 for nuc in strand: if nuc == 'c' or nuc == 'g': cg += 1 return cg def maxIndex(strand,windowSize): index,max = 0,0 for i in range(0,len(strand)-windowSize+1): cg = cgratio(strand[i:i+windowSize]) if cg > max: max,index = cg,i return index

Compsci 06/101, Spring Revisiting cgratio APT l 'cost' of finding likely sources of protein in DNA def runningMax(strand,windowSize): gc,counters = 0,[] for nuc in strand: counters.append(gc) if nuc == 'c' or nuc == 'g': gc += 1 counters.append(gc) index,max = 0,0 for i in range(windowSize,len(strand)+1): diff = counters[i] - counters[i-windowSize] if diff > max: max,index = diff,i return index-windowSize