450 likes | 747 Vues
Computer Science 101 Survey of Computer Science. What is computer science?. Course Goals. Provide broad view of the field of computer science for purposes of general education. further study of computer science. Computer Science - NOT. JUST. The study of computers.
E N D
Computer Science 101Survey of Computer Science What is computer science?
Course Goals • Provide broad view of the field of computer science for purposes of • general education. • further study of computer science.
Computer Science - NOT JUST • The study of computers. • The study of computer programming. • The study of computer applications.
Algorithm (informal) Algorithm: A step by step procedure for solving a general class of problems. Algorithm: What Bill Clinton plays on his saxophone.
Programming 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 times Step 4. Enter the channel number and press CHAN Step 5. Enter time to start and press TIME-START Step 6. Enter time to stop and press TIME-FINISH Step 7. If no more programs, press END-PROG Step 8. Press TIMER
Algorithms on Youtube • Tying a Windsor Knot • Algorithm March with Prisoners • Sheldon’s Friendship Algorithm • Bubble Sort Algorithm • Quicksort Algorithm • Heap Sort Algorithm
Sort Algorithm Demo • Use lab software for demo • Want to be president or work for Google?
Adding m-digit numbers 478 a2 a1 a0 + 614 +b2 b1 b0 1092 c3 c2 c1 c0
Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i < m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm c(m-1) … c0 Step 10. Stop
a2 a1 a0 b2 b1 b0 carry 4 7 8 6 1 4 c3 c2 c1 c0 i m 3 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 c3 c2 c1 c0 i m 3 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop carry 0
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 c3 c2 c1 c0 i m 3 0 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop carry 0
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 c3 c2 c1 c0 i m 3 0 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop carry 0
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 0 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 12 carry 0
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 0 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 12 carry 0
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 0 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 2 carry 0
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 0 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 2 carry 1
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 1 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 2 carry 1
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 1 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 2 carry 1
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 1 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 2 carry 1
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 1 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 9 2 carry 1
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 1 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 9 2 carry 1
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 1 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 9 2 carry 1
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 1 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 9 2 carry 0
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 2 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 9 2 carry 0
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 2 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 9 2 carry 0
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 2 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 9 2 carry 0
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 2 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 10 9 2 carry 0
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 2 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 10 9 2 carry 0
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 2 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 0 9 2 carry 0
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 2 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 0 9 2 carry 1
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 3 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 0 9 2 carry 1
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 3 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 0 9 2 carry 1
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 3 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 0 9 2 carry 1
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 3 Output: Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 1 0 9 2 carry 1 1 0 9 2
a2 a1 a0 b2 b1 b0 4 7 8 6 1 4 i m 3 3 Output: 1 0 9 2 Adding m-digit numbers Step 1. Set carry to 0 Step 2. Set i to 0 Step 3. While i<m do Step 4. Set ci to ai + bi + carry Step 5. If ci ≥ 10 then Set ci to ci - 10 Set carry to 1 else Set carry to 0 Step 6. Set i to i + 1 Step 7. End-of-loop Step 8. Set cm to carry Step 9. Print cm … c0 Step 10. Stop c3 c2 c1 c0 1 0 9 2 carry 1
Three major control constructs of algorithms(Execution flow of instructions) • Sequential: Simply do steps one after the other in order they are listed. • Conditional: Decide which statement to do next based on some true/false test. • Iterative: A set of statements is repeated over and over until some condition is met.
Algorithm (formal) A well-ordered collection of unambiguous and effectively computable operations that when executed produces a result and halts in a finite amount of time.
Algorithm • Well-ordered: There is a clear order in which to do the operations. • Unambiguous: Each operation is clearly understood by all intended computing agents. • Effectively computable: The computing agent has ability to carry out each operation. • Finite time: Each operation takes finite time and there will be a finite number of steps.
Algorithms – Formal, mathematical properties • How will algorithm perform on big data sets? • Which algorithm is better for the task? • Is the algorithm correct? • Is there a feasible algorithm for the task? • Is it possible to have algorithm for the task? • Do we need an approximation algorithm?
Hardware Realizations • How do we build machines that can execute algorithms? • How do we store the data in hardware? • How do we store the instructions in hardware? • Smaller and faster? • Networks, wireless, etc. • Robots?
Linguistic realizations • Language that machine understands • Language that is understandable to humans • Translation from one to the other • Languages that are good for certain kinds of tasks – scientific computing, business computing, artificial intelligence, etc.
Applications • Intelligent robots • Web applications, E-commerce • Medical imaging • Social networking
That's not a rattler, what kinda snake is that?