Top Banner
91.102 - Intro. To Computing II • Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli [email protected] Web Page: http://www.cs.uml.edu/~giam/CS2 Project Grading and Problem Sessions by [email protected].
26

91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli [email protected].

Dec 29, 2015

Download

Documents

Avis Hopkins
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

91.102 - Intro. To Computing II

• Data Structures, Algorithms and Software Principles in C. Text by T. Standish.

• Lectures and Exams by G. Pecelli • [email protected]• Web Page: http://www.cs.uml.edu/~giam/CS2• Project Grading and Problem Sessions by

[email protected].

Page 2: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

91.102 - Computing II

WARNING: Although you will be expected to deliver a fair amount of code, thinking of this as a "coding course" will miss the point: this is a course of IDEAS, where the code is necessary to realize the ideas in ways that allow computation to be performed.

The method of presentation will include verbal descriptions, pictures, mathematical formulae and code.

Page 3: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

• What is Computer Science?• It does NOT refer to just the artifact known as a

COMPUTER - a better name might be Computing Science.

• It refers to whatever can be represented in terms of COMPUTATION and the mathematics, physics and engineering required to understand it and realize it.

• Theory sometimes leads the creation of new computational objects and sometimes follows it: there is, at the moment, no primacy of theory over artifact or vice-versa.

• A Computer Scientist must be ready to model a portion of existing reality, to invent a new reality, or to analyze the characteristics of a (proposed or pre-existing) reality.

91.102 - Computing II

Page 4: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

This course will attempt to introduce you to some of the fundamental concepts of Computer Science:

• Data Abstraction, Information Hiding, Modularity, Interfacing, Algorithms and the Role of Mathematics in these topics.

• Abstract Data Types: Lists, Strings, Stacks, Queues, Trees, Graphs, Tables - and their realizations in C.

• Sorting and Searching Algorithms - and their implementation in C.

• Recursion and Iteration.

• Software Engineering Principles, at least in so far as they relate to Reliability, Affordability, Efficiency and Correctness.

91.102 - Computing II

Page 5: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

What are we trying to do first?

Determine the Level of Abstraction appropriate to this course.

Multiple Backgrounds of Students: Level of Abstraction may NOT satisfy everybody… This must be directed to the student of Computer Science with just ONE completed course. Must also be directed towards “principles” rather than implementation in a particular language: languages come and go and will continue to come and go...

Multiple Possibilities: C++ or Java would lead to slightly different ways of approaching and using abstraction.

91.102 - Computing II

Page 6: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

Regardless of the language, or the level of abstraction chosen, we have to try to answer these questions:

• What are the appropriate level building blocks we must learn to use and manipulate?

• How can we THINK about these building blocks? What is the level of detail we need to understand them?

•How can we REASON with these building blocks? How can we use them correctly and efficiently in more complex structures?

•How can we IMPLEMENT these building blocks? What tools does the implementation language provide?

91.102 - Computing II

Page 7: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

91.102 - Computing II

BUILDING BLOCKS:

• Bits, Bytes and Words. This is what people had to work with at the beginning (1940s and early 1950s).

• The level of detail is TOO LOW:

A) too tied to the hardware;

B) hardware changes relatively quickly;

C) hardware is dependent on a specific manufacturer;

D) hardware requires we think in chunks that are TOO SMALL for most of the problems we need to solve: like writing a novel and worrying about every molecule of ink as you write.

Page 8: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

91.102 - Computing II

First Users: Scientists (Physicists, really) and Engineers.

Building blocks: mathematical formulae to describe behavior of systems. Arrays and Matrices.

Systems Modeled: Airplane Wings, Radar Antennae, Explosions (how to trigger a Hydrogen bomb), Missile and Bullet Trajectories.

Language Invented: FOR(mula)TRAN(slation) provided the programmer with the right level of abstraction. That it was - more by luck than by design - “the right level” follows from the fact that FORTRAN is still alive and well.

Page 9: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

Computer Scientist: what are the objects of interest?

One could argue that anything that has something to do with computers or computation (this is a hard one to really characterize) falls within the interest of a Computer Scientist.

This is NOT a useful characterization - although it may seem quite valid given the range of jobs available to Computer Science graduates: from designing microcode and microcode interpreters to designing Web pages, and anything in between.

91.102 - Computing II

Page 10: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

Computer Scientist: What are the objects of interest?

Algorithms : what kind of actions do you take? How do you describe these actions in terms the computer can execute?

Data Structures : what kind of objects do you act on? How do you describe them in terms the hardware can represent?

Efficiency : how much space and time do your choices require to complete the task? CAN you complete the task within the limitations imposed?

Correctness : is there a way in which you can determine whether your construct will behave “properly”? People’s lives might depend on it. You might eventually be legally liable for your mistakes...

91.102 - Computing II

Page 11: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

Algorithms :

How to search for something.

How to sort a set of items.

How to compute a value given one or more input values.

How to perform a task.

Must be expressed in terms that (eventually) can be translated into the manipulation of Bits, Bytes and Words via a (relatively) small set of primitive hardware instructions.

91.102 - Computing II

Page 12: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

91.102 - Computing II

What do we apply these Algorithms to?

The algorithms (recipes) of a cookbook are applied to stuff you find around a kitchen: ingredients (e.g., flour), tools (e.g., an oven).

The “standard” items in a kitchen are the result of several millennia (maybe as many as 2000 millennia) of practice and technological evolution.

What are the “standard” items in the Computer Scientist’s cubicle? They are called Data Structures.

Page 13: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

91.102 - Computing II

Data Structures :

Can we represent data in ways that are more “natural” than Bits, Bytes and Words?

