Today`s Coursenotes

Coursenotes
CS3114: Data Structures and
Algorithms
Clifford A. Shaffer
Department of Computer Science
Virginia Tech
Copyright © 2008-2013
How to Survive
Keys to success:
 Keeping Track of all the details
 You can’t remember it all
 Rational Planning (and keeping to the
plan)
 Spread the work over time
 Incremental Development
 Interleave writing and debugging
2
Being Organized 1
• Software development has so many
details
– Spec requirements
– Program interactions
• So does Life
– Assignments and other things to do
3
Being Organized 2
• You can’t turn this on/off
– Either you live an organized life, or you
can’t succeed as a software developer
– Part of it is developing the attitude of
“sweating the details”
– Part of it is having the coping mechanisms
to handle the details
4
Memory Can’t Handle It
• Externalize
– TODO lists (What)
– Scheduling (The Plan for How)
– Issue trackers
– Documenting/Commenting
– Be able to update lists at any time,
• Repository: GitHub
5
Spread Work Over Time
• For anything beyond a small software
project, you must have a plan/schedule
• Explicitly develop a schedule:
– Break into pieces: List of subtasks
– Deadlines for subtasks
– Realistic, enough flexibility built in
– Continuously modify and refine the plan
6
Incremental Development 1
How to fail at implementing your project:
1. Write the project
2. Debug the project
7
Incremental Development 2
How to succeed:
1. Write the smallest possible kernel
2. Debug the kernel thoroughly
3. Repeat until completion:
i. Add a functional unit
ii. Debug the resulting program
4. Have a way to track details
8
Incremental Development 3
• On any given day, write only as much
code as you have time to debug THAT
DAY
• This works well with Scheduling and
Organizing
9
Recursion
• An algorithm is recursive if it calls itself
to do part of its work.
• The key to success in recursion
– Don’t think about the process
– The recursive call is just another function call to do
something
Induction
• Just like recursion
– Base cases
– Induction hypothesis is the recursive call
(on a smaller version of the theorem)
– Induction works because you get to “use”
the induction hypothesis to do something.
Estimation Techniques
Known as “back of the envelope” or
“back of the napkin” calculation
1. Determine the major parameters that effect the
problem.
2. Derive an equation that relates the parameters
to the problem.
3. Select values for the parameters, and apply
the equation to yield and estimated solution.
12
Estimation Example
How many library bookcases does it
take to store books totaling one
million pages?
Estimate:
–
–
–
Pages/inch
Feet/shelf
Shelves/bookcase
13