ECE 242 Spring 2003 Data Structures in Java - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

ECE 242 Spring 2003 Data Structures in Java

Description:

If there are lots of memory, then make the program as fast as possible. If it's critical application, make it as robust as possible. ECE242 Spring 2003 ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 23
Provided by: teng8
Category:
Tags: ece | data | java | spring | structures

less

Transcript and Presenter's Notes

Title: ECE 242 Spring 2003 Data Structures in Java


1
ECE 242 Spring 2003Data Structures in Java
  • http//rio.ecs.umass.edu/ece242
  • Algorithm Analysis 1
  • Prof. Lixin Gao

2
Todays Topics
  • Introduction to analysis of algorithms.
  • Big O notation

3
Select Algorithms
  • A lot of sorting algorithms
  • Selection sort
  • Insertion sort
  • etc.
  • Which one to choose?

4
Criteria Used So Far
  • Little code
  • Little time to write codes
  • Little time to debug
  • If its due tomorrow, make it work!!!

5
More Criteria
  • Fast execution
  • More functionality
  • Minimize memory space used
  • If there are lots of memory, then make the
    program as fast as possible
  • If its critical application, make it as robust
    as possible

6
Important Criteria
  • Execution time is the most important
  • Memory space is also important
  • Might not be first priority as memory is getting
    cheaper
  • Need trade execution time with space for some
    problems

7
Analytical Approach vs. Empirical Approach
  • Two existing strategies
  • Strategy A
  • Strategy B
  • Empirical approach
  • implement both, pick the better one
  • Analytical approach
  • analyze both, implement the better one

8
Example
  • Analysis
  • 2 days
  • Implementation
  • 2 months

9
Analytical Approach
  • Analyze Strategy A 2 days
  • Analyze Strategy B 2 days
  • Compare two analytical results 0 days
  • Choose faster strategy 0 days
  • Implement faster one 2 months
  • Total 2 months4 days

10
Empirical Approach
  • Implement Strategy A 2 months
  • Implement Strategy B 2 months
  • Compare two implementations 2 days
  • Choose faster strategy 0 days
  • Total 4 months2 days

11
Analytical or Empirical Approach?
  • Empirical approach can be faster in some cases.
  • Both approaches are important
  • Learning both skills can make you a better and
    faster programmer
  • Focus on empirical approach
  • Lots of coding so far
  • Let us do some analysis!

12
Execution Time?
  • Real time?
  • Machine has different speed
  • Number of Operations?
  • Comparison
  • Assignment
  • Instruction

13
Example
  • Search
  • Search position for 30

14
Sequential Search
  • How many key operations? 8
  • N inputs
  • Worst case N key comparisons
  • Average case N/2 key comparisons
  • Typically, we use worst case.

15
Enhanced Sequential Search
16
N vs. N/2
  • Cost(N) N (sequential)
  • Cost(N) N/2 1 (enhanced sequential)

Cost(N)
N
N/2 1
N
17
Binary Search
18
Analysis of Binary Search
  • N 2x
  • log2N x

19
N vs. log2N
Cost(N)
N
log2N
N
20
Big-O Notation
  • O stands for the order of
  • Also called asymptotic analysis
  • O(N) linear to N
  • E.g. N and N/2
  • O(logN) order of log N
  • E.g. log2N and log3N
  • O(N) gt O(logN)

21
Big-O notation
  • O(1) constant
  • E.g. initialize i
  • O(N) gt O(logN) gt O(1)
  • Ignore less dominating term.
  • Ignore constant
  • E.g. N/21 is O(N)

22
Search Algorithms
  • Linear search O(N)
  • Enhanced Linear search O(N)
  • Binary search O(logN)
Write a Comment
User Comments (0)
About PowerShow.com