Analysis

Systems in Rust

Preamble

This builds off the DAG lab.

Basically, after completing the lab, implement functions to compute the height and depth of nodes.

As a bonus problem, compute the height and depth of the entire graph (optional).

Review: The BS CS

  • New for 2025, the BS CS has a lot of classes in it (16, up from 10)
  • They form a DAG (so does the BA thanks to CS-351).
  • Instead of advising separately from teaching, let’s just use advising as the application domain.
  • Here is a dot diagram of a simplified version of the degree.
    • Basically, I picked the most common class within any possible distribution.
    • So “Any Software Class” becomes CS-262: Web Development.

CoursePrerequisites CS 151:\n Intro to Programming in Python CS 151: Intro to Programming in Python CS 280:\n Human-Computer Int. CS 280: Human-Computer Int. CS 151:\n Intro to Programming in Python->CS 280:\n Human-Computer Int. CS 152:\n Data Structures CS 152: Data Structures CS 151:\n Intro to Programming in Python->CS 152:\n Data Structures DATA 351:\n Data Man. in SQL DATA 351: Data Man. in SQL CS 151:\n Intro to Programming in Python->DATA 351:\n Data Man. in SQL CS 262:\n Web Development CS 262: Web Development CS 152:\n Data Structures->CS 262:\n Web Development CS 271:\n Systems Programming CS 271: Systems Programming CS 152:\n Data Structures->CS 271:\n Systems Programming CS 351:\n Analysis of Algorithms CS 351: Analysis of Algorithms CS 152:\n Data Structures->CS 351:\n Analysis of Algorithms CS 371:\n Adv. Systems Computing CS 371: Adv. Systems Computing CS 271:\n Systems Programming->CS 371:\n Adv. Systems Computing CS 480:\n Project Development CS 480: Project Development CS 351:\n Analysis of Algorithms->CS 480:\n Project Development CS 371:\n Adv. Systems Computing->CS 480:\n Project Development CS 481:\n Project Deployment CS 481: Project Deployment CS 480:\n Project Development->CS 481:\n Project Deployment MATH 150:\n Differential Calculus with Precalculus MATH 150: Differential Calculus with Precalculus MATH 251W:\n Fndns Adv Math MATH 251W: Fndns Adv Math MATH 150:\n Differential Calculus with Precalculus->MATH 251W:\n Fndns Adv Math MATH 280:\n Math for Data Sci. MATH 280: Math for Data Sci. MATH 150:\n Differential Calculus with Precalculus->MATH 280:\n Math for Data Sci. PHYS 221:\n Intro Physics 1 PHYS 221: Intro Physics 1 MATH 150:\n Differential Calculus with Precalculus->PHYS 221:\n Intro Physics 1 MATH 251W:\n Fndns Adv Math->CS 351:\n Analysis of Algorithms MATH 352:\n Linear Algebra MATH 352: Linear Algebra MATH 251W:\n Fndns Adv Math->MATH 352:\n Linear Algebra PHYS 222:\n Intro Physics 2 PHYS 222: Intro Physics 2 PHYS 221:\n Intro Physics 1->PHYS 222:\n Intro Physics 2

  • You can see the code that made that in the source, but I also formulated it as concisely as I could manage here:

Review: Two Representations

  • Do something like this.
src/lib.rs
#[derive(Debug)]
struct Node {
    data: String,
    next: Vector<String>,
}
  • You will probably at some point want to use a dictionary or something a lot like that on this task.
  • The use of std::collections::HashMap should be basically familiar, and some helpful combinations of methods can be found on this page.
  • You certainly do not have to use a HashMap, and I had no intention of doing so until I realized I was lazy.

An Aside

  • You can probably improve your quality of life with a type alias.
type Graph = std::collections::HashMap<String, Node>;

Your task

  • Load the prerequisite edges into Rust.
    • Use std::io:stdin::lock().lines()
    • I terminated on an empty line.
  • Build a DAG out of nodes.
    • Basically, conditionally add a node.
      • Look at .or_insert_with(|| <thing you want to insert);
  • Compute the height and depth of two non-trivial nodes, I choose CS 152 and CS 371.
    • I stored the inputs in data.txt.
$ cargo run -- < data.txt
   Compiling dag v0.1.0 (/home/user/tmp/dag)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.25s
     Running `target/debug/dag`
[src/main.rs:61:13] depth(String::from("C152"), &graph) = 1
[src/main.rs:62:13] depth(String::from("C371"), &graph) = 3
[src/main.rs:63:13] height(String::from("C152"), &graph) = 4
[src/main.rs:64:13] height(String::from("C371"), &graph) = 2