index↑
FSU Seal - 1851     COT 4401 Top 10 Algorithms
Chris Lacher
Introduction to Algorithms
  index↑

What is an Algorithm?

What is an Algorithm? - Official definition for this course

An algorithm is any clearly specified computational procedure that operates on some set of values. (Note that a set may be empty.) An algorithm should have the following attributes (which may be stated explicitly or understood implicitly):

  1. Assumptions: things that must be true before executing the algorithm
  2. Outcomes: things that are asserted to be true after executing the algorithm
  3. Proof: of the proposition "if the assumptions are true and the algorithm is executed then the outcomes are true"
  4. Runtime: the time required to execute the algorithm, usually expressed as an asymptotic estimate as a function of input size
  5. Runspace: the space required to execute the algorithm, usually expressed as an asymptotic estimate of the additional space required as a function of input size

Algorithm Analysis


Generate random integers to a file

#include <xran.cpp> // /home/courses/cop4530p/LIB/cpp

int main(int argc, char* argv[])
{
  if (argc != 5)
  {
    std::cout << " ** program requires 4 arguments\n"
              << "    1 = number of generated entries\n"
              << "    2 = min size\n"
              << "    3 = max size\n"
              << "    4 = output filename\n"
              << " ** try again\n";
    exit(0);
  }

  std::cout << "Program generating file of integers\n"
            << " ...\n";

  std::ofstream out1;
  out1.open(argv[4]);
  if (out1.fail())
  {
    std::cout << " ** Unable to open file " << argv[4] << '\n'
              << " ** program closing\n";
    exit(0);
  }

  fsu::Random_int ranint;
  size_t num = atoi(argv[1]), min = atoi(argv[2]), max = atoi(argv[3]) + 1;
  for (size_t i = 0; i < num; ++i)
  {
    out1 << ranint(min,max) << '\t';
  }

  // close outfile
  out1.close();

  // terminate program
  std::cout << "File of int constructed:\n"
            << " filename:        " << argv[4] << '\n'
            << " number of ints:  " << num << '\n'
            << " int bounds:     [" << min << ',' << max - 1 << "]\n";

  return 0;
}
  index↑