Algorithms and Python

CS 65: Introduction to Computer Science I

Algorithms

Algorithm: a sequence of instructions to accomplish a task or solve a problem

Programs and Programming Languages

Program: a computer program is a series of instructions for the computer to execute.

An algorithm is an idea and the program is a concrete expression of that idea.

Programming Language: a set of rules that define which programs are legal

Like natural languages, programming languages have a grammar and syntax - they describe how instructions are constructed

An analogy: Music

Algorithm: "Beethoven's 5th"

Program: This arrangement

Programming Langauge: Modern sheet music notation

Components of Computer Programs

  • Basic values: 500, 3.14, ...
  • Basic operations: +, -, /, //, *, **, ...
  • Sequencing: the order instructions are carried out
  • Variables: names we give to basic values
  • Conditionals: if …. then ...
  • Repetition: do X ten times ...
  • Subroutines: helper algorithms
  • Inputs: initial values that are given to an algorithm
  • Outputs: values that are produced by the algorithm

Why Python?

  • It's a high-level programming language with simple syntax
  • It's widely used in industry - in software development, data science, and research
  • It's versatile and can be used for a variety of paradigms/styles
    • imperative programming
    • object-oriented programming
    • functional programming
  • It has an easy to use interactive shell environment
In [1]:
print("Hello world!")
Hello world!