CS241: Spring 2017 -- Lecture 22, Shell sort, graphical TTT

  1. Shell sort -- a generalization of bubble sort, that is *much* faster.
    1. Bubble sort - n-1 passes, each compares each pair of adjacent elements and swaps if ooo
          iterate n-1 times {
              for the ith element (i ranging from 0 to n-1-1) {
                  if (out of order (relative to the i+1th element) 
                      swap ith and ith+1th values
              }
          }
                      
    2. Or, some people write it as:
          while out of order (globally) {
              for the ith element (i ranging from 0 to n-1-1) {
                  if (out of order (relative to the i+1th element) 
                      swap ith and ith+1th values
              }
          }
                      
    3. shell sort is identical, but using a variable step size, s (instead of always 1).
          s = n/3;  // set the initial gap size
          while out of order (globally) {
              for the i ranging from 0 to n-s-1 {
                  if (out of order (relative to the i+sth element) 
                      swap ith and ith+sth values
              }
              s = s/2+1  // reduce the step size
          }
                      
  2. GUI tic tac toe (or other game)
    1. Frame:public void paint(Graphics g)
    2. invoke it with repaint()
    3. Board:
              void paint(Graphics g) {  // very much like paint(Graphics) in Conway's life
                  drawLines(g);   // g.drawLine(x1, y1, x2, y2);
                  drawPieces(g);  // g.drawString("X", x, y);
              }
    4. How to make the font bigger? new Font(...)

  3. Alternative representations for the bioinformatics table
    1. Array of ints
    2. Array of Cells (where a Cell has int value; int fromRow; int fromCol;
    3. Or... Array of Objects, where the edges are Characters (the values in the two sequences) and the middle is Cells (or Integers)