CS 311 Fall 2024: Data Structures and Algorithms


CS 311 Fall 2024
Data Structures and Algorithms

Department: Computer Science, UAF
Instructor: Glenn G. Chappell
Office: 539 Duckering
Office Hours:  11:45–12:45 MWF, 2:15–2:45 MW on fall 2024 class days,  or by appointment
E-mail: ggchappell@alaska.edu

Announcements

Course Materials

Materials are listed with the most recent at the top.

Week Class Meetings Readings & Homework Handouts & Code
See Git repository for code
Finals
Dec 9–Dec 13
  • Dec 9: Final Exam 1–3 pm in the classroom
   
Week 15
Dec 2–Dec 6
  • Dec 6: Other graph topics; course wrap-up
    Slides [PDF]
  • Dec 4: Spanning trees
    Slides [PDF]
  • Dec 2: Graph traversals
    Slides [PDF]
Week 14
Nov 25–Nov 29
  • Nov 29: No class meeting (Fall Break)
  • Nov 27: No class meeting (Fall Break)
  • Nov 25: The rest of the course; external data; introduction to graphs
    Slides [PDF]
   
Week 13
Nov 18–Nov 22
  • Nov 22: Thoughts on Assignment 8; Tables in the C++ STL & elsewhere
    Slides [PDF]
  • Nov 20: Hash Tables (cont’d); Prefix Trees
    Slides [PDF]
  • Nov 18: Hash Tables
    Slides [PDF]
  • reverser_test.cpp [C++ source] SKELETON
    Tests for class Reverser
    For Assignment 8, Exercise B
    Uses the “doctest” unit-testing framework, version 2
    Requires doctest.h, reverser.hpp
  • reverser.hpp [C++ header]
    Header for class Reverser
    There is no associated source file.
    For Assignment 8, Exercise B
  • wordcount_test.txt [ASCII text file]
    Test input file for Assignment 8, Exercise A
    This file is also in the Git repository.
  • hash_function.cpp [C++ source]
    Demo of a typical hash function for integers
Week 12
Nov 11–Nov 15
  • Nov 15: 2-3 Trees (cont’d); other self-balancing search trees
    Slides [PDF]
  • Nov 13: 2-3 Trees
    Slides [PDF]
  • Nov 11: Thoughts on Assignment 7; Binary Heap Algorithms (cont’d); Heaps & Priority Queues in the C++ STL
    Slides [PDF]
  • introsort.cpp [C++ source]
    Introsort
    Requires heap_algs.hpp
    Based on quicksort2.cpp
  • pq.cpp [C++ source]
    Priority Queues & custom comparisons
  • heap_sort.cpp [C++ source]
    Heap Sort
    Requires heap_algs.hpp
  • treesort_test.cpp [C++ source]
    Test program for function template treesort
    For Assignment 7, Exercise A
    Uses the “doctest” unit-testing framework, version 2
    Requires doctest.h, treesort.hpp
  • treesort.hpp [C++ header] SKELETON
    Header for function template treesort
    There is no associated source file.
Week 11
Nov 4–Nov 8
  • Nov 8: Priority Queues; Binary Heap Algorithms
    Slides [PDF]
  • Nov 6: Binary Search Trees (cont’d); unit overview—Tables & Priority Queues; introduction to Tables
    Slides [PDF]
  • Nov 4: Binary Trees; Binary Search Trees
    Slides [PDF]
  • heap_algs.hpp [C++ header]
    Header for Heap algorithms
    There is no associated source file.
  • heap_algs_main.cpp [C++ source]
    Simple main program for Heap algorithms
    Requires heap_algs.hpp
Week 10
Oct 28–Nov 1
  • Nov 1: Thoughts on Assignment 6; Queues; unit overview—the basics of trees; introduction to trees
    Slides [PDF]
  • Oct 30: Stacks
    Slides [PDF]
  • Oct 28: More on Linked Lists (cont’d); Sequences in the C++ STL
    Slides [PDF]
  • da6_test.cpp [C++ source]
    Test program for Assignment 6 templates
    For Assignment 6, Exercises A, B
    Uses the “doctest” unit-testing framework, version 2
    Requires doctest.h, da6.hpp
  • fibo_bf_elim.cpp [C++ source]
  • rpncalc.cpp [C++ source]
    Entering & evaluating Reverse Polish Notation
    Requires rpneval.hpp/.cpp
  • rpneval.hpp [C++ header]
    Header for rpnEval: Reverse Polish Notation evaluation
    Example application of a Stack
  • rpneval.cpp [C++ source]
    Source for rpnEval: Reverse Polish Notation evaluation
    Example application of a Stack
