Problem solving and programming Flashcards

1
Q

Give a subsection of procedural programming

A

Structured programming

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Sequence is a type of programming construct

What does it do?

A

Code is run line by line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Branching is a type of programming construct
What does it do?

A

Branching/selection

-Certain block of code is run if a SPECIFIC condition is met

(IF statements)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Iteration is a type of programming construct
What does it do?

A

Code is executed a certain number of times (countcontrolled) or while a condition is met (condition controlled)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Recursion is a programming construct

TRUE OR FALSE

A

TRUE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Give advantages of using recursion

A

-Problem can be solved with fewer lines of code
(perhaps making it less prone to errors)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is essential for recursive subroutines?

A

They need to be clearly defined so that a base case is reached after a finite number of function calls

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does a stack frame contain?

A

-Parameters
-Local variables
-Return addresses

This info allows the subroutine to return to that particular point when that subroutine call is finished

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Give disadvantages of recursion

A

-Stack overflow(call stack runs out of memory) if the base case isnt reached

-Extra function call overhead. Each recursive call involves storing the state of the function, including parameters and local variables, which consumes time and memory
-Can be hard to trace (specially when there is loads of function calls in a program) because the program’s flow involves multiple function calls.

-An iterative solution is easier to understand for humans

-Need well defined base case or could enter an infinite recursion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Recursive subroutines need to be clearly defined so that a base case is reached after a finite number of function calls

A

Can lead to stack overflow (call stack runs out of memory)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why is tail recursion good?

A

Form of recursion which is implemented in a more efficient way by not requiring additional stack frames. (so avoids stack overflow)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why are local variables considered good programming practices?

A

They have limited scope meaning they can only be accessed within the block of code they are defined in:
Ensures that subroutines are self contained so no code outside the subroutine will affect these variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the difference between local and global variables?

A

Local= limited scope= can only be accessed within the block of code they are defined in
-Require less memory as they are deleted once subroutine terminates

Global= can be accessed accross whole program
-More memory is requeired as they are deleted once whole program terminates

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

In the event of a local variable within a subroutine with the same name as a global variable, the global variable will take precedence

TRUE OR FALSE

A

FALSE

Local variable will take precendence

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Top down approach in Modular programming

A

A technique used to modularise programs

-The program is continually split into subproblems until each can be represented as an individual, selfcontained which performs a specific task

Subtasks are organised in a hierarchy from the most abstract (high-level) to the most detailed (low-level).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is modular programming?

A

A programming technique used to split large and complex programs into smaller self contained modules

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Give advantages of modular programming

A

-Makes code easier to understand
-Can divide a problem between a team as each component can be delt with individually and independently from the rest
-Once tested, components can be reused
-Easier to test (as it can be tested indepently of other components)
-Parts of program can be developed in parallel (so it takes less time for program to be delivered)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Classes can be used to create objects
What is this called?

A

Instantiation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is meant by instantiation?

A

When an object from a class is created

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

An object can also be called…

A

an instance of a class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

In OPP, how are attributes declared as private altered?

A

Using public methods

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is meant by encapsulation?

A

The process of combining attributes and methods that operate on data into a class. Protecting the integrity of data using access modifiers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is a public access modifier?

A

Public:

Accessible from anywhere (inside and outside the class).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is a private access modifier?

A

Private:

Accessible only within the class.

