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×1015 (90 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:
- Formal and Mathematical Properties: Studying the behavior of algorithms to determine if they are correct and efficient.
- Hardware Realizations: Designing and building computer systems that are able to execute algorithms.
- Linguistic Realizations: Designing programming languages and translating algorithms into these languages for hardware execution.
- 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 1920s to 1940s, 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 63000000 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.
- 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 1, Step 2, and so on.
Building Blocks: Three Categories of Operations
- 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 x to 1."
- Conditional Operations: "Question-asking" instructions. A question is asked, and the next operation is selected based on the answer.
- Example: "If x is not equal to 0, then set y equal to x1; otherwise, print an error message."
- 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 1: Wet hair.
- Step 2: Lather.
- Step 3: Rinse.
- Step 4: Repeat.
- Issue: At Step 4, the "Repeat" instruction is ambiguous. Does it go to Step 1, Step 2, or Step 3? It also lacks a termination condition, leading to an infinite process.
- Correction for Ambiguity:
- Precise sequencing: "Go back to Step 3 and continue execution from that point."
- Precise stopping: "If you are 18 years of age or older, do Part 1… otherwise, do Part 2."
- Pie Algorithm Example:
- Step 1: Make the crust.
- Step 2: Make the cherry filling.
- Step 3: Pour the filling into the crust.
- Step 4: Bake at 350 degrees F for 45 minutes.
Historical Context and Etymology
- The Word "Algorithm": Derived from the last name of Abu Ja'far Muhammad ibn Musa Al-Khwarizmi (AD780–850?), a Persian mathematician.
- He taught at the House of Wisdom in Baghdad.
- Author of Kitab al jabr w’al muqabala (AD820), the origin of the word "algebra" (al jabr means "reduction").
- In AD825, he wrote about the base-10 positional numbering system from India. His name was Latinized to "Algoritmi," and his formalized procedures became known as algorithms.
- Euclid's Algorithm: A 2300-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 1930s; 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 40 legal moves from any position and a game lasting 30 moves.
- Total board positions: 40×40×⋯×40=4030≈1048.
- A supercomputer evaluating 1015 positions per second would take 300000000000000000000000000 years to make the first move.
The Grade-School Addition Algorithm
- Input: m≥1 and two positive numbers with m digits: am−1am−2…a0 and bm−1bm−2…b0.
- Goal: Find cmcm−1cm−2…c0.
- Formal Steps:
- Set the value of carry to 0.
- Set the value of i to 0.
- While the value of i is less than or equal to m−1, repeat steps 4 through 6.
- Add digits ai and bi to the current carry to get ci.
- If ci≥10, reset ci to (ci−10) and set carry to 1; otherwise, set carry to 0.
- Add 1 to i.
- Set cm to the value of carry.
- Print result and stop.
- Trace Example (47+25):
- m=2, a1=4,a0=7,b1=2,b0=5.
- Iteration 1 (i=0): 7+5+0=12. c0=2, carry=1, i=1.
- Iteration 2 (i=1): 4+2+1=7. c1=7, carry=0, i=2.
- Final: c2=0. Result: 072.
History of the Computer Science Discipline
- Foundational Theoretical Work: 1930s.
- First General-Purpose Electronic Computers: 1940–1946.
- Association for Computing Machinery (ACM): Established in 1947. It is the world's largest professional computer science society with over 100000 members.
- UNIVAC I: First commercial machine, appeared in March 1951, marking the start of the computer industry.
- FORTRAN: First high-level programming language, debuted in 1957.
- Purdue University: Established the first Department of Computer Science in October 1962. Awarded first M.Sc. in 1964 and first Ph.D. in 1966. Undergraduate program started in 1967.
- Age of Discipline: Somewhere between 50 and 80 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., 20010).
- CURRVAL: Returns the current value of the sequence in the current session.
- Example: After creating an invoice with
INV_NUMBER_SEQ.NEXTVAL (yielding invoice 4010), CURRVAL is used to insert associated line items for the same invoice number.
- SQL Operations Trace:
INSERT INTO CUSTOMER generates CUS_CODE 20010.INSERT INTO INVOICE generates INV_NUMBER 4010.- Multiple
INSERT INTO LINE commands use INV_NUMBER_SEQ.CURRVAL to link items to INV_NUMBER 4010. COMMIT finalize the transaction.