CS 311 Fall 2020: Data Structures and Algorithms


CS 311 Fall 2020
Data Structures and Algorithms

Department: Computer Science, UAF
Instructor: Glenn G. Chappell
Office Hours: No face-to-face office hours during fall 2020; private Zoom sessions are available by appointment
Office phone: (474-)5736
E-mail: ggchappell@alaska.edu
Class meeting Zoom: here (passcode distributed via e-mail)

Announcements

Course Materials

Materials are listed with the most recent at the top.

Week Class Meetings
See Blackboard for class-meeting videos
Readings & Homework Handouts & Code
See Git repository for code
Week 15
11/30–12/4
  • 12/4: Other graph topics; course wrap-up
  • 12/2: Graph traversals (cont’d); spanning trees
    Slides [PDF]
  • 11/30: Introduction to graphs; graph traversals
    Slides [PDF]
  • prim.cpp [C++ source]
    Prim’s Algorithm
  • Pictures for Online Quiz 24 [PDF]
  • graph_traverse.cpp [C++ source]
    Graph traversals: DFS & BFS
Week 14
11/23–11/24
  • 11/27: No class meeting (Thanksgiving)
  • 11/25: No class meeting (Thanksgiving)
  • 11/23: Tables in the C++ STL & elsewhere (cont’d); the rest of the course; external data
    Slides [PDF]
  • Online Quiz 23—on Blackboard
    Before taking this quiz, attend the 11/18 & 11/20 classes
    Due 12:30 pm Mon 11/23
 
Week 13
11/16–11/20
  • 11/20: Thoughts on Project 8; Tables in the C++ STL & elsewhere
    Slides [PDF]
  • 11/18: Hash Tables (cont’d); Prefix Trees
    Slides [PDF]
  • 11/16: Hash Tables
    Slides [PDF]
  • Project 8
    Due 5 pm Tue 12/1
  • Online Quiz 22—on Blackboard
    Before taking this quiz, attend the 11/11–16 classes
    Due 12:30 pm Wed 11/18
  • squarer_test.cpp [C++ source] SKELETON
    Tests for class Squarer
    For Project 8, Exercise B
    Uses the “doctest” unit-testing framework, version 2
    Requires doctest.h, squarer.h
  • squarer.h [C++ header]
    Header for class Squarer
    There is no associated source file.
    For Project 8, Exercise A
  • countwords_test.txt [ASCII text file]
    Test input file for Project 8, Exercise A
    This file is also in the Git repository.
  • Pictures for Online Quiz 22 [PDF]
Week 12
11/9–11/13
  • 11/13: 2-3 Trees (cont’d); other self-balancing search trees
    Slides [PDF]
  • 11/11: 2-3 Trees
    Slides [PDF]
  • 11/9: Thoughts on Project 7; Binary Heap Algorithms (cont’d); Heaps & Priority Queues in the C++ STL
    Slides [PDF]
  • Online Quiz 21—on Blackboard
    Before taking this quiz, attend the 11/6 & 11/9 classes
    Due 12:30 pm Wed 11/11
  • Project 7
    Due 5 pm Mon 11/16
  • Pictures for Online Quiz 21 [PDF]
  • treesort_test.cpp [C++ source]
    Test program for function template treesort
    For Project 7, Exercise A
    Uses the “doctest” unit-testing framework, version 2
    Requires doctest.h, treesort.h
  • treesort.h [C++ header] SKELETON
    Header for function template treesort
    There is no associated source file.
  • pq.cpp [C++ source]
    Priority Queues & custom comparisons
  • heap_sort.cpp [C++ source]
    Heap Sort
    Requires heap_algs.h
Week 11
11/2–11/6
  • 11/6: Priority Queues; Binary Heap algorithms
    Slides [PDF]
  • 11/4: Binary Search Trees (cont’d); unit overview—Tables & Priority Queues; introduction to Tables
    Slides [PDF]
  • 11/2: Binary Trees; Binary Search Trees
    Slides [PDF]
  • Online Quiz 20—on Blackboard
    Before taking this quiz, attend the 11/4 class
    Due 12:30 pm Fri 11/6
  • Online Quiz 19—on Blackboard
    Before taking this quiz, attend the 11/2 class
    Due 12:30 pm Wed 11/4
  • Online Quiz 18—on Blackboard
    Before taking this quiz, attend the 10/30 class
    Due 12:30 pm Mon 11/2
