data structures and algorithms for information processing

23
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 1: Introduction Data Structures and Algorithms for Information Processing Lecture 1: Introduction

Upload: basia-cash

Post on 31-Dec-2015

33 views

Category:

Documents


1 download

DESCRIPTION

Data Structures and Algorithms for Information Processing. Lecture 1: Introduction. Course Web Site. http://www.andrew.cmu.edu/~mm6. Structure of the Course. Lectures / class participation Homeworks (programming) Midterm examination Final examination. Readings. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

1Lecture 1: Introduction

Data Structures and Algorithms for Information

ProcessingLecture 1: Introduction

Page 2: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

2Lecture 1: Introduction

Course Web Site

• http://www.andrew.cmu.edu/~mm6

Page 3: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

3Lecture 1: Introduction

Structure of the Course

• Lectures / class participation• Homeworks (programming)• Midterm examination • Final examination

Page 4: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

4Lecture 1: Introduction

Readings

• Readings from the required text are assigned for each lecture -- read them in advance

• The book contains self-test exercises in each section

• Work these exercises (especially if you are new to the material)

Page 5: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

5Lecture 1: Introduction

Grading

• Homework (5-6) 50%• Midterm Exam 25%• Final Exam 25%

Page 6: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

6Lecture 1: Introduction

Definitions

• A data structure is an organized collection of data with specific aggregate properties

• An algorithm is a sequence of program instructions designed to compute a particular result

Page 7: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

7Lecture 1: Introduction

Five Steps per Datatype

• Understand it Abstractly• Write a Specification• Write Applications• Select an existing, or Design and

Implement our own• Analyze the Implementation in

terms of performance

Page 8: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

8Lecture 1: Introduction

Abstract vs. Concrete

• An abstract data type (ADT) specifies behavior, but not implementation

• An implementation uses a particular low-level datatype to implement the desired behavior

Page 9: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

Quick Example• A stack is an abstract data type (ADT).• We push and pop from the top.• Consider three implementations: (1) Every push causes all elements in an array to shift down 1 before the insertion at s[0]. (2) We add at stackTop and then add one to stackTop. (3) A linked list use where the top is always at the list’s front end.• Each implementation can be written correctly.• Implementation (1) runs in Θ(n).• Implementations (2) and (3) run in Θ(1).

9Lecture 1: Introduction

Page 10: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

10Lecture 1: Introduction

Step 1: Understanding

• Grasp the datatype at the level of concepts and picturese.g., visualize a stack and the operations of pushing / popping

• Understand simple applications• Simulate by hand

e.g., use a stack to reverse the order of letters in a word

Page 11: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

11Lecture 1: Introduction

Step 2: Specification

• Write a specification for a Java class that could implement the datatype (see javadoc Appendix H)

• Headings for constructor, public methods, public features

• Includes precondition / postcondition for each method

• Independent of implementation!

Page 12: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

12Lecture 1: Introduction

Step 3: Application

• Based on the specification, write small applications to illustrate the use of the datatype

• “Test the specification” prior to implementation

• Code not yet compiled / run

Page 13: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

13Lecture 1: Introduction

Step 4: Implementation

• Select appropriate data structure• Implement as private class vars• Write rules relating instance

variables to abstract specification:the invariant of the ADT

• Each method knows the invariant is true when it starts

• Each method upholds the invariant

Page 14: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

14Lecture 1: Introduction

Step 5: Analysis

• Correctness• Flexibility• When possible, compare different

implementations of the same ADT• Time Analysis

– number of operations– big-O notation, e.g.,

Page 15: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

15Lecture 1: Introduction

Phases of Software Development

• Specification of the Task• Design of a Solution• Implementation of the Solution• Running Time Analysis• Testing and Debugging• Maintenance and Evolution• Obsolescence

Page 16: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

16Lecture 1: Introduction

Java

• Conceived in 1991 at Sun• Has Similarities to C++• Is simpler than C++• Object-Oriented Programming (OOP)

– information hiding– component re-use– programs (methods) and data are

grouped together into classes– we will not be using the collection

classes

Page 17: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

17Lecture 1: Introduction

What You Should Know Already

• How to use a Java development environment (java, javac, javadoc)

• How to write, compile, and run short Java programs

• Java primitive types (number types, char, boolean) and arrays

• Easy to pick up with prior programming experience

Page 18: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

18Lecture 1: Introduction

Specifying a Java Method

• Specification: what a method does not how it does it

• A form of information hiding called procedural abstraction

• Method signaturepublic static double celsiusToFahrenheit(double c)

• Method calldouble fahrenheit = celsiusToFahrenheit(celsius);

Page 19: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

19Lecture 1: Introduction

Elements of Specification

• Short Introduction• Parameter Description• Returns

– Specify the meaning of return value

• Throws list– error conditions (exceptions) “thrown”

by this method

• Precondition and Postcondition

Page 20: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

20Lecture 1: Introduction

Preconditions

• A precondition is a statement giving the condition that should be true when the method is called

• The method is not guaranteed to perform as it should unless the precondition is true.

• If violated, ignore (like c) or throw an exception (like Java).

Page 21: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

21Lecture 1: Introduction

Postconditions

• A postcondition is a statement describing what will be true when a method call completes

• If the method is correct and precondition was met, then the method will complete, and the postcondition will be true when it does

• Use Java assert statement for post-condition checks during debugging. Not

during deployment.

Page 22: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

22Lecture 1: Introduction

Example Specification

• celsiusToFahrenheit public static double celsiusToFahrenheit(double c)

– convert a temperature from Celsius degrees to Fahrenheit degrees

– Parameters:c - a temperature in Celsius degrees

– Precondition: c>= -273.16– Returns: temperature c in Fahrenheit– Throws: IllegalArgument Exception

Page 23: Data Structures and Algorithms for Information Processing

90-723: Data Structuresand Algorithms for

Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved.

23Lecture 1: Introduction

More on Pre/Postconditions

• Slides from Main’s Lectures