Although a Chemist can have a lot fun in the kitchen (and a number of chefs are trained chemists), thinking always at the level of chemical reactions isn’t going to get dinner on the table in any reasonable amount of time.

Nor is it going to make it easy for even another chemist to figure out what kind of dinner was being cooked...

Page 14: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

Data Structures:

We should be able to represent “real objects” at a level that is easy to “think about” and easy to “translate into Bits, Bytes and Words”.

Experience has shown that certain types of objects occur with consistent regularity over many applications: Booleans, Integers, Rationals (limited to “floating point numbers” in the less sophisticated environments), arrays, records, lists, characters, strings, files, trees, graphs, sets, dictionaries, etc…

Some are straightforward, others not.

91.102 - Computing II

Page 15: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

91.102 - Computing II

Data Structures :

They represent an “intermediate layer” between the User Problem, which has to deal with, for example, wing loadings, lift, drag, weight, cargo volume, power, etc., and the machine representation in terms of our Bits, Bytes and Words.

They are the layer of interest to the Computer Scientist because they admit of manipulation in terms of finite sequences of simple operations, without being TOO SIMPLE.

Page 16: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

How simple? They can be RELIABLY translated into sequences of operations on Bits, Bytes and Words, so reliably that we can accurately estimate the cost of the machine operations from the operations on these “intermediate layer” objects.

How high-level? They can be RELIABLY associated with user concepts in such a way that a “normal user” can make sense of them without a deep understanding of lower level ideas (bits, bytes, words, etc…)

91.102 - Computing II

Page 17: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

91.102 - Computing II

Data Structures :

There is nothing miraculous about the data structures we will study.

They just happen to be the ones that have appeared with consistency and regularity over more than 50 years of computing, and they continue to provide fruitful ways to think about the world around us in terms of its representation and the manipulation of the models we construct.

Page 18: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

91.102 - Computing II

Efficiency :

How fast will it run?

Is this the best one can do?

How much space will it use?

Is this the best one can do?

How long will it take for me to deliver the solution?

Can one deliver a solution within the constraints (time, cost, hardware, etc.) imposed?

Page 19: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

91.102 - Computing II

Correctness :

Can you really stand behind your program, or is it “unfit for any use”?

Can you prove that your program is correct:

a) at the level of individual fragments and

algorithms?

b) at the system level?

What techniques can one use?

Are they practical?

Are they effective?

Page 20: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

91.102 - Computing II

Software Engineering :

The engineering disciplines have a history of delivering complex systems (bridges, airplanes, cars, buildings) that function (mostly) acceptably.

They have all developed a number of ideas:

Break the project up into small pieces.

Make sure the interfaces among them match.

Develop procedures and FOLLOW them.

Use off-the shelf components.

Don’t push the envelope unless you need to.

Be redundant if you can.

Page 21: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

91.102 - Computing II

Software Engineering :

In the Small: (< 100,000 lines)

Top-Down Design and Structured Programming;

In the Large: (> 1,000,000 lines)

Reusable Components;

Modular Decomposition;

Rapid Prototyping;

Life Cycle Processes;

Testing Methodologies;

etc...

Page 22: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

91.102 - Computing II

Mathematics : Why a Computer Scientist Needs It.

Estimation of time and space required for execution.

Estimation of time required for design and delivery.

Proofs of correctness (or attempts at such).

Logical Analysis of a problem. This is, sometimes quite complex.

Representation of object behavior: a checking account manager needs little Mathematics; a program to design airplane wings and simulate their behavior in flight needs a lot more. Although the Computer Scientist will have the help of domain experts (aeronautical and mechanical engineers), she must still be able to talk to such experts.

Page 23: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

91.102 - Computing II

Analysis of very complex systems: Algebra and Calculus, alone, may not be very helpful, but statistical techniques - sometimes quite sophisticated - may allow one to make sensible claims for one’s product.

Techniques from Algebra and Logic are crucial to constructing consistent and useful strongly typed languages - and crucial for thinking about many classes of objects.

Observation : Physics became very successful in providing both EXPLANATORY and PREDICTIVE theories only after it was “reduced” to Mathematics.

Page 24: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

91.102 - Computing II

By analogy (and analogy to Chemistry and Biology, which became VERY successful only after their “reduction” to Physics and Chemistry, respectively), one can expect that further mathematization of Computer Science will make Computer Science even more successful than it already is: it will be necessary to both explain and predict the behavior of complex systems at a level that we simply don’t possess yet - and “just programming our way through” will not suffice (and is quite unsatisfactory today: just think of all the missed deadlines and all the “bugs” in commercial programs) .

We don’t yet know how to do it, so we grope along... and the Mathematics that has been very successful in Physics may not be right for this task…

Page 25: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

#include <stdio.h>#define MaxIndex 100

int Find(int A[]) // Find operates on integer arrays, A{ int j; // j is an index variable used in the search

for (j = 0; j < MaxIndex; ++j){ // search upward starting at position 0 if (A[j] < 0) { // if A[j] is negative return j; // return its index j as the result } }

return -1; // return -1 if no negative integers were found}

91.102 - Computing II

Page 26: 91.102 - Intro. To Computing II Data Structures, Algorithms and Software Principles in C. Text by T. Standish. Lectures and Exams by G. Pecelli giam@cs.uml.edu.

int main(void){ int A[MaxIndex]; // declare A to be an integer array int i; // let i be an index variable used for // initialization

// Initialize array A to squares of integers. // Then make A[17] negative. for ( i = 0; i < MaxIndex; ++i ) A[i] = i*i; A[17] = - A[17];

// Print test results printf("First negative integer in A found at index = %2d.\n", Find(A));}

Program 1.3 Finding the First Negative Integer in an Integer Array

91.102 - Computing II