UNIX and Vim
Operating system family.
Originally developed in the 1970s.
Has many derived systems:
Primarily command-line based.
Programs do one thing and do it well.
Programs interact with other
A linked list is a fundamental data structure. The basic idea is that the list is composed of "nodes". Each node node contains one
data element and the link to the next node in the list.
Unlike arrays, the elements in a linked li
The point of object-oriented programming is to create new types. When we create types, we
want to be able to use them as naturally as possible. Suppose we have written a Fraction
class to represent fractional values:
So far we have mostly worked with programs that have consisted of a single file. Most
programs, however, are split into multiple files. In order to compile multiple files together,
we could pass them all to g+ like so:
> g+ a.cpp b.cp
Introduction to Data
A data structure is a way of storing data in an organized way that allows the data to be used
Data structures that work well for some usages may be totally inappropriate for another use.
Huffman coding is a simple method of data compression. In data compression we want to
represent some information in the smallest memory space possible. There are two main
types of compression:
Lossy: some data is lost in the pr
Say we want to write a phone book program. The program will allow us to enter our friend's
phone numbers. Then we will be able to search for a friend's phone number by entering their
What data structure would we use for this?
A queue is a data structure for storing elements in a first-in-first-out manner. So we will
remove items in the same order that they came in.
In some applications, however, we may want to allow elements to skip others in some
I/O Redirection, Pipes &
Suppose you want to test your Spell Check program by reading in several words and
checking the results. This process can be automated on UNIX.
To do this we first create a file with our input in it. We can use
Function Pointers &
Accessing Linked List Elements
The linked list now allows us to store any type of data inside of it. So if we want to use the
linked list in multiple programs, to store lots of different types of data, then we would be
The exam will be cumulative, this page only lists material since the midterm.
Enqueue and Dequeue.
Array and List Implementations.
Motivation for using them.
How to write a template class.
Using type parameters.
Pointers & Arrays
Arrays are the only data structure built into the C+ language.
They are stored contiguously in memory.
Every element must be the same data type.
Arrays have a fixed number of elements.
They are indexed starting at 0.
We have seen how to time programs using the "time" command. This allows us to see how long it takes to run an entire program. If
your program runs slower than you want, however, how would you know how to improve it?
We could look at
Using Multiple Files
When writing larger programs, it becomes impractical to put all of the code in one file.
Instead, we split the code into multiple files where the code in a single file is logically
This also allows parts of programs
The next data structure we will look at is the stack. The data structures we have looked at thus far, arrays and linked lists, have been primarily
concerned with how data is physically stored and accessed. Stacks, on the other hand, are pr
So far in this class, we have implemented data structures that hold a specific type of data,
such as ints, strings, doubles etc. For example, the Queue example from last class stores
If we want to change the data structure to stor
The command line can be dangerous:
rm * .o
g+ program.cpp -o program.cpp
tar -cvf program.cpp header.h
Everyone will accidentally delete or corrupt a file at some point. We want to be able to recover our code if this
Due: April 26
To gain experience using graphs and topological sorting.
Directed Acyclic Graphs (DAGs) are an important type of graph with many applications.
Recall that a directed graph is one where the edges have a direction. Rec
Standard Template Library
The C+ standard template library is a library that includes many of the data structures and algorithms we have discussed this
It is important to know and understand how these data structures work, so that you'l
Searching & Sorting
Searching and sorting are important problems in computer science and are used in some
way in most non-trivial programs. Like most problems, there are multiple ways to do
searching and sorting, with trade-offs for each.
Due: April 15
To gain experience using templates and binary search trees.
A simple way of performing spell checking is to store the set of all valid words in some data
structure. For each word we need to check, we'll search th
We can define the factorial of a number as follows:
x! = x * (x - 1) * (x - 2) . * 3 * 2 * 1
If we want to write a C+ function that computes the factorial of a number, we can do it
with a loop like so:
int fact(int x) cfw_
int product =
As we saw, stacks are "Last In First Out" (LIFO) data structures. This means that the last thing added to the stack is the first
thing that is removed.
If we do the opposite of this, and remove the first thing we added instead of the last,
A graph is a data structure that consists of a number of nodes (or vertices) and a number of edges.
An edge is a connection between two nodes. Nodes are used to represent objects and the edges
represent some kind of relationship between th
All of the memory for variables and objects we have used so far has been managed
automatically for us. This means that the compiler sets up the space to store our variables
However, many times we don't k
Additional UNIX Skills
On the command line, if you hit the "tab" key, the shell will try to complete the
command for you.
Using the "up" and "down" keys will cycle through your command history.
You can have multiple terminals open at once, and t
Binary Search Trees
The data structures we have used so far have been linear by nature. Arrays, linked lists, stacks, queues and hash tables all of a definite
start and end. Today we will look at a type of data structure, the tree, where this is not
Linked List Exercise
To gain practice using linked lists and multiple file programs.
For this lab, you will extend the "IntList" with a function that will calculate the sum of the
numbers stored in the list. You will write the function and
To gain experience with graphs.
Recall that a complete graph is one in which every node is connected to every other node by
an edge. In this lab, you will write a function to test whether or not a graph (based on an