420 likes | 578 Vues
Chapter 13 Analysis of Algorithms. Analysis of Algorithms. multiple algorithms for same problem time-space tradeoff same algorithm on various computers how to compare complexity analysis. Asymptotic Complexity. comparison independent of actual data and machine used problem size
E N D
Analysis of Algorithms • multiple algorithms for same problem • time-space tradeoff • same algorithm on various computers • how to compare • complexity analysis
Asymptotic Complexity • comparison independent of actual data and machine used • problem size • significant step • time complexity in terms of problem size • e.g. g(n) = n2/2 + 5n/2 - 3 • compare functions • approximation of g(n) • asymptotic complexity • dominant term
Methods • big-O notation • order O(…) • order of dominant term • definition • desire lowest order such function • big-Ω notation • definition • if g(n) is O(f(n)) then f(n) is Ω(g(n)) • big-Θ notation • definition • if g(n) is Θ(f(n)) then g(n) is O(f(n)) and g(n) is Ω(f(n)) • comparison • complexity classes • polynomial • non-polynomial
Determining Complexity • informal analysis • rough count of significant step • constant time (O(1)) • number of times independent of n • linear code • loops • if number of times is a factor of n • order is the order of the factor • nested code • nesting rule • sum of the orders • sequential code • sequence rule • maximum of the orders • examples
Timing Algorithms • determining actual run-time of program • to compare implementations or hardware • data? • representative set • System.currentTimeMillis • timing • example – methods of different order • results • accuracy of results
Software Development • Phases • Analysis • problem statement • requirements specification • system analysts • inputs and outputs • system model • Design • class specifications • architectural plan • system designers • Coding • coding according to specifications • programmers
Testing • unit level testing • integration testing • system testing • testers • Debugging • based on test results • Production • trainers • technical support • Maintenance • releases • versions • Documentation • user documentation • technical documentation • technical writers
Case Study: Grade Report System • Problem statement • Analysis • develop requirements specification • refine statement • determine inputs and outputs • files • Graphical User Interface (GUI) • report formats • develop model • select object/classes • determine relationships
Analysis • Refinement • marking scheme? • Inputs • course name • bases and weights for each piece of work • number of students • for each student: • student #, name and mark for each piece of work • class list • text file with class (student) information • mark data arrives over time • requires persistence • binary file • application to create a new course • application to enter/update mark data
Outputs • forms • course info • marking scheme info • student info • reports • final mark report • for each student • student number and final grade • summary statistics: course average • others?
Object/Classes • nouns in problem specification • candidate objects • eliminate values, duplicates and irrelevant entities • Model • relationships between classes • multiplicity
Design • Classes identified in analysis • Goal: detailed class descriptions • CRC card • class • responsibilities • collaborators • four cards, one per class • do responsibilities for knowing first • then responsibilities for doing • fill in collaborators
Responsibilities for Knowing • Nouns in problem statement • keep values • others from analysis/experience • Assign each to a class • consider real-world • don’t duplicate in another class • Example: • student number and marks in Student • bases and weights in MarkingScheme • average final mark in Course