Week 10
10/26–10/30
  • 10/30: Thoughts on Project 6; Queues; unit overview—the basics of trees; introduction to trees
    Slides [PDF]
  • 10/28: Stacks
    Slides [PDF]
  • 10/26: More on Linked Lists (cont’d); sequences in the C++ STL
    Slides [PDF]
  • Project 6
    Due 5 pm Thu 11/5
  • Online Quiz 17—on Blackboard
    Before taking this quiz, attend the 10/23–28 classes
    Due 12:30 pm Fri 10/30
  • dp6_test.cpp [C++ source]
    Test program for Project 6 templates
    For Project 6, Exercises A, B
    Uses the “doctest” unit-testing framework, version 2
    Requires doctest.h, dp6.h
  • fibo_bf_elim.cpp [C++ source]
    Computing Fibonacci numbers
    Recursion eliminated, brute-force method
  • rpn_evaluate.cpp [C++ source]
    Reverse Polish Notation expression evaluation
    Example application of a Stack
  • use_list2.cpp [C++ source]
    Singly Linked List example using smart pointers: create & find size
    Based on use_list.cpp
    Requires llnode2.h
  • llnode2.h [C++ header]
    Header for struct LLNode2
    Singly Linked List node using smart pointers + associated functionality
    Based on llnode.h
    There is no associated source file.
Week 9
10/19–10/23
  • 10/23: Node-based structures; more on Linked Lists
    Slides [PDF]
  • 10/21: Allocation & efficiency; generic containers; thoughts on Project 5
    Slides [PDF]
  • 10/19: Exception safety (cont’d)
    Slides [PDF]
  • Online Quiz 16—on Blackboard
    Before taking this quiz, attend the Wed 10/21 class
    Due 12:30 pm Fri 10/23
  • Project 5
    Due 5 pm Thu 10/29
  • Online Quiz 15—on Blackboard
    Before taking this quiz, attend the Fri 10/16 & Mon 10/19 classes
    Due 12:30 pm Wed 10/21
  • tfsarray_test.cpp [C++ source]
    Test program for class template TFSArray
    For Project 5, Exercise A
    Uses the “doctest” unit-testing framework, version 2
    Requires doctest.h, tfsarray.h
Week 8
10/12–10/16
  • 10/16: Exception safety
    Slides [PDF]
  • 10/14: Basic array implementation
    Slides [PDF]
  • 10/12: Where are we?; data abstraction; introduction to Sequences; interface for a smart array
    Slides [PDF]
  • Online Quiz 14—on Blackboard
    Before taking this quiz, attend the Mon 10/12 & Wed 10/14 classes
    Due 12:30 pm Fri 10/16
  • fsarray.h [C++ header] INCOMPLETE
    Header for class FSArray
    Frightfully smart array of int
    Preliminary to Project 5
  • fsarray.cpp [C++ source] INCOMPLETE
    Source for class FSArray
    Frightfully smart array of int
    Preliminary to Project 5
  • fsarray_main.cpp [C++ source]
    Check whether FSArray package compiles
    Requires fsarray.h, fsarray.cpp
Week 7
10/5–10/9
  • 10/9: No class meeting; Take-Home Midterm Exam due  2 pm  5 pm
  • 10/7: Non-comparison sorts; sorting in the C++ STL
    Slides [PDF]
  • 10/5: Comparison sorts III (cont’d)
    Slides [PDF]
  • Online Quiz 13—on Blackboard
    Before taking this quiz, attend the Mon 10/5 class
    Due 12:30 pm Wed 10/7
  • Online Quiz 12—on Blackboard
    Before taking this quiz, attend the Fri 10/2 class
    Due 12:30 pm Mon 10/5
Week 6
9/28–10/2
  • 10/2: The limits of sorting; comparison sorts III
    Slides [PDF]
  • 9/30: Asymptotic notation; divide and conquer; comparison sorts II
    Slides [PDF]
    Master Theorem Slide [PDF]
  • 9/28: Thoughts on Project 4; comparison sorts I
    Slides [PDF]
  • Online Quiz 11—on Blackboard
    Before taking this quiz, attend the Wed 9/30 class
    Due 12:30 pm Fri 10/2
  • Online Quiz 10—on Blackboard
    Before taking this quiz, attend the Mon 9/28 class
    Due 12:30 pm Wed 9/30
  • Project 4
    Due 5 pm Tue 10/6
  • Online Quiz 9—on Blackboard
    Before taking this quiz, attend the Wed 9/23 & Fri 9/25 classes
    Due 12:30 pm Mon 9/28
  • stirling.py [Python 3 source]
    Compare factorial & Stirling’s approximation
  • iterative_merge_sort.cpp [C++ source]
    Iterative Merge Sort
  • merge_sort.cpp [C++ source]
    Merge Sort (recursive)
  • counthsw_test.cpp [C++ source]
    Test program for function countHSW
    For Project 4, Exercise A
    Uses the “doctest” unit-testing framework, version 2
    Requires doctest.h, counthsw.h, counthsw.cpp
  • insertion_sort.cpp [C++ source]
    Insertion Sort
  • bubble_sort.cpp [C++ source]
    Bubble Sort
