Fundamentals of Computer Science II (CSC-152 97F)

[News] [Basics] [Syllabus] [Outlines] [Assignments] [Examples] [Readings] [Bailey Docs]

# Outline of Class 52: Overview of CS

The outline of today's class is still in draft form.

## Miscellaneous

• Reminder: We'll have a review session Tuesday, Dec. 16th at 7pm.
• My "laboratory" now has one Macintosh, an 8600/300. You should feel free to use it, but don't abuse it (it's in the MathLAN laboratory).
• Today and tomorrow we'll do a short "tour of computer science". I hope you'll find the material interesting, but you don't need to worry about it being on the final.

## Implementing Graphs

• In order to implement any of the aforementioned algorithms, we'll need a `Graph` data structure.
• How do we implement graphs (directed graphs, weighted graphs, etc.)
• As in other cases, it may depend on the way you intend to use the graph. For example, if you frequently attempt to list all the neighbors of a node (as we did in a few recent algorithms), you want something that provides an answer to that question quickly.
• There are three main implementations of graphs:
• Edge lists
• In an edge list implementation, the graph is implemented as a list of edges (pairs of nodes, potentially ordered, potentially weighted).
• This makes it easy to get a list of all the edges :-).
• This makes it easy to add edges.
• This makes it easy to present the graph in textual form (just list the edges).
• This makes it difficult to get all the neighbors of a node, as we must look at all the edges in the graph.
• This makes it difficult to determine whether or not a node is in the graph.
• In an adjacency list implementation, we associate a list of neighbors (plus edge weights if appropriate) with each node. Often, we store the individual nodes in a dictionary for quick access.
• This makes it nearly as easy to add edges.
• This makes it relatively easy to get a list of all edges.
• This makes it easy to get all the neighbors of a node.
• This makes is slightly difficult to determine if there is an edge between two nodes (it's O(#neighbors)).
• In an adjacency matrix implementation, we build a matrix of all pairs of nodes. Each entry in the matrix reflects the weight of the edge from one node to the corresponding node. (In a non-weighted graph, it might simply contain a boolean value: true for edge, false for non-edge.)
• This makes it easy to determine if there is an edge between two nodes (O(1)).
• This makes it easy to add edges (O(1)).
• This makes is slightly more difficult to get lists of edges O(n^2).
• ...
• Can you think of other reasonable implementations?

## A Tour of Computer Science

• What is computer science? At times, it depends on who you ask.
• An engineer might tell you that it's the study of how to build computers. Others would call this Computer Engineering.
• One of the faculty at my old institution might tell you that it's the study of computational complexity -- what can and cannot be computed. Others might call this a part of Theoretical Computer Science.
• A programmer might tell you that it's the study of programming. Others might call that Software Engineering.
• A typical computer user might guess that it's the study of computer applications, like word processors or spreadsheets.
• A humanist might tell you that computer science is a preprofessional specialization, unfit for a liberal arts education. Others might call that severely biased. (Yes, that was intended as a joke.)
• While CS encompasses these ideas, it is much more.
• A book I like (Schneider and Gersting's An Invitation to Computer Science) suggests that
Computer Science is the study of algorithms, including their (1) formal and mathematical properties, (2) hardware realizations, (3) linguistic realizations, and (4) applications.
• I would extend that to say that computer science is the study of algorithms and data representation, since some of what we do in CS focuses more on the data than on the algorithm (as we've seen in this course).
• Computer Science lies at the intersection of a number of intellectual endeavors, particularly
• Science
• Mathematics
• Engineering
• In fact, the recommended computing curriculum suggests that we approach each topic in CS from each of these perspectives.
• If we're to do that, we need definitions. That's up to you ... (it may be less fun in this class than in other classes I've taught).

### Subfields of Computer Science

• Like many modern fields, computer science has segmented into a number of subfields. There is some overlap between many of these subfields, but there are also some clear divisions.
• Some of the ones that come to mind are ...
• Computer architecture -- the design and analysis of the primary electronic components of computers.
• Programming languages -- the design, analysis, and implementation of the languages we use to express computation.
• Algorithms -- the formal design and analysis of procedures for solving problems.
• Computability theory -- the study of what can and cannot be computed.
• Human-computer interaction -- the study of how computers can be made easier to use and how computers affect human task-completion activities.
• Information retrieval -- mechanisms for organizing data for quick access; models and systems for access to data.
• Multimedia -- the electronic integration of text, audio, video, graphics, animations, ....
• Operating systems -- how to provide a robust and reliable computing system upon which other applications rely. Concerns itself with processes (programs as they execute), memory, file systems, and such.
• Networking -- how computers can communicate with each other reliably and quickly.
• Parallel and distributed computing -- the use and coordination of multiple computers (and computer components) acting together.
• Applications -- the things we can do with computers.
• Software engineering -- the formal discipline of writing computer programs.
• Artificial intelligence -- the attempt to simulate human thought processes on computers.
• Social issues -- the effects of computers on humans and society.
• ...
• Obviously, it won't be possible to discuss all of these in any detail. We will, however, attempt to visit an interesting problem (or problems) in many of the subfields.
• We won't visit these subfields in any particular order.

### Operating Systems

• The goal of operating systems design is to provide a mechanism by which programs can easily and reliably use system resources.
• These resources include the computer's memory, the hardware, and such.
• The problem becomes more difficult as you need to have your computer handle multiple "cooperating" processes. For example, on the HP's you can be simultaneously running a mail reader, netscape, emacs, and more.
• What happens if two processes try to modify the same file?
• What happens if the total amount of memory the processes need is greater than the actual memory on the machine?
• Given that most processors can only run one process at a time, how do you simulate multiple processes?
• ...

#### Dining Philosophers

• An interesting problem from the operating systems community is the dining philosophers problem. Seated around a circular table are N philosophers thinking and eating Chinese food. Between every two philosophers is a chopstick. Each philosopher needs two chopsticks in order to eat. Come up with a strategy for the philosophers to use that ensures that every philosopher gets to eat.
• More particularly, you would want to define `getChopSticks()` and related functions for the following ...
```public class Philosopher() {
public exist() {
think();
getChopSticks();
eat();
dropChopSticks();
} // while still alive
} // exist
} // philosopher
```
• If your `getChopSticks()` simply picks up left then right, you may run into a problem if all philosophers get hungry at the same time. Each picks up the left chopstick and then waits until the right chopstick becomes available.
• It turns out that the solution to this problem relies on a special concept called the critical section in which you ensure that only one process can access a critical section at once.
• The dining philosphers problem models resource usage on many computing systems ("I need this file and this output device and ...").

### Programming Languages

• The subfield of programming languages concerns itself with the languages used to describe algorithms ("their linguistic realizations").
• It has its own subsubfields that include the design of languages, the implementation of languages, and even the theoretical power of languages.
• You've already seen a number of key issues in programming language design, including:
• Key paradigms: Imperative, Functional, and Object-oriented (yes, there are others).
• Error-handling mechanisms (e.g., exceptions vs. "test then do").
• Translation (implementation of one thing using another).

#### Lazy Evaluation

• One of my favorite concepts in languages is that of lazy evaluation.
• Consider a simple language in which you can define functions and apply them.
• One problem in the design of such a language is how to deal with the application of a function to arguments.
• You might choose to evaluate the arguments and then pass the results to the function.
• You might choose to pass the unevaluated arguments to the function. In this case, you'll eventually need to evaluate arguments in order to get some output.
• For example, given the definition
```square(x) = x*x
```
• You could evaluate `square(2+3)` by ...
• first evaluating `2+3` (getting 5), then replacing `square(5)` by `5*5`, then replacing `5*5` by 25.
• replacing `square(2+3)` by `(2+3)*(2+3)`, then evaluating each of the `(2+3)`'s, then replacing `5*5` by 25.
• The first strategy is called innermost, the second is often called outermost.
• Which is better? Well, it depends on how extreme you're willing to be. If you believe that you should only use one strategy, then innermost can have serious disadvantages.
• Consider the factorial function, which might be defined as ``` fact(n) = if(n==0, 1, n*fact(n-1)) ```
• Observe that `if()` is also a function.
• `if` might be defined as
```if(true,T,F) = T
if(false,T,F) = F
```
• Consider the evaluation of `fact(1)` ...
```fact(1)
-> if(1==0, 1, 1*fact(1-1))
-> if(false, 1, 1*fact(1-1))
-> if(false, 1, 1*fact(0))
-> if(false, 1, 1*if(0==0, 1, 0*fact(0-1)))
-> if(false, 1, 1*if(true, 1, 0*fact(-1)))
-> if(false, 1, 1*if(true, 1, 0*if(-1==0, 1, -1*fact(-1-1))))
-> ...
```

Outlines: prev next

[News] [Basics] [Syllabus] [Outlines] [Assignments] [Examples] [Readings] [Bailey Docs]

Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.