150 likes | 291 Views
CSCI 1001. overview of. computer science. ALGORITHMS. what is computer science?. Computer Science. The study of algorithms , including Formal and mathematical properties Hardware realizations Software realizations Applications. Algorithm. A sequence of steps that will always produce
E N D
CSCI 1001 overview of computer science ALGORITHMS
what is computer science?
Computer Science The study of algorithms, including • Formal and mathematical properties • Hardware realizations • Software realizations • Applications
Algorithm A sequence of steps that will always produce the same results from the same starting point.
Sequential operations are executed by an agent one after another. set a variable to a value get input from a user print output to a user stop executing
Conditional operations decide what to do next based on the answer to a yes/no question. if (question) then: more operations if (question) then: more operations else: other operations
Iterative operations repeat a sequence of operations. Go back to a step for every value in a list: do some operations while (the answer to a question is yes): do some operations
Algorithm “A well-ordered collection of unambiguous and effectively computable operations that, when executed, produces a result and halts in a finite amount of time.”
Input:two positive integers, x and y • Output: an integer, z • set z=0 • while (x > 0): • set z = z+y • set x = x-1 • stop and output z
Input:a list of ages, {age1,age2,…,agek} Output: an integer, count • set count=0 • for every a ∈{age1,…,agek}: • if (a ≥ 21): • set count = count+1 • stop and output count
Input:two lists of friends, {alice1,…,alicek} and {bob1,…,bobm} Output: yes or no. • for every a ∈{alice1,…,alicek}: • for every b ∈ {bob1,…,bobm}: • if (a = b) then: • stop and output yes • stop and output no
when is it hard to find an algorithm?
http://cs1001.us/ Please read Chapter 4.2.1 for Monday’s lecture.