Week 9
Oct 21–Oct 25
  • Oct 25: Node-based structures; more on Linked Lists
    Slides [PDF]
  • Oct 23: Allocation & efficiency; generic containers; thoughts on Assignment 5
    Slides [PDF]
  • Oct 21: [Class held via Zoom] Exception safety (cont’d)
    Slides [PDF]
  • use_list2.cpp [C++ source]
    Singly Linked List example using smart pointers: create & find size
    Based on use_list.cpp
    Requires llnode2.hpp
  • llnode2.hpp [C++ header]
    Header for struct LLNode2
    Singly Linked List node
    Based on llnode.hpp
    There is no associated source file.
  • gfsarray_test.cpp [C++ source]
    Test program for class template GFSArray
    For Assignment 5, Exercise A
    Uses the “doctest” unit-testing framework, version 2
    Requires doctest.h, gfsarray.hpp
  • fsarray_main2.cpp [C++ source]
    Simple program using class FSArray
    Avoids resizing, swap, and assignment
    Requires fsarray.hpp, fsarray.cpp
Week 8
Oct 14–Oct 18
  • Oct 18: Exception safety
    Slides [PDF]
  • Oct 16: Basic array implementation
    Slides [PDF]
  • Oct 14: Where are we?; data abstraction; introduction to Sequences; interface for a smart array
    Slides [PDF]
  • Online Quiz 8—on Canvas
    Due 5 pm Sun, Oct 20
  • fsarray.hpp [C++ header] HAND-OFF
    Header for class FSArray
    Frightfully smart array of int
    Preliminary to Assignment 5
  • fsarray.cpp [C++ source] HAND-OFF
    Source for class FSArray
    Frightfully smart array of int
    Preliminary to Assignment 5
  • fsarray_main.cpp [C++ source]
    Check whether FSArray package compiles
    Requires fsarray.hpp, fsarray.cpp
Week 7
Oct 7–Oct 11
  • Oct 11: Midterm Exam
  • Oct 9: Non-comparison sorts; sorting in the C++ STL
    Slides [PDF]
  • Oct 7: Comparison sorts III (cont’d)
    Slides [PDF]
  • Online Quiz 7—on Canvas
    Due 5 pm Sun, Oct 13
  • comparison.cpp [C++ source]
    Passing comparisons to STL sorts
    Also demonstrates use of lambdas
  • radix_sort.cpp [C++ source]
    Radix Sort for integers with specified number of digits
  • pigeonhole_sort.cpp [C++ source]
    Pigeonhole Sort for small-ish integers
  • In-Class Worksheet 2: The Master Theorem—Solutions [PDF]
    Worksheet distributed in class Mon, Oct 7
  • In-Class Worksheet 2: The Master Theorem [PDF]
    Worksheet distributed in class Mon, Oct 7
  • quicksort2.cpp [C++ source]
    Quicksort
    Implementation #2: optimized
Week 6
Sep 30–Oct 4
  • Oct 4: The limits of sorting; comparison sorts III
    Slides [PDF]
  • Oct 2: Asymptotic notation; divide and conquer; comparison sorts II
    Slides [PDF]
  • Sep 30: Introduction to sorting; comparison sorts I
    Slides [PDF]
  • Online Quiz 6—on Canvas
    Due 5 pm Sun, Oct 6
Week 5
Sep 23–Sep 27
  • Sep 27: Thoughts on Assignment 4; analysis of algorithms
    Slides [PDF]
  • Sep 25: Recursive backtracking; unit overview—algorithmic effiency & sorting
    Slides [PDF]
  • Sep 23: Search algorithms II; eliminating recursion; search in the C++ STL
    Slides [PDF]
  • holeydtcount_test.cpp [C++ source]
    Test program for function holeyDTCount
    For Assignment 4, Exercise A
    Uses the “doctest” unit-testing framework, version 2
    Requires doctest.h, holeydtcount.hpp, holeydtcount.cpp
  • important.py [Python 3 source]
    Print the sum from Analysis of Algorithms slides
    Illustrates the most important part of a formula
  • nqueen_count.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: single tail-recursive call
  • seqsearch_compare.cpp [C++ source]
    Compare Sequential Search with Binary Search
    Uses Binary Search implementation from binsearch2.cpp