Week 5
9/21–9/25
  • 9/25: Analysis of algorithms; introduction to sorting
    Slides [PDF]
  • 9/23: recursive backtracking; unit overview—algorithmic effiency & sorting
    Slides [PDF]
  • 9/21: Search algorithms II; eliminating recursion; search in the C++ STL
    Slides [PDF]
  • Online Quiz 8—on Blackboard
    Before taking this quiz, attend the Fri 9/18 & Mon 9/21 classes
    Due 12:30 pm Wed 9/23
  • important.py [Python 3 source]
    Print the sum from Analysis of Algorithms
    Illustrates the most important part of a formula
  • nqueencount.cpp [C++ source]
    Count solutions to the n-Queens problem
    Example of Recursive Backtracking
  • nqueen.cpp [C++ source]
    Print solutions to the n-Queens problem
    Example of Recursive Backtracking
  • binsearch4.cpp [C++ source]
    Binary Search
    Implementation #4: iterative (tail recursion eliminated)
  • binsearch3.cpp [C++ source]
    Binary Search
    Implementation #3: tail-recursive
  • seqsearch_compare.cpp [C++ source]
    Compare Sequential Search with Binary Search
    Uses Binary Search implementation from binsearch2.cpp
Week 4
9/14–9/18
  • 9/18: Recursion vs. iteration
    Slides [PDF]
  • 9/16: Search algorithms I
    Slides [PDF]
  • 9/14: Software engineering concepts: abstraction; a little about Linked Lists; unit overview—recursion & searching; introduction to recursion
    Slides [PDF]
  • Project 3
    Due 5 pm Thu 9/24
  • Online Quiz 7—on Blackboard
    Before taking this quiz, attend the Wed 9/16 class
    Due 12:30 pm Fri 9/18
  • Online Quiz 6—on Blackboard
    Before taking this quiz, attend the Fri 9/11 & Mon 9/14 classes
    Due 12:30 pm Wed 9/16
  • fibo_fast.py [Python 3 source]
    Computing Fibonacci numbers
    Fast method
  • fibo_formula.cpp [C++ source]
    Computing Fibonacci numbers
    Formula implementation
  • fibo_dp_topdown.cpp [C++ source]
    Computing Fibonacci numbers
    Recursive top-down dynamic programming implementation
    A.k.a. memoizing
  • fibo_recurse.cpp [C++ source]
    Computing Fibonacci numbers
    Fast recursive implementaton
  • fibo_iterate.cpp [C++ source]
    Computing Fibonacci numbers
    Iterative implementaton
  • dp3_test.cpp [C++ source]
    Test program for Project 3 functions & templates
    For Project 3, Exercises A, B, C, D
    Uses the “doctest” unit-testing framework, version 2
    Requires doctest.h, dp3.h, dp3.cpp
  • dp3.h [C++ header] SKELETON
    Header for Project 3 functions
    For Project 3, Exercises A–D
  • dp3.cpp [C++ source] SKELETON
    Source for Project 3 functions
    For Project 3, Exercises A–D
  • binsearch2.cpp [C++ source]
    Binary Search
    Implementation #2: recursive (improved)
  • binsearch1.cpp [C++ source]
    Binary Search
    Implementation #1: recursive
  • fibo_first.cpp [C++ source]
    Computing Fibonacci numbers
    First attempt: slow recursive implementation
  • use_list.cpp [C++ source]
    Singly Linked List example: create & find size
    Requires llnode.h
  • llnode.h [C++ header]
    Header for struct LLNode
    Singly Linked List node
    There is no associated source file.
Week 3
9/8–9/11
  • 9/11: Error handling; using exceptions
    Slides [PDF]
  • 9/9: Containers & iterators (cont’d); invisible functions II; thoughts on Project 2
    Slides [PDF]
  • 9/7: No class meeting (Labor Day)
  • Online Quiz 5—on Blackboard
    Before taking this quiz, attend the Wed 9/9 class
    Due 12:30 pm Fri 9/11
  • Project 2
    Due 5 pm  Tue 9/15  Thu 9/17
  • Online Quiz 4—on Blackboard
    Before taking this quiz, attend the Fri 9/4 class
    Due 12:30 pm Wed 9/9
  • allocate2_raii.cpp [C++ source]
    Out-of-memory handling using exceptions, with RAII classes
  • allocate2.cpp [C++ source]
    Out-of-memory handling using exceptions
  • except.cpp [C++ source]
    Demo of throwing & catching exceptions
  • iterators.cpp [C++ source]
    Iterator & STL demo
  • msarray_test.cpp [C++ source]
    Test program for class template MSArray
    For Project 2, Exercise A
    Uses the “doctest” unit-testing framework, version 2
    Requires doctest.h, msarray.h