Used to protect data from being directly accessed or modified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is a protected access modifier?
Protected: Accessible within the class and subclasses Used to suggest the variable or method shouldn’t be accessed directly but isn’t strictly private.
26
What is an IDE?
Integrated development environment -A program which provides a set of tools to make it easier for programmers to write, develop and debug code
27
Give examples of IDEs
Integrated development environments IDLE Microsoft visual studio Eclipse PyCharm
28
Microsoft visual studio Eclipse PyCharm Are examples of:
Integrated development environments
29
Give common features of IDEs
Stepping -Allows you to monitor the effect of each individual code by executing one line at a time Variable watch -Allows you to observe how the contents of a variable change during execution of program (GOOD FOR DEBUG) Breakpoint -Allows users to set a point in the program in which they want the program to stop (good for finding errors) Source code editor -Aims to make programming easier by using autocompletion, indentation, syntax highlightinh and automatic bracket completion Debugging tools -Some provide runtime detection of errors (shows where they likely ocurred suing line numbers and higlighting)
30
Why is variable watch a useful feature of an IDE when it comes to debugging?
-Allows you to observe how the contents of a variable change during execution of program (GOOD FOR DEBUG)
31
How does the Source code edition make programming easier in an IDE?
-Aims to make programming easier by using autocompletion, indentation, syntax highlightinh and automatic bracket completion
32
Explain breakpoints in IDEs
Breakpoint -Allows users to set a point in the program in which they want the program to stop (good for finding errors)
33
What is meant by stepwise refinement?
Build on from a simpler problem to the overview
34
Give a differences between procedures and functions
Procedures CAN return a value but dont have to Functions MUST return a value Procedures can return multiple values Functions must return a single value
35
When a parameter is passed by a value how is that different to when its passed by reference into a subroutine?
Value: effectively treated as a local variable, a copy of the value is passed into the subroutine and is then deleted when the subroutine terminates -Any changes made to the variable inside the subroutine do not affect the original variable outside the subroutine Reference: Address of parameter is given to subroutine, so the value of the parameter is updated at the given address -Changes made to the variable in the subroutine affect the original variable because both refer to the same memory location.
36
The first stage of problem solving is....
Identifying whether or not a problem can be solved using computational methods
37
What is meant by a problem being computable?
A problem that can be solved using an algorithm
38
Problems can only be called computable when....
They can be solved within a finite, realistic amount of time
39
What do problems that can be solved computationally consist of?
Inputs, outputs and calculations
40
Once a problem is determined to be computable, what is the next stage?
Problem recognition Stakeholders state what they want from finished product This info is used to define ssytem requirements and problem by: Analysing strenghts and weaknesses by the way the problem is currently being solved Considering amount of data and types of data (e.g inputs, outputs) and store data involved
41
Once a problem has been determined to be computable and we have recognised the problem as it has been defined, what happens next?
Problem decomposition Problem is broken down into smaller subproblems which continues until each problem can be split into individual, selfcontained subroutines so that the problem is easier to understand
42
Explain divide and conquer as a problem solving technique
Divide: involves halving the size of the problem with every iteration Conquer: Each subproblem is solved (conquered) often requersively Merge: solutions to subproblems are recombined to form final solution
43
What is meant by 'representational abstraction'?
Removing unnecessary details to simplify a problem Often problems are reduced down to the point that preprogrammed modules and libraries can be used rather than coding from scratch
44
Using levels of abstraction allows large, complex problems to...
be split up into simpler components as we are removing unnecessary details to simplify problem
45
What is meant by abstraction by generalisation?
Grouping together different sections of the problem with similar functionalities
46
Prroblem solving techniques What is backtracking?
Often done recursively Works by visiting each path and building a solution based on the paths found to be correct If a path is found to be invalid at some point, the algorithm backtracks eg. Depthfirst algorithm uses it
47
Give the name of an algorithm which uses backtracking as a problem solving technique
Depth first graph traversal
48
What is meant by 'data mining'?
A problem solving technique used to identify patterns or outliers in large sets of data -Good for making predictions about future from previous trends -Often used in marketing (e.g you can see people's shopping habits)
49
What is meant by heuristics?
Non optimal approach to problem solving which finds an approximate solution (The solution is not perfectly accurate/complete but its good enough) -Used when the standards solution is timeconsuming or resourceintensive
50
What is meant by performance modelling?
Used to test safety critical systems -Eliminates the need for actual performance testing by providing mathematical methods to test a variety of loads on different operating systems -Used to identify potential inefficiencies or failures before implementing whole system
51
What is meant by pipeling as a problem solving strategy?
Allows projects to be delivered faster as modules are divided a into individual tasks which can then be developed in parallel Within a module/subtask, there are stages in order (e.g., planning → design → development → testing). As soon as one stage of a module is complete, the next stage begins, like an assembly line.( even if other modules are still in earlier stages) (stages of different subtasks can overlap, even if the earlier stages of some subtasks haven't been completed yet)
52
What is meant by visualisations as a problem solving strategy?
Data can be represented in a way that is easier for us to understand -This makes it possible to identify trends that were not obvious before -Data can be represented using trees, graphs, charts and tables... -Used by businesses as well as data mining
53
Give a scenario of when performance modelling would be useful and why
Airplane Because its used to test safety-critcal systems, those that would not be safe to do a real trial as it could lead to castastrophy
54
Give advantages of performance modelling
-Cheaper ( allows you to identify potential bottlenecks before further implementation) -May reduce cost of expensive physical performance testing in the early stages. (when you dont know if it will work out) -Less time consumming (Instead of running numerous physical tests/ full implementations, it provides quick insights through simulations..) -Safer (avoids the risks of damage associated with testing on real systems)
55
Give advantages of using pipelining as a programming strategy
-Speeds up project delivery by overlapping tasks instead of waiting for one to finish before starting the next. as different teams/individuals can work on separate tasks simultaneously.
56
Give disadvantages of using pipelining as a programming strategy
-Requires careful planning to avoid dependencies between tasks causing delays. -Effective coordination to ensure the tasks align properly when combined.
57
Visualisation is a problem strategy used to present data in a way that is easier to understand. Give ways in which the data can be represented
Graphs Trees Charts Tables
58
Give problem solving strategies to solve problems computationally
Backtracking Data mining Heuristics Perfomance modelling Pipelining Visualisation
59
Give problems that use heuristics
-A* algorithm (to determine shortest path) -Travelling Salesman problem
60
Give examples of algorithms which use divide and conquer
-Quick sort -Merge sort -Binary search
61
What is an advantage of using divide and conquer in problem solving?
-Breaks down a large, complex problem into smaller, manageable subproblems, making it easier to understand and solve. -Each smaller problem can be tackled independently.
62
Give disadvantages of using divide and conquer algorithms
Often they use recursion in the conquer stage -Can lead to stack overflow -Recursion can be hard to trace in large programs
63
What is the aim of using the top down design
To keep spliting problems into subproblems until each subproblem can be represented as a single and selfcontained blackbox/subroutine. Where each task can be solved separetly
64
How would you solve a problem broken down using the top down design?
(because we broke down the problem we need to build up to its solution) Start building it up from the lowest levels
65
Define 'decision'
A result reached after some consideration
66
What is meant by concurrent processing?
The process of completing more than one task at a time Each task is give a slice of processor time which makes it look like the tasks are being completed at the same time but they are actually being executed sequentially (one after the other)
67
What is the difference between concurrent processing and parallel processing?
Parallel= multiple processors complete multiple tasks at the same time Concurrent= each task is give a slice of processor time which makes it look like the tasks are being completed at the same time but they are actually being executed sequentially (one after the other)
68
Give advantages of concurrent processing
-Can perform a higher number of tasks within the given time -Less time is wasted for example when waiting for an input/user interaction as while doing this other tasks can be completed
69
Give disadvantages of concurrent processing
-Not all tasks are suited to being broken up and performed concurrently (like with parallel processing) -Added overhead of coordinating and switching between processes -Can take longer when there is a large number of tasks as processes cant be completed at once (as each task would get less time to execute (time-slicing)). -If tasks depend on one another, some may need to wait for others to complete before they can proceed.
70
What is meant by the base case in recursion?
The terminating condition which doesnt use recursion to produce an output
71
Define recursion
When a subroutine calls itself
72
What is this called in IDEs? Allows you to monitor the effect of each individual code by executing one line at a time
Stepping
73
Explain variable watch in IDEs
Variable watch -Allows you to observe how the contents of a variable change during execution of program (GOOD FOR DEBUG)
74
Functions must return a single value TRUE OR FALSE?
TRUE
75
Procedures must return a single value TRUE OR FALSE?
FALSE They can return more than a single value