Introduction to Computer Science and Algorithmic Foundations

Chapter 1: An Introduction to Computer Science

  • Goal: To provide an understanding of computer science and an appreciation for the diverse areas of research and study within the field.
  • Modern Advances:
    • Supercomputers performing more than 90×101590 \times 10^{15} (9090 quadrillion) mathematical operations per second.
    • Wireless networks streaming high-definition media globally.
    • Computer chips embedded in appliances, clothing, and human bodies.
    • Artificial intelligence systems responding to natural language questions faster and more accurately than humans.

Learning Objectives

  • Understand the definition of the term algorithm.
  • Understand the formal definition of computer science.
  • Write down everyday algorithms.
  • Determine if an algorithm is ambiguous or not effectively computable.
  • Understand the roots of modern computer science in mathematics and mechanical machines.
  • Summarize the key points in the historical development of modern electronic computers.

The Definition of Computer Science

  • The Gibbs and Tucker Definition: First proposed by professors Norman Gibbs and Allen Tucker, this definition states that the central concept in computer science is the algorithm. It is the task of the computer scientist to design and develop algorithms to solve important problems.
  • Operations in the Design Process:
    1. Formal and Mathematical Properties: Studying the behavior of algorithms to determine if they are correct and efficient.
    2. Hardware Realizations: Designing and building computer systems that are able to execute algorithms.
    3. Linguistic Realizations: Designing programming languages and translating algorithms into these languages for hardware execution.
    4. Applications: Identifying important problems and designing correct and efficient software packages to solve them.