Week 2
8/31–9/4
  • 9/4: Managing resources in a class (cont’d); containers & iterators
    Slides [PDF]
  • 9/2: Software engineering concepts: testing; integer types; managing resources in a class
    Slides [PDF]
  • 8/31: Software engineering concepts: invariants; simple class example (cont’d); thoughts on Project 1
    Slides [PDF]
  • Online Quiz 3—on Blackboard
    Before taking this quiz, attend the Mon 8/31 & Wed 9/2 classes
    Due 12:30 pm Fri 9/4
  • Project 1
    Due 5 pm Tue 9/8
  • intarray.h [C++ header]
    Header for class IntArray
    Simple RAII class class holding dynamic array of int
    There is no associated source file.
  • intarray_main.cpp [C++ source]
    Simple main program for class IntArray
    Requires intarray.h
  • setmember.cpp [C++ source]
    See how class members are initialized
  • productorder_test.cpp [C++ source]
    Test program for class ProductOrder
    For Project 1, Exercise A
    Uses the “doctest” unit-testing framework, version 2
    Requires doctest.h, productorder.h, productorder.cpp
  • Coding Standards
Week 1
8/24–8/28
  • 8/28: Invisible functions I (cont’d); simple class example
    Slides [PDF]
  • 8/26: Operator overloading; parameter passing II; invisible functions I
    Slides [PDF]
  • 8/24: Course overview; unit overview—advanced C++ & software engineering concepts; expressions; parameter passing I
    Slides [PDF]
  • Online Quiz 2—on Blackboard
    Before taking this quiz, attend the Wed 8/26 & Fri 8/28 classes and read “On Following Rules”
    Due 12:30 pm Mon 8/31
  • 8/26: Read “On Following Rules”.
    The above date is when the reading is assigned. Each reading should be completed before taking the quiz that covers it—in this case, Online Quiz 2.
  • Online Quiz 1—on Blackboard
    Before taking this quiz, attend the Mon 8/24 class
    Due 12:30 pm Wed 8/26
  • timeofday.h [C++ header]
    Header for class TimeOfDay
    Time of day: hours, minutes, seconds
  • timeofday.cpp [C++ source]
    Source for class TimeOfDay
    Time of day: hours, minutes, seconds
  • timeofday_main.cpp [C++ source]
    Simple main program for class TimeOfDay
    Requires timeofday.h/.cpp
  • invisible.cpp [C++ source]
    Demo of invisible functions
  • Semester Plan
    Updated Mon 11/9
  • Syllabus

External links last checked December 1, 2020.
cppreference.com
A comprehensive, up-to-date reference for the C & C++ programming languages and their standard libraries. I have found this site to be very helpful; I use it often.
Git
Git is the the version-control software used in this class. This site includes downloads and a helpful tutorial.
Class Git Repository
Source code for the class will be kept in this repository.
Learn Git Branching
An excellent tutorial. If you are familiar with the Git operations clone, pull, push, add, and commit, but you are having trouble wrapping your head around branching, then this is for you.
doctest: The fastest C++ single-header testing framework
The website (on GitHub.com) for doctest, a C++ unit-testing framework used by all posted test programs in this class. doctest is simple and easy to use, it comprises only a single header file, and it is available as a free download distributed under a FLOSS license.
Introspective Sorting and Selection Algorithms [PDF]
The 1997 research paper that introduced algorithmic introspection and the Introsort algorithm. By David R. Musser, professor of computer science at the Rensselaer Polytechnic Institute.
Exception Handling: A False Sense of Security
A 1994 article on C++ exceptions from the—now defunct—C++ Report, by Tom Cargill of Bell Labs. Cargill analyzes the exception-safety characteristics of a Stack implementation from an earlier article by David Reed [“Exceptions: Pragmatic issues with a new language feature”, C++ Report, 1993]. Cargill is pessimistic about the ease and practicality of writing exception-safe code. The article does make some good points; however, it turns out that, with the interface given, it is impossible to implement a Stack in an exception-safe manner. Issues raised by this article led to a much improved understanding of exception safety in the mid-1990s, including many of the ideas we cover. (Compare the Stack interface in the article with the interface to std::stack, which was finalized in 1998—just four years later; in particular, note the difference in member function pop and the existence of member function top.)
File dictobject.c
This is the source file dictobject.c from the GitHub repository for CPython. This file contains C source code for Python’s built-in key-value Hash Table, which is called dict (for dictionary).
Links to supplemental readings will be posted here as they are assigned. Links to these will also be in the “Readings & Homework” column of the Course Materials section, above.
On Following Rules
A short essay that makes a good point. From kirit.com, a blog by Norwegian software developer Kirit Sælensminde.
Sorting a Million 32-bit integers in 2MB of RAM Using Python
A short article discussing the implemention of an external sort in the Python programming language. By Guido van Rossum, creator and former “Benevolent Dictator for Life” of Python. From his Neopythonic blog.