100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4,6 TrustPilot
logo-home
Overig

2.2 Problem Solving and Programming

Beoordeling
-
Verkocht
-
Pagina's
8
Geüpload op
11-09-2024
Geschreven in
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.

Meer zien Lees minder
Instelling
Vak









Oeps! We kunnen je document nu niet laden. Probeer het nog eens of neem contact op met support.

Geschreven voor

Study Level
Publisher
Subject
Course

Documentinformatie

Geüpload op
11 september 2024
Aantal pagina's
8
Geschreven in
2023/2024
Type
Overig
Persoon
Onbekend

Onderwerpen

Voorbeeld van de inhoud

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,15
Krijg toegang tot het volledige document:

100% tevredenheidsgarantie
Direct beschikbaar na je betaling
Lees online óf als PDF
Geen vaste maandelijkse kosten

Maak kennis met de verkoper
Seller avatar
maddysunter1
5,0
(1)

Ook beschikbaar in voordeelbundel

Maak kennis met de verkoper

Seller avatar
maddysunter1
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
1
Lid sinds
1 jaar
Aantal volgers
0
Documenten
16
Laatst verkocht
5 maanden geleden

5,0

1 beoordelingen

5
1
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via Bancontact, iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo eenvoudig kan het zijn.”

Alisha Student

Veelgestelde vragen