Common Misconceptions About Computer Science

  • Misconception 1: Computer Science is the Study of Computers:
    • Theoretical work began in the 19201920s to 19401940s, long before physical computer systems existed.
    • Many branches study logical and mathematical properties using formal models of computation rather than circuit boards.
    • Analogy (Fellows and Parberry): Computer science is no more about computers than astronomy is about telescopes, biology is about microscopes, or chemistry is about beakers.
  • Misconception 2: Computer Science is the Study of How to Write Computer Programs:
    • Programming is a tool used to build and test solutions, but it is not the discipline itself.
    • Example: Designing a "new and improved" search technique for a database (like the Social Security Administration's 6300000063000000 active listings) involves theoretical analysis followed by empirical testing via programming to measure performance.
  • Misconception 3: Computer Science is the Study of the Uses and Applications of Computers and Software:
    • Learning to use software packages (word processors, search engines, database systems) is not computer science.
    • Analogy: Driver's education is not a branch of automotive engineering. The computer scientist specifies, designs, builds, and tests the packages that others use.

Formal Definition of an Algorithm

  • Dictionary Definition (Merriam-Webster): A procedure for solving a mathematical problem in a finite number of steps that frequently involves repetition of an operation; broadly: a step-by-step method for accomplishing some task.
  • Informal Definition: An ordered sequence of instructions that is guaranteed to solve a specific problem.
  • Formal Definition Decomposition:
    • Well-Ordered Collection: There must be a clear and unambiguous ordering to operations. The system must know which operation to do first and precisely which one to do next as each step completes.
    • Unambiguous Operations: Each operation must be clear and leave no room for confusion for the computing agent.
    • Effectively Computable Operations: The operations must be doable/computable by the agent.
  • The Computing Agent: The machine, robot, person, or thing carrying out the steps of the algorithm. It does not need to understand the underlying concepts; it merely follows Step 11, Step 22, and so on.

Building Blocks: Three Categories of Operations

  1. Sequential Operations: Carries out a single well-defined task. Once finished, the algorithm moves to the next instruction. Usually expressed as simple declarative sentences.
    • Example: "Set the value of xx to 11."
  2. Conditional Operations: "Question-asking" instructions. A question is asked, and the next operation is selected based on the answer.
    • Example: "If xx is not equal to 00, then set yy equal to 1x\frac{1}{x}; otherwise, print an error message."
  3. Iterative Operations: "Looping" instructions. They instruct the agent to go back and repeat a previous block of instructions.
    • Example: "While there are still more checks to be processed, do the following five steps."

Criteria and Ambiguity in Algorithms

  • Ambiguity Example (Shampoo Bottle):
    • Step 11: Wet hair.
    • Step 22: Lather.
    • Step 33: Rinse.
    • Step 44: Repeat.
    • Issue: At Step 44, the "Repeat" instruction is ambiguous. Does it go to Step 11, Step 22, or Step 33? It also lacks a termination condition, leading to an infinite process.
  • Correction for Ambiguity:
    • Precise sequencing: "Go back to Step 33 and continue execution from that point."
    • Precise stopping: "If you are 1818 years of age or older, do Part 11… otherwise, do Part 22."
  • Pie Algorithm Example:
    • Step 11: Make the crust.
    • Step 22: Make the cherry filling.
    • Step 33: Pour the filling into the crust.
    • Step 44: Bake at 350350 degrees F for 4545 minutes.

Historical Context and Etymology

  • The Word "Algorithm": Derived from the last name of Abu Ja'far Muhammad ibn Musa Al-Khwarizmi (AD 780AD\,780–850850?), a Persian mathematician.
    • He taught at the House of Wisdom in Baghdad.
    • Author of Kitab al jabr w’al muqabala (AD 820AD\,820), the origin of the word "algebra" (al jabr means "reduction").
    • In AD 825AD\,825, he wrote about the base-1010 positional numbering system from India. His name was Latinized to "Algoritmi," and his formalized procedures became known as algorithms.
  • Euclid's Algorithm: A 23002300-year-old procedure for finding the greatest common divisor of two positive integers.

Limitations of Algorithmic Problem Solving

  • Unsolvable Problems: Proved by Kurt Gödel in the early 19301930s; there are problems for which no generalized algorithmic solution exists.
  • Intelligence Tasks: Tasks like facial recognition, natural language understanding, and abstract reasoning are performed easily by humans but are difficult to specify algorithmically.
  • Efficiency and Brute Force: Some algorithms take too long to be useful.
    • Chess Example: A brute-force approach examining all moves.
    • Assume 4040 legal moves from any position and a game lasting 3030 moves.
    • Total board positions: 40×40×⋯×40=4030≈104840 \times 40 \times \dots \times 40 = 40^{30} \approx 10^{48}.
    • A supercomputer evaluating 101510^{15} positions per second would take 300000000000000000000000000300000000000000000000000000 years to make the first move.

The Grade-School Addition Algorithm

  • Input: m≥1m \ge 1 and two positive numbers with mm digits: am−1am−2…a0a_{m-1}a_{m-2}\dots a_0 and bm−1bm−2…b0b_{m-1}b_{m-2}\dots b_0.
  • Goal: Find cmcm−1cm−2…c0c_m c_{m-1} c_{m-2} \dots c_0.
  • Formal Steps:
    1. Set the value of carrycarry to 00.
    2. Set the value of ii to 00.
    3. While the value of ii is less than or equal to m−1m - 1, repeat steps 44 through 66.
    4. Add digits aia_i and bib_i to the current carrycarry to get cic_i.
    5. If ci≥10c_i \ge 10, reset cic_i to (ci−10c_i - 10) and set carrycarry to 11; otherwise, set carrycarry to 00.
    6. Add 11 to ii.
    7. Set cmc_m to the value of carrycarry.
    8. Print result and stop.
  • Trace Example (47+2547 + 25):
    • m=2m = 2, a1=4,a0=7,b1=2,b0=5a_1 = 4, a_0 = 7, b_1 = 2, b_0 = 5.
    • Iteration 11 (i=0i = 0): 7+5+0=127 + 5 + 0 = 12. c0=2c_0 = 2, carry=1carry = 1, i=1i = 1.
    • Iteration 22 (i=1i = 1): 4+2+1=74 + 2 + 1 = 7. c1=7c_1 = 7, carry=0carry = 0, i=2i = 2.
    • Final: c2=0c_2 = 0. Result: 072072.

History of the Computer Science Discipline

  • Foundational Theoretical Work: 19301930s.
  • First General-Purpose Electronic Computers: 19401940–19461946.
  • Association for Computing Machinery (ACM): Established in 19471947. It is the world's largest professional computer science society with over 100000100000 members.
  • UNIVAC I: First commercial machine, appeared in March 19511951, marking the start of the computer industry.
  • FORTRAN: First high-level programming language, debuted in 19571957.
  • Purdue University: Established the first Department of Computer Science in October 19621962. Awarded first M.Sc. in 19641964 and first Ph.D. in 19661966. Undergraduate program started in 19671967.
  • Age of Discipline: Somewhere between 5050 and 8080 years old.

Database Systems: Oracle Sequence Examples

  • Sequences: Used for generating unique numeric values automatically.
  • NEXTVAL: Generates and returns the next value in the sequence.
    • Example: INSERT INTO CUSTOMER VALUES (CUS_CODE_SEQ.NEXTVAL, 'Walker', 'James', ...); results in a new customer code (e.g., 2001020010).
  • CURRVAL: Returns the current value of the sequence in the current session.
    • Example: After creating an invoice with INV_NUMBER_SEQ.NEXTVAL (yielding invoice 40104010), CURRVAL is used to insert associated line items for the same invoice number.
  • SQL Operations Trace:
    1. INSERT INTO CUSTOMER generates CUS_CODE 2001020010.
    2. INSERT INTO INVOICE generates INV_NUMBER 40104010.
    3. Multiple INSERT INTO LINE commands use INV_NUMBER_SEQ.CURRVAL to link items to INV_NUMBER 40104010.
    4. COMMIT finalize the transaction.