Exam 03. 

(a) Have you taken C211? / Have you instead taken C200?

(b) Explain how  C200/C211 prepared you (or not) for this class. 

 1. Data Representation 
 2. Give examples 
 3. Code: signature, purpose statement 
 4. Examples of I/O 
 5. Template for your code
 6. Flesh out the code
 7. Test it

Let's start from our data. 

In Computer Science we have five basic data models:

  (a) list data model
  (b) set data model
  (c) tree data model
  (d) relational data model
  (e) graph data model 

Minute paper: 

(a) name
 
(b) C200/C211 

    (a) Have you taken C211? / Have you instead taken C200?
    (b) Explain how  C200/C211 prepared you (or not) for this class. 

(c) picture of graph 

    (a) sketch the data structure
    (b) start in A produce the depth-first and breadth-first traversals 

https://www.cs.indiana.edu/classes/c211-dgerman/sum2016/queens/hobokennj.jpg

A graph is a collection of vertices and edges. 

http://silo.cs.indiana.edu:8346/c212/milestones/backmatter.jpg

public class Vertex {
  String name; 
  public Vertex(String name) {
    this.name = name; 
  }
  public String toString() {
    return this.name; 
  }
}

--

import java.util.*; 

public class Neighbors extends ArrayList<Vertex> {
  public Neighbors (Vertex[] n) {
    for (Vertex v : n)
      this.add(v); 
  }
}

--

import java.util.*;

public class Graph extends HashMap<Vertex, Neighbors> { //  ArrayList<Vertex>{
  public void show() {
    for (Vertex v : this.keySet()) {
      System.out.println( v + ": " + this.get(v) );  
    }
    System.out.println("------------"); 
  }
}

--

public class Example {
  public static void main(String[] args) {
    Graph a = new Graph(); 
    Vertex A = new Vertex("A"); 
    Vertex B = new Vertex("B"); 
    Vertex C = new Vertex("C"); 
    Vertex D = new Vertex("D"); 
    Vertex E = new Vertex("E"); 
    Vertex F = new Vertex("F"); 
    Vertex G = new Vertex("G"); 
    Vertex H = new Vertex("H"); 
    Vertex I = new Vertex("I"); 
    Vertex[] b = new Vertex[] { B, C, D }; 
    a.put(A, new Neighbors(b)); 
    a.show(); 
    a.put(B, new Neighbors( new Vertex[] { A, E } )); 
    a.put(C, new Neighbors( new Vertex[] { A, H } )); 
    a.put(D, new Neighbors( new Vertex[] { A, F } )); 
    a.show(); 
    a.put(E, new Neighbors( new Vertex[] { B, I } )); 
    a.put(F, new Neighbors( new Vertex[] { D, G } )); 
    a.put(G, new Neighbors( new Vertex[] { I, F } )); 
    a.put(H, new Neighbors( new Vertex[] { C    } )); 
    a.put(I, new Neighbors( new Vertex[] { E, G } )); 
    a.show(); 
  }
}

--

Things to add: weights, code, sorted show.