DOC PREVIEW
UMD CMSC 131 - Lecture 21: Algorithms and Design

This preview shows page 1-2-3-4-5-6 out of 19 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Lecture 21 Algorithms and Design Last time 1 Interfaces 2 Wrappers Today 1 Design CMSC 131 Fall 2007 Jan Plane Adapted from Bonnie Dorr Putting all your eggs in one basket Problem I have 16 baskets full of 12 eggs each I want to combine them or Algorithm 1 Combine 1 and 2 Combine result with 3 Combine result with 4 etc Algorithm 2 Combine 1 2 combine 3 4 combine 5 6 Combine 1 2 with 3 4 Combine 5 6 with 7 8 Combine 1 2 3 4 with 5 6 7 8 Combine last two CMSC 131 Fall 2007 Jan Plane Adapted from Bonnie Dorr 1 Algorithmic Efficiency Analysis Measuring which is better for time What if the time required for the merging machine is constant both have 15 calls to the merging machine when there are 16 baskets to merge what if the number of baskets is another value What if the time required for the merging machine is dependent on the number of eggs being merged for example 1 second per egg i e merging two baskets of 12 each takes 24 seconds this takes more math when you want to generalized on the number of baskets CMSC 131 Fall 2007 Jan Plane Adapted from Bonnie Dorr 2 Big O Notation Categories of formulas What takes over as n approaches infinity O log n O n O n log n O n2 O n2 log n CMSC 131 Fall 2007 Jan Plane Adapted from Bonnie Dorr 3 Coding vs Software Design Coding writing of Java code to implement classes methods etc Projects so far have been primarily coding We have told you what to code Design determination of what to code What classes are needed How should classes interact What methods belong in each class How should method functionality be implemented CMSC 131 Fall 2007 Jan Plane Adapted from Bonnie Dorr High level Low level 4 Low Level Design Pseudo Code and Algorithms We have already talked about pseudo code as a design technique NOT English NOT a program Something in between Captures the logic flow of desired code Note that pseudo code could be translated into any programming language not just Java Pseudo code is used to represent algorithms stepby step solutions to problems Algorithms are often coded as single methods CMSC 131 Fall 2007 Jan Plane Adapted from Bonnie Dorr 5 Example Linear Search Recall findMin from last time Given a non empty array find the smallest element Algorithm used is called linear search In pseudo code set variable min to initial element of array for each subsequent element in array compare element to min if element is less than min assign its value to min The polymorphic findMin method is the Java code implementing linear search CMSC 131 Fall 2007 Jan Plane Adapted from Bonnie Dorr 6 Concerns at the Algorithmic Level of Design Correctness Does my algorithm correctly solve the problem Efficiency Is my algorithm fast enough for the job Clarity Is my algorithm understandable and is it implementable CMSC 131 Fall 2007 Jan Plane Adapted from Bonnie Dorr 7 Interfaces and Design Next level up the design hierarchy what methods should go in classes This information can be captured using interfaces These interfaces can also be used to identify opportunities for polymorphism reusable code CMSC 131 Fall 2007 Jan Plane Adapted from Bonnie Dorr 8 Designing a Twenty Questions Game Interface What methods should be in interface between Twenty Questions and Oracle Politician Dog Methods should support a generic game driver in Twenty Questions class Methods should be common to both Oracle Politician Dog What notions are common to Oracle Politician Dog Say name Answer Y N questions Taunting CMSC 131 Fall 2007 Jan Plane Adapted from Bonnie Dorr 9 Rules of Thumb Keep interfaces small Think carefully about operations needed between classes Use interfaces to support polymorphism and keep code size down CMSC 131 Fall 2007 Jan Plane Adapted from Bonnie Dorr 10 Upper Levels of Software Design Where do ideas for classes interactions between classes come from Software development part of larger system design process System design requires identifying what system users expect system to do These user requirements often suggest system components and how they fit together First part of software design understand system design CMSC 131 Fall 2007 Jan Plane Adapted from Bonnie Dorr 11 What is an algorithm The method used to solve a particular problem is called an algorithm Example Make a peanut butter and jelly sandwich Get a loaf of bread Remove two slices Get a jar of peanut butter Get a knife Open the jar Using the knife get some peanut butter and spread it on one slice blah blah blah There is essentially one sequential process being described CMSC 131 Fall 2007 Jan Plane Adapted from Bonnie Dorr 12 System Design What Is It System design is concerned with coordinating a collection of entities to achieve a complex process Each entity has its own responsibilities to the others to achieve an overall objective E g Running a restaurant involves a coordinated interaction of many entities within one system Entities System Chef owners waiters etc Restaurant CMSC 131 Fall 2007 Jan Plane Adapted from Bonnie Dorr 13 Other Examples of Systems Classroom environment Lecturers TAs students Library Circulation checkout and return indexing services online catalogue library users book buyers shelvers Pharmacy Patients and medical records pharmacists doctors drug retailers the pharmacy products in stock Video game Race cars motorcycles warriors space ships death squads monsters aliens mutants guns swords weapons of mass destruction cute Japanese cartoon animals with huge eyes Pikachu visits Doom3 CMSC 131 Fall 2007 Jan Plane Adapted from Bonnie Dorr 14 Essential Questions Challenges System design is very hard Once the number of entities and interactions becomes large it is very hard to foresee all the possible consequences of these interactions Essential Questions What is the desired behavior of the program as a whole system design overview What are the entities that produce this behavior classes or objects How do these entities interact API for each class How does each one work algorithm for each task CMSC 131 Fall 2007 Jan Plane Adapted from Bonnie Dorr 15 Behavior Specifying Desired Behavior A use case is a description of the interaction of a user and the system It includes Prerequisites pre conditions What must hold for this use case to arise Possible actions and interactions What happens Effects post conditions What conditions hold what changes have taken place as a result of these actions Example Customer in a restaurant Pre conditions Customer hungry and has money Restaurant has food Actions


View Full Document

UMD CMSC 131 - Lecture 21: Algorithms and Design

Documents in this Course
Set #3

Set #3

7 pages

Exam #1

Exam #1

6 pages

Exam #1

Exam #1

6 pages

Notes

Notes

124 pages

Notes

Notes

124 pages

Load more
Download Lecture 21: Algorithms and Design
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 21: Algorithms and Design and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 21: Algorithms and Design and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?