Week 4
Sep 16–Sep 20
  • Sep 20: Thoughts on Assignment 3; recursion vs. iteration
    Slides [PDF]
  • Sep 18: Search algorithms I
    Slides [PDF]
  • Sep 16: Unit overview—recursion & searching; arrays & Linked Lists; introduction to recursion
    Slides [PDF]
  • fibo_fast.py [Python 3 source]
    Computing Fibonacci numbers
    Fast method
  • fibo_formula.cpp [C++ source]
    Computing Fibonacci numbers
    Formula implementation
  • fibo_memo.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
  • binsearch2_list.cpp [C++ source]
    Binary Search
    Based on binsearch2.cpp
    Same Binary Search funcgtion, but called on std::list, not std::vector
  • da3_test.cpp [C++ source]
    Test program for Assignment 3 functions & templates
    For Assignment 3, Exercises A, B, C, D
    Uses the “doctest” unit-testing framework, version 2
    Requires doctest.h, da3.hpp, da3.cpp
  • da3.hpp [C++ header] SKELETON
    Header for Assignment 3 functions
    For Assignment 3, Exercises A–D
  • da3.cpp [C++ source] SKELETON
    Source for Assignment 3 functions
    For Assignment 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.hpp
  • llnode.hpp [C++ header]
    Header for struct LLNode
    Singly Linked List node
    There is no associated source file.
  • range.py [Python 3 source]
    Example of a range specification in Python
Week 3
Sep 9–Sep 13
  • Sep 13: Thoughts on Assignment 2; error handling; using exceptions
    Slides [PDF]
  • Sep 11: Containers & iterators (cont’d); Software engineering concepts: invariants; invisible functions II
    Slides [PDF]
  • Sep 9: Managing resources in a class (cont’d); containers & iterators
    Slides [PDF]
  • allocate2_raii.cpp [C++ source]
    Out-of-memory handling using exceptions, with RAII classes
  • allocate2.cpp [C++ source]
    Out-of-memory handling using exceptions
  • msarray_test.cpp [C++ source]
    Test program for class template MSArray
    For Assignment 2, Exercise A
    Uses the “doctest” unit-testing framework, version 2
    Requires doctest.h, msarray.hpp
  • iterators.cpp [C++ source]
    Iterator & STL demo
Week 2
Sep 2–Sep 6
  • Sep 6: Parameter Passing II; invisible functions I; managing resources in a class
    Slides [PDF]
  • Sep 4: Example class (cont’d); software engineering concepts: testing; thoughts on Assignment 1
    Slides [PDF]
  • Sep 2: No class meeting (Labor Day)
  • intarray.hpp [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 program using class IntArray
    Requires intarray.hpp
  • invisible.cpp [C++ source]
    Demo of invisible functions
  • player_test.cpp [C++ source]
    Test program for class Player
    For Assignment 1, Exercise A
    Uses the “doctest” unit-testing framework, version 2
    Requires doctest.h, player.hpp, player.cpp
  • Coding Standards
Week 1
Aug 26–Aug 30
  • Aug 30: Example class
    Slides [PDF]
  • Aug 28: Software engineering concepts: abstraction; operator overloading; software engineering concepts: assertions
    Slides [PDF]
  • Aug 26: Course overview; unit overview—advanced C++ & software engineering concepts; expressions; parameter passing I
    Slides [PDF]
  • Online Quiz 1—on Canvas
    Due 5 pm Sun, Sep 1
  • Aug 26: Read “On Following Rules”.
    The above date is when the reading is assigned. The reading should be completed before taking Online Quiz 1, which will be posted on Friday, August 30 and due at 5 pm on Sunday, September 1.
  • timeofday.hpp [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 program using class TimeOfDay
    Requires timeofday.hpp, timeofday.cpp
  • assertion.cpp [C++ source]
    Demo of assert in C++
  • Semester Plan
    Updated Sat, Sep 14
  • Syllabus
    Distributed in class Mon, Aug 26

External links last checked 2024-12-06.
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. One hidden gem is the Useful resources page
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.
Jason Turner’s C++ Best Practices
An excellent page with recommendations on C++ development tools and their use. This is my primary source for which compiler warnings to enable—among other things.
The worst algorithm in the world?
An article about the slow Fibonacci algorithm and how it might be improved, by Robin Houston, as part of his Bosker Blog.
Introspective Sorting and Selection Algorithms [PDF] (must access from a UAF domain)
The 1997 research paper that introduced algorithmic introspection and the Introsort algorithm. By David R. Musser, professor emeritus 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.)
If You Were Lost on a Desert Island, What One ADT Would You like to Have with You? [PDF]
A little article about the versatility of the Priority Queue, by Nell B. Dale, Senior Leturer in Computer Sciences at The University of Texas at Austin.
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).
Ackermann function
This is the Wikipedia article for the Ackermann function, a function that is related to the performance of the Disjoint Set Forest data structure.
Links to supplemental readings will be posted here as they are assigned. Links to these will also be in 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. Note. This is not an assigned reading. But I considered assigning it, and it is both short and interesting.