A computational model is a mathematical model in computational science that requires extensive computational resources to study the behavior of a complex system by computer simulation.
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Models of computation(Algorithm)
1. MODELS OF COMPUTATION
Submitted To:- Submitted By:-
Ms. Shano Solnaki Alpana (171401)
Astt. Professor ME Modular 2017
Computer Science & Engg. 9459942212
NITTTR Chandigarh anshubhaskar93@gmail.com
2. Contents
Computational Model
Random Access Machine
Stored program model or von Neumann model of a computer
Difference between Random access machine and Random Access
Memory
References
2
3. Computational Model
“A computational model is a mathematical model in
computational science that requires extensive computational
resources to study the behavior of a complex system by computer
simulation.
The common basis of programming language and computer
architecture is known as computational model.
Provides higher level of abstraction than the programming
language and the architecture.
Computational model is the combination of the above two.
3
4. Contd…
Algorithms are most important and durable part of computer science
because they can be studied in a language- and machine-
independent way.
This means that we need techniques that capable us to compare
the efficiency of algorithms without implementing them. Our two
most important tools are:
The RAM model of computation and,
The asymptotic analysis of worst-case complexity.
4
5. The RAM Model
Random Access Machine (not R.A. Memory)
An idealized notion of how the computer works
Each "simple" operation (+, -, =, if) takes exactly 1 step.
Each memory access takes exactly 1 step
Loops and method calls are not simple operations, but depend upon the size
of the data and the contents of the method.
Measure the run time of an algorithm by counting the number of steps.
The program for RAM is not stored in memory.
Thus we are assuming that the program does not modify itself.
5
6. A Random Access Machine (RAM) consists of:
a fixed program
an unbounded memory
a read-only input tape
a write-only output tape
Each memory register can hold an arbitrary integer (*).
Each tape cell can hold a single symbol from a finite alphabet s.
6
7. Space Complexity
The amount of memory required by an algorithm to run to
completion.
Fixed part: The size required to store certain data/variables, that is
independent of the size of the problem: Such as int a (2 bytes, float
b (4 bytes) etc
Variable part: Space needed by variables, whose size is dependent
on the size of the problem: Dynamic array a[]
7
8. Space Complexity (cont’d)
S(P) = c + S(instance characteristics)
c = constant
Example:
void float sum
(float* a, int n) {
float s = 0;
for(int i = 0; i<n; i++) {
s+ = a[i]; }
return s;
Constant Space: one for n, one for a [passed by reference!], one for
s, one for I , constant space=c=4 8
9. Running Time of Algorithms
depends on input size n
size of an array
polynomial degree
elements in a matrix
bits in the binary representation of the input vertices and edges in a
graph
number of primitive operations performed
Primitive operation
unit of operation that can be identified in the pseudo-code 9
10. Steps To determine Time Complexity
Step-1. Determine how you will measure input size.
Ex:
N items in a list N x M table (with N rows and M columns)
Two numbers of length N
Step-2. Choose the type of operation (or perhaps two operations)
Comparisons, Swaps, Copies ,Additions .
Note: Normally we don't count operations in input/output.
10
11. Steps To determine Time Complexity (Cont !!!)
Step-3. Decide whether you wish to count operations in the
Best case? - the fewest possible operations
Worst case? - the most possible operations Average case? This is
harder as it is not always clear what is meant by an "average case".
Normally calculating this case requires some higher mathematics
such as probability theory.
Step-4. For the algorithm and the chosen case (best, worst, average),
express the count as a function of the input size of the problem.
11
12. Primitive Operations in an algorithm
Assign a value to a variable (i.e. a=5)
Call a method (i.e. method())
Arithmetic operation (i.e. a*b, a-b*c)
Comparing two numbers ( i.e. a<=b, a>b &&a>c)
Indexing into an array (i.e. a[0]=5)
Following an object reference (i.e. Test obj) Returning from a
method (i.e. return I )
12
13. for Loops
The running time of a for loop is at most the running time of the
statements inside the for loop (including tests) times the number of
iterations.
Example
For(i=0;i<=n-1;i++)
A[i]=0;
Let running time of basic operations is constant C and loop is
iterated n times then Total Running time will be n*c
Note: (number of basic steps in loop body) * (number of
iterations) 13
14. Primitive Operations:
Example -1
Count the number of primitive
operations in this program :
Int method() {
i = 0;
a = 0;
for (i=1;i<=n;i++) {
printf(“%d”,i);
a=a+i;
}
return I
}
Primitive Operations Yes/No
Total Assign a value to a variable
Call a method
Arithmetic operation
Comparing two numbers
Indexing into an array
Following an object reference
Returning from a method
14
15. Primitive Operations:
Yes/No
Total Assign a value to a variable Yes 5
Call a method No
Arithmetic operation 2
Comparing two numbers 1
Indexing into an array
Following an object reference Returning from a method
15
16. RASP Machine or stored program model
Same as RAM but allow program to change itself as it is now stored
in the memory
Same power as RAM
Example Von Neumann architecture
Let RAM use memory registers to store modifiable program of
RASP
16
17. Stored program model or von Neumann model of a
computer.
Around 1944–1945, John von Neumann proposed that, since
program and data are logically the same, programs should also be
stored in the memory of a computer.
Computers built on the von Neumann model divide the computer
hardware into four subsystems: memory, arithmetic logic unit,
control unit, and input/output.
17
18. The stored program concept
The von Neumann model states that the program must be stored in
memory. This is totally different from the architecture of early
computers in which only the data was stored in memory: the
programs for their task was implemented by manipulating a set of
switches or by changing the wiring system.
The memory of modern computers hosts both a program and its
corresponding data. This implies that both the data and programs
should have the same format, because they are stored in memory. In
fact, they are stored as binary patterns in memory—a sequence of 0s
and 1s.
18
19. Sequential execution of instructions
A program in the von Neumann model is made of a finite number of
instructions.
In this model, the control unit fetches one instruction from memory,
decodes it, then executes it. In other words, the instructions are
executed one after another.
Of course, one instruction may request the control unit to jump to
some previous or following instruction, but this does not mean that
the instructions are not executed sequentially.
19
20. Sequential execution of instructions
Sequential execution of a program was the initial requirement of a
computer based on the von Neumann model.
Today’s computers execute programs in the order that is the most
efficient.
20
21. What is the difference between random access machine
and random access memory?
The Random Access Machine is a simplified model of a
modern computer used in theoretical computer science to
analyze algorithms.
Random Access Memory is the primary memory device in
which the CPU stores data in a real life computer.
21