Computer Science Computer Science 101101
Survey of Computer Survey of Computer ScienceScience
What is computer science?What is computer science?
Course GoalsCourse Goals
Provide broad view of the field of Provide broad view of the field of computer science for purposes of computer science for purposes of
– general education. general education.
– further study of computer science.further study of computer science.
Computer Science - NOTComputer Science - NOT
The study of computers.The study of computers.
The study of computer The study of computer programming.programming.
The study of computer applications.The study of computer applications.
JUST
Algorithm Algorithm (informal)(informal)
Algorithm:
A step by step procedure for solving a generalclass of problems.
Algorithm:
What Bill Clinton plays on his saxophone.
Programming VCRProgramming VCR
Step 1. If the clock and calendar are not correctly set, then go to page 9 of the owner's manual and follow instructions there.
Step 2. Place a blank tape in the VCR tape slot.Step 3. Repeat steps 4-7 for each program, up to 10 timesStep 4. Enter the channel number and press CHANStep 5. Enter time to start and press TIME-STARTStep 6. Enter time to stop and press TIME-FINISHStep 7. If no more programs, press END-PROGStep 8. Press TIMER
Algorithms on YoutubeAlgorithms on Youtube Tying a Windsor KnotTying a Windsor Knot
Algorithm March with PrisonersAlgorithm March with Prisoners
Sheldon’s Friendship AlgorithmSheldon’s Friendship Algorithm
Bubble Sort AlgorithmBubble Sort Algorithm
Quicksort AlgorithmQuicksort Algorithm
Heap Sort AlgorithmHeap Sort Algorithm
Sort Algorithm DemoSort Algorithm Demo
Use lab software for demoUse lab software for demo
Want to be president or work for Want to be president or work for Google?Google?
Adding m-digit numbersAdding m-digit numbers
478 a2 a1 a0 + 614 +b2 b1 b0
1092 c3 c2 c1 c0
Adding m-digit numbersAdding m-digit numbers
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i < m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm c(m-1) … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersStep 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
a2 a1 a0 4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0
carry
i
Output:
3m
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0
carry 0
i
Output:
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
3m
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0
carry 0
i
0
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0
carry 0
i
0
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 12
carry 0
i
0
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 12
carry 0
i
0
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 2
carry 0
i
0
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 2
carry 1
i
0
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 2
carry 1
i
1
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 2
carry 1
i
1
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 2
carry 1
i
1
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 9 2
carry 1
i
1
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 9 2
carry 1
i
1
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 9 2
carry 1
i
1
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 9 2
carry 0
i
1
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 9 2
carry 0
i
2
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 9 2
carry 0
i
2
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 9 2
carry 0
i
2
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 10 9 2
carry 0
i
2
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 10 9 2
carry 0
i
2
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 0 9 2
carry 0
i
2
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 0 9 2
carry 1
i
2
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 0 9 2
carry 1
i
3
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 0 9 2
carry 1
i
3
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 0 9 2
carry 1
i
3
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 1 0 9 2
carry 1
1 0 9 2
i
3
Output:
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Adding m-digit numbersAdding m-digit numbersa2 a1 a0
4 7 8
b2 b1 b0 6 1 4
c3 c2 c1 c0 1 0 9 2
carry 1
i
3
Output: 1 0 9 2
3m
Step 1. Set carry to 0Step 2. Set i to 0Step 3. While i<m doStep 4. Set ci to ai + bi + carryStep 5. If ci ≥ 10 then
Set ci to ci - 10Set carry to 1
else Set carry to 0
Step 6. Set i to i + 1Step 7. End-of-loopStep 8. Set cm to carryStep 9. Print cm … c0Step 10. Stop
Three major control Three major control constructs constructs
of algorithmsof algorithms(Execution flow of instructions)(Execution flow of instructions)
Sequential:Sequential: Simply do steps one after Simply do steps one after the other in order they are listed.the other in order they are listed.
Conditional:Conditional: Decide which statement Decide which statement to do next based on some true/false to do next based on some true/false test.test.
Iterative:Iterative: A set of statements is A set of statements is repeated over and over until some repeated over and over until some condition is met.condition is met.
Algorithm Algorithm (formal)(formal)
A well-ordered collection of unambiguous A well-ordered collection of unambiguous and effectively computable operations and effectively computable operations that when executed produces a result that when executed produces a result and halts in a finite amount of time.and halts in a finite amount of time.
AlgorithmAlgorithm Well-orderedWell-ordered: There is a clear order : There is a clear order
in which to do the operations.in which to do the operations. UnambiguousUnambiguous: Each operation is : Each operation is
clearly understood by all intended clearly understood by all intended computing agents.computing agents.
Effectively computableEffectively computable: The : The computing agent has ability to carry computing agent has ability to carry out each operation.out each operation.
Finite timeFinite time: Each operation takes : Each operation takes finite time and there will be a finite finite time and there will be a finite number of steps.number of steps.
Computer ScienceComputer Science
F orm a l a ndm a th e m a tica l
p rope r ties
H ard w a rere a liza tions
L ing u is ticre a liza tions
A p p lica tio ns
A lgo ri thm s
Algorithms – Formal, mathematical Algorithms – Formal, mathematical propertiesproperties
How will algorithm perform on big data How will algorithm perform on big data sets?sets?
Which algorithm is better for the task?Which algorithm is better for the task? Is the algorithm correct?Is the algorithm correct? Is there a feasible algorithm for the task?Is there a feasible algorithm for the task? Is it possible to have algorithm for the Is it possible to have algorithm for the
task?task? Do we need an approximation algorithm?Do we need an approximation algorithm?
Hardware RealizationsHardware Realizations
How do we build machines that can How do we build machines that can execute algorithms?execute algorithms?
How do we store the data in hardware?How do we store the data in hardware? How do we store the instructions in How do we store the instructions in
hardware?hardware? Smaller and faster?Smaller and faster? Networks, wireless, etc.Networks, wireless, etc. Robots?Robots?
Linguistic realizationsLinguistic realizations
Language that machine understandsLanguage that machine understands Language that is understandable to Language that is understandable to
humanshumans Translation from one to the otherTranslation from one to the other Languages that are good for certain Languages that are good for certain
kinds of tasks – scientific computing, kinds of tasks – scientific computing, business computing, artificial business computing, artificial intelligence, etc.intelligence, etc.
ApplicationsApplications
Intelligent robotsIntelligent robots
Web applications, E-commerceWeb applications, E-commerce
Medical imagingMedical imaging
Social networkingSocial networking