CS2301:
Systems Programming
for Non-Majors
Class 20
Multi-Tasking
Networking
Why C is Great
Why C Stinks
Copyright 2005-2014, Michael J. Ciaraldi
1
Multi-Tasking
2
Multi-Threading vs.
Multi-Tasking
Ways to have your computer do
more than one thing at a ti
CS2301:
Systems Programming
for Non-Majors
Class 15
Data Structures:
Implementing Stacks
Lists
Trees
Copyright 2005-2014, Michael J. Ciaraldi
1
Implementing a Stack
2
Implementing a Stack
Data we need to keep track of:
Location of stack space.
Size of
CS2301:
Systems Programming
for Non-Majors
Class 14
Data Structures:
Defining
Using
Implementing
Copyright 2005-2014, Michael J. Ciaraldi
1
Data Structures
You may have used some:
Stack
Queue
Linked list
Tree
We will learn how to make them.
2
Data Struc
Theory in Practice, Part II,American
Scientist, 88, no. 2 (2000), 104109.
P1: 1/1 P2: 1/2 QC: 1/1 T1: 2 SUG-T
Rosen-2311T MHIA017-Rosen-v5.cls
May 13, 2011 10:28 B-6 Suggested
Reading [Ha93] John P. Hayes,
Introduction to Digital Logic Design,
Addison-Wes
its discovery by Cocks is described in
[Si99], which also provides an
appealing account of the history of
cryptography. CHAPTER 5 An
accessible introduction to
mathematical induction can be found
[Gu10] and in Sominskii [So61]. Books
that contain thorough
respectively. Sollins algorithm is an
example of an algorithm well suited for
parallel processing; although Sollin
never published a description of it, his
algorithm has been described by Even
[Ev73] and Goodman and Hedetniemi
[GoHe77]. CHAPTER 12 Boolean
both p and q are true, so the conclusion
p q is also true. e) If the hypothesis
(p q) is true, then p q is false, so
the conclusion p is true (and q is false).
f) If the hypothesis (p q) is true,
then p q is false, so p is true and q is
false. Hence, the
Graphs and Digraphs, 5th ed., Chapman
and Hall/CRC, Boca Raton, 2010.
[ChOe93] G. Chartrand and O. R.
Oellermann, Applied Algorithmic
Graph Theory, McGraw-Hill, New York,
1993. [ChZh04] G. Chartrand and P.
Zhang, Introduction to Graph Theory,
McGraw-Hill,
1984. [Da82] C. J. Date, An Introduction
to Database Systems, 3d ed., AddisonWesley, Reading, MA, 1982. [DaSiWe94]
M. Davis, R. Sigal, and E. J. Weyuker,
Computability, Complexity, and
Languages, 2d ed., Academic Press, San
Diego, 1994. [Da10] T. Davis, T
computer science, provides examples
of average case complexity analysis
and covers the probabilistic method.
Aho and Ullman [AhUl95] includes a
discussion of various aspects of
probability theory important in
computer science, including
programming applic
P1: 1 ANS Rosen-2311T MHIA017Rosen-v5.cls May 13, 2011 10:29 S-28
Answers to Odd-Numbered Exercises
left) causes the left-hand side to
increase by x y. Because x y (mod
11), the congruence will no longer hold.
Therefore errors of this type are always
dete
hostess and the remaining professors
know that the first professor did want
coffee. Similarly, the second professor
must want coffee. When the third
professor said no, the hostess knows
that the third professor does not want
coffee. 19. A is a knight and
[RoFo80]; Roberts and Tesman
[RoTe03]; and Tucker [Tu06]. The
application of lattices to information
flow is treated in Denning [De82].
CHAPTER 10 General references for
graph theory include Agnarsson and
Greenlaw [AgGr06]; Aldous, Wilson,
and Best [AlWiB
comprehensive description of
algorithms in graph theory can be
found in Gibbons [Gi85] and in Kocay
and Kreher [KoKr04]. Other references
for algorithms in graph theory include
Buckley and Harary [BuHa90];
Chartrand and Oellermann [ChOe93];
Chachra, Ghare
form 2kp + 1. Furthermore, the product
of numbers of this form is also of this
form. Therefore, all divisors of 2p 1
are of this form. 43. M11 is not prime;
M17 is prime. 45. First, 2047 = 23 89 is
composite. Write 2047 1 = 2046 = 2
1023, so s = 1 and t
CS2301:
Systems Programming
for Non-Majors
Class 6
Kinds and Scope of Variables
Conditionals
Arrays
Sorting
Copyright 2005-2014, Michael J. Ciaraldi
1
But First
Header Files
Where are standard header files
stored?
o Most are in /usr/include and its
subdir
CS2301:
Systems Programming
for Non-Majors
Class 12
The const Keyword
Logical & Bit-Wise Operations
Formatted Input
Raw Input/Output
Copyright 2005-2014, Michael J. Ciaraldi
1
const
2
const
In C, you can put the const keyword
on a variable or on a formal
CS2301:
Systems Programming
for Non-Majors
Class 13
Octal, Hex, and Binary Constants
Bit Masks
Bit Shift
Preprocessor:
Defines, Macros, Conditional Compile
Start of Data Structures
Copyright 2005-2014, Michael J. Ciaraldi
1
Octal, Hex, and Binary
Constant
CS2301:
Systems Programming
for Non-Majors
Class 7
Incrementing & Decrementing
Memory
Pointers
Arrays & Pointers
Copyright 2005-2014, Michael J. Ciaraldi
1
Incrementing &
Decrementing
2
Incrementing &
Decrementing
Similar to Java, but more versatile.
Pre-
CS2301:
Systems Programming
for Non-Majors
Class 10
Source Formatting
Error Messages
Pointers and Efficiency
Structs
printf() and its Relatives
Copyright 2005-2014, Michael J. Ciaraldi
1
Source Formatting
2
Eliminate Needless Blank Lines
and Indenting
for
CS2301:
Systems Programming for
Non-Majors
Class 09
sizeof
Character Arrays & Functions
Pointer Arithmetic
Copyright 2005-2014, Michael J. Ciaraldi
1
sizeof
2
sizeof
A unary operator which returns the
size of a variable, expression, or
type.
o In bytes.
o
CS2301:
Systems Programming
for Non-Majors
Class 4
Source File Formatting
Sequence Control
if, for, while, goto, break, and continue
The One-and-a-Half Loop Problem
Header Files
Make
Copyright 2005-2014, Michael J. Ciaraldi
1
But First
The two biggest se
CS2301:
Systems Programming
for Non-Majors
Class 3
Primitive Data Types
Variable Declarations
Assignment
Expressions
Output
Copyright 2005-2014, Michael J. Ciaraldi
1
Primitive Data Types
2
Primitive Data Types
Usually those implemented directly
by the ha
CS2301:
Systems Programming
for Non-Majors
Class 1
Introduction
Copyright 2005-2014, Michael J. Ciaraldi
1
Today
Course intro
2
Course Intro
3
Course Intro
Introduction of the course staf
Text
Purpose of the course
Logistics
Enrollment limits
Policies
CS2301:
Systems Programming
for Non-Majors
Class 5
Functions & Function Prototypes
Parameter Passing
Doxygen & Documentation
Brief Intro to printf()
Multiple Files
Copyright 2005-2014, Michael J. Ciaraldi
1
Functions and
Function Prototypes
2
Functions
W
CS2301:
Systems Programming
for Non-Majors
Class 2
More Introduction
Some History
Linux
Program Construction
Copyright 2005-2014, Michael J. Ciaraldi
1
Academic Honesty Policy
Dont Cheat!
Do your own work.
Dont take credit for someone elses
work.
Mere
CS2301:
Systems Programming
for Non-Majors
Class 11
Standard I/O & Redirection
Debugging
Copyright 2005-2014, Michael J. Ciaraldi
1
Standard I/O & Redirection
2
Standard I/O
In Unix / Linux, programs start with
three standard I/O devices already
open:
S
CS2301:
Systems Programming for
Non-Majors
Class 08
typedef
Memory Alignment
malloc()
Casting
Copyright 2005-2014, Michael J. Ciaraldi
1
typedef
2
typedef
Allows you to create aliases for
types.
o For greater readability.
o For greater portability.
Since
CS2301:
Systems Programming
for Non-Majors
Class 16
Trees
Tree Traversal
Tree Sort
Allocation/Deallocation:
caller vs. callee
Copyright 2005-2014, Michael J. Ciaraldi
1
C is Fun!
http:/stuph.hackshack.ca/
2
Trees
3
Trees
A very useful data structure whi
CS2301:
Systems Programming
for Non-Majors
Class 18
Numbers:
Representation & Conversion
Copyright 2005-2014, Michael J. Ciaraldi
1
Numbers:
Representation
and Conversion
2
Number Representation
All Java implementations are
supposed to use the same inter
TTF T T T F T TFT T T F T T TFF F F F F
F FTT T F F F F FTF T F F F F FFT T F F F
F FFF F F F F F 7. a) Jan is not rich, or
Jan is not happy. b) Carlos will not
bicycle tomorrow, and Carlos will not
run tomorrow. c) Mei does not walk to
class, and Mei doe
Analytic Geometry, 9th ed., AddisonWesley, Reading, MA, 1996. [TrMa75] J.
P. Tremblay and R. P. Manohar, Discrete
Mathematical Structures with
Applications to Computer Science,
McGraw-Hill, New York, 1975. [Tu06]
Alan Tucker, Applied Combinatorics,
5th ed
1984. [Ro10] K. H. Rosen, Elementary
Number Theory and Its Applications,
6th ed., Pearson, Boston, 2010. [Ro00]
K. H. Rosen, Handbook of Discrete and
Combinatorial Mathematics, CRC Press,
Boca Raton, FL, 2000. [Ro09] Jason
Rosenhouse, The Monty Hall Probl
Functions, Bell System Technical
Journal (May 1962), 877884. [Ra92]
Gregory J. E. Rawlins, Compared to
What? An Introduction to the Analysis
of Algorithms, Computer Science Press,
New York, 1992. [ReNiDe77] E. M.
Reingold, J. Nievergelt, and N. Deo,
Combi
Moore machines were originally
introduced in Mealy [Me55] and Moore
[Mo56]. The original proof of Kleenes
theorem can be found in [Kl56].
Powerful models of computation,
including pushdown automata and
Turing machines, are discussed in
Brookshear [Br89],