100% de satisfacción garantizada Inmediatamente disponible después del pago Tanto en línea como en PDF No estas atado a nada 4,6 TrustPilot
logo-home
Otro

2.2 Problem Solving and Programming

Puntuación
-
Vendido
-
Páginas
8
Subido en
11-09-2024
Escrito en
2023/2024

This is the topic: 2.2 Problem Solving and Programming for the OCR Computer Science (H446) course. I got 4 A*s in my A-Levels (Computer Science, Physics, Maths, Further Maths) , so they are very detailed and cover all of the specification for this topic.

Mostrar más Leer menos
Institución
Grado









Ups! No podemos cargar tu documento ahora. Inténtalo de nuevo o contacta con soporte.

Escuela, estudio y materia

Nivel de Estudio
Editores
Tema
Curso

Información del documento

Subido en
11 de septiembre de 2024
Número de páginas
8
Escrito en
2023/2024
Tipo
Otro
Personaje
Desconocido

Temas

Vista previa del contenido

2.2 Problem Solving and Programming


2.2.1 Programming Techniques

Programming Constructs:

Casting is when you convert one data type to another data type. To convert to a real, we use float().

String concatenation is when strings are joined together.

MOD gives remainder, DIV gives whole division with no remainder.

Programming Constructs: These determine the order in which lines of code are executed.

 Sequencing = Lines of code are run one line at a time, in the order they are written.
 Selection/branching = The outcome of a condition determines which lines of code run next.
 Iteration = Repeating lines of code using a loop. It can be count controlled (repeated a fixed
number of times), or condition controller (repeated until a condition is met).

Recursion:

Recursion = When a function calls upon itself. A recursive algorithm has three features:

 The function must call itself
 A base case: A condition which stops the recursion, so it can return a final value without
further recursive calls. This prevents stack overflow errors, resulting in program crashes.
 A stopping case: this must be reachable after a finite number of times. If it doesn’t, it will call
itself indefinitely, using up excessive memory and causing the program to malfunction.

Recursion Iteration
Benefits  Concise - Can often be expressed in a  Performance – More efficient that
more concise way, especially for recursion, less memory usage
structures like trees.  Debugging – Easier to understand and
 Simple – Simply states what needs to be debug
done makes it more reusable and  Wider application – More suitable to a
maintainable wider range of problems
Drawback  Performance – Repeated function calls  Complexity – Can get very complex and
s can be CPU and memory intensive, use more lines of code than recursive
leading to slower execution alternatives
 Debugging – Recursive code can be much  Less concise – Compared to recursive
more difficult to track the state of the alternatives, making them harder to
program understand
 Limited application – Not all problems
are suited to recursive solutions




1

, Tracing a Recursive Function - Example:

We use a table:

1. When the function is called make
note of it (function call)
2. Write in what is passed to it (value)
3. When it returns a value, write what
it returns + an arrow downwards
4. Once the final call has been made,
work your way back u to get to the
final return (in this case, 29).




Global and Local Variables:

Global variable = A variable declared at the outermost level of a program. They have a global scope,
so they can be accessed or modified from any part of the
program. Uses:

 Data sharing - They allow data sharing between different
parts of the program, allowing data to be passed
between different modules easily without parameter
passing.
 Persistent storage - They retain their values throughout
the program’s execution, so they can store data that
needs to persist across function calls.
 Global configuration - They can store configuration
settings or constants relevant across the whole program.

Local variable = A variable declared within the specific scope
they’re defined in (e.g. a subroutine). They’re only accessible
within the subroutine which they are defined. Once the
execution of the subroutine ends, the local variable is
destroyed, and its memory is freed. They can’t be accessed
externally unless passed as a parameter or returned from a
function.

Two variables can share the same name if they have different
scopes.




2
$4.92
Accede al documento completo:

100% de satisfacción garantizada
Inmediatamente disponible después del pago
Tanto en línea como en PDF
No estas atado a nada

Conoce al vendedor
Seller avatar
maddysunter1
5.0
(1)

Documento también disponible en un lote

Conoce al vendedor

Seller avatar
maddysunter1
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
1
Miembro desde
1 año
Número de seguidores
0
Documentos
16
Última venta
5 meses hace

5.0

1 reseñas

5
1
4
0
3
0
2
0
1
0

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes