how our brains work and how it ties in to programming and arrays storage sorting algorithms etc…
Post on 23-Dec-2015
214 Views
Preview:
TRANSCRIPT
What is computing?
• Computing is about computers just as much as astronomy is about telescopes
• Computing is not just hardware etc..
• It’s a science…
Why is it called computer science?
• Just because our brains do it automatically –doesn’t mean everything else will
• We study how our brains do things…and try and replicate that in an in-animate system.
Numbers on a visual screen presented to your brain
53 32 81
Your brain contains the information (the Algorithim, if you like)To do stuff with these numbers.
You could add the numbersSort the numbers from smallest to largest.
How do we make a computer sort numbers?
53 32 81
SORT
32……53…….81
Programming codePut behind this to sort!
For instance.
Declare variables 1 2 and 3For i is 1 to 3
If 1 > 2 then move 1 to Right.Next i
Our brains do this automatically
• Much of computer science
• Is –copying the way the brain works
• Making a system –a computer –that can do what our brains do!
Algorithms in our brain (that resemble a sort program)
• At any given time, you can do a million different things,• You couldSIT STILLWALKRUNSWALLOWSINGTALKTHINK ABOUT YOUR EX BOYFRIENDTHINK OF A PLAN TO KILL Person XEAT SOMETHING that is in your pocketCLIMB A TREE
SIT STILLWALKRUNSWALLOWSINGTALKTHINK ABOUT YOUR EX BOYFRIENDTHINK OF A PLAN TO KILL Person XEAT SOMETHING that is in your pocketCLIMB A TREE
Eating
Swallow
Taste
Chew
Spit
Chew Again
Bite
Transfer to Molars
Swallow again
Open Mouth
Close Mouth
Lift Spoon
Eating
Swallow
Taste
Chew
Spit
Chew Again
Bite
Transfer to Molars
Swallow again
Open Mouth
Close Mouth
Lift SpoonIf food looks edible
Else
If Food tastes nice
Else
Lift Spoon
Put spoon down
Put spoon down
Bite
Taste
Swallow
Spit
Eating
If food looks edible
Else
If Food tastes nice
Else
Lift Spoon
Put spoon down
Bite
Taste
Swallow
Spit
Reciting timestables
• 2 times 1 is 2• 2 times 2 is 4• And so on
HOW DOES YOUR BRAIN DO THIS?
Task: Recite your two timestable –starting at 1 and stop at 10.
Three types of loops
• WHILE LOOPS
• REPEAT UNTIL LOOPS
• FOR LOOPS
Declare i as integeri=1
While I <10 theni*2= answer
Declare i as integeri=1
Repeati * 2 = answer
Until i=10
Dim i as integerFor i = 1 to 10
i= i*2Next i
Computers (in order to even remotely resemble our brains) need
to be programmed.
• Algorithms are developed to do what we imagine is something very very simple
What are the main programming constructs?
• SequenceSequence (sequential programming) just a whole load of STATEMENTS
• Iteration (loops –While, Repeat, For)
• Selection (if statements, case statements)
Recursion –a very complex type of functionThat calls itself
What are loops –how do they work
• All loops have a start stop
• i.e they all have a STOPPING CONDITION..
• Otherwise they would go on forever!
RecursionModule Module1 Dim a As Integer = 3 Dim b As Integer = 3
Sub Main() add(a, b) Console.ReadLine() End Sub
Function add(ByVal a, ByVal b) If a = 0 Then Return b Else add = (a - 1) + (b + 1) Console.WriteLine(add) End If End Function
End Module
Recursion
Function (x)If x = 1Return 1 elseFunction = x - Function (x-1)
x=3
What is the value returned by Function?
And what’s an Array?
• What is a variable?
• A variable is like a like a space you need to declare –so that the computer knows to set aside a block of space to store something that it may need to compute
What is the answer of the addition of those two numbers?
= Number 3
100Your brain stored the number 100 somewhere!
In a computer we call this storage the use of a VARIABLE
Say you had a whole load of numbers
• 1• 2• 3• 4• 5• 6• 7• 8• 9
Instead of setting aside 9 blocks of space in Your head for these numbers you might set aside
1 BLOCK OF SPACE and call it “counting up”
That way…whenever anyone said COUNTING UP
You’d remember to count up from 1 to 9…and you#dRemember the 9 numbers
THIS IS CALLED AN ARRAY
(lots of variables)
top related