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
Q

What is a protected access modifier?

A

Protected:

Accessible within the class and subclasses

Used to suggest the variable or method shouldn’t be accessed directly but isn’t strictly private.

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

What is an IDE?

A

Integrated development environment

-A program which provides a set of tools to make it easier for programmers to write, develop and debug code

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

Give examples of IDEs

A

Integrated development environments

IDLE
Microsoft visual studio
Eclipse
PyCharm

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

Microsoft visual studio
Eclipse
PyCharm

Are examples of:

A

Integrated development environments

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

Give common features of IDEs

A

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)

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

Why is variable watch a useful feature of an IDE when it comes to debugging?

A

-Allows you to observe how the contents of a variable change during execution of program (GOOD FOR DEBUG)

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

How does the Source code edition make programming easier in an IDE?

A

-Aims to make programming easier by using autocompletion, indentation, syntax highlightinh and automatic bracket completion

32
Q

Explain breakpoints in IDEs

A

Breakpoint
-Allows users to set a point in the program in which they want the program to stop (good for finding errors)

33
Q

What is meant by stepwise refinement?

A

Build on from a simpler problem to the overview

34
Q

Give a differences between procedures and functions

A

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
Q

When a parameter is passed by a value how is that different to when its passed by reference into a subroutine?

A

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
Q

The first stage of problem solving is….

A

Identifying whether or not a problem can be solved using computational methods

37
Q

What is meant by a problem being computable?

A

A problem that can be solved using an algorithm

38
Q

Problems can only be called computable when….

A

They can be solved within a finite, realistic amount of time

39
Q

What do problems that can be solved computationally consist of?

A

Inputs, outputs and calculations

40
Q

Once a problem is determined to be computable, what is the next stage?

A

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
Q

Once a problem has been determined to be computable and we have recognised the problem as it has been defined,

what happens next?

A

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
Q

Explain divide and conquer as a problem solving technique

A

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
Q

What is meant by ‘representational abstraction’?

A

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
Q

Using levels of abstraction allows large, complex problems to…

A

be split up into simpler components as we are removing unnecessary details to simplify problem

45
Q

What is meant by abstraction by generalisation?

A

Grouping together different sections of the problem with similar functionalities

46
Q

Prroblem solving techniques

What is backtracking?

A

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
Q

Give the name of an algorithm which uses backtracking as a problem solving technique

A

Depth first graph traversal

48
Q

What is meant by ‘data mining’?

A

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
Q

What is meant by heuristics?

A

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
Q

What is meant by performance modelling?

A

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
Q

What is meant by pipeling as a problem solving strategy?

A

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
Q

What is meant by visualisations as a problem solving strategy?

A

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
Q

Give a scenario of when performance modelling would be useful and why

A

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
Q

Give advantages of performance modelling

A

-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
Q

Give advantages of using pipelining as a programming strategy

A

-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
Q

Give disadvantages of using pipelining as a programming strategy

A

-Requires careful planning to avoid dependencies between tasks causing delays.
-Effective coordination to ensure the tasks align properly when combined.

57
Q

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

A

Graphs
Trees
Charts
Tables

58
Q

Give problem solving strategies to solve problems computationally

A

Backtracking
Data mining
Heuristics
Perfomance modelling
Pipelining
Visualisation

59
Q

Give problems that use heuristics

A

-A* algorithm (to determine shortest path)
-Travelling Salesman problem

60
Q

Give examples of algorithms which use divide and conquer

A

-Quick sort
-Merge sort
-Binary search

61
Q

What is an advantage of using divide and conquer in problem solving?

A

-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
Q

Give disadvantages of using divide and conquer algorithms

A

Often they use recursion in the conquer stage

-Can lead to stack overflow
-Recursion can be hard to trace in large programs

63
Q

What is the aim of using the top down design

A

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
Q

How would you solve a problem broken down using the top down design?

A

(because we broke down the problem we need to build up to its solution)

Start building it up from the lowest levels

65
Q

Define ‘decision’

A

A result reached after some consideration

66
Q

What is meant by concurrent processing?

A

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
Q

What is the difference between concurrent processing and parallel processing?

A

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
Q

Give advantages of concurrent processing

A

-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
Q

Give disadvantages of concurrent processing

A

-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
Q

What is meant by the base case in recursion?

A

The terminating condition which doesnt use recursion to produce an output

71
Q

Define recursion

A

When a subroutine calls itself

72
Q

What is this called in IDEs?

Allows you to monitor the effect of each individual code by executing one line at a time

73
Q

Explain variable watch in IDEs

A

Variable watch
-Allows you to observe how the contents of a variable change during execution of program (GOOD FOR DEBUG)

74
Q

Functions must return a single value

TRUE OR FALSE?

75
Q

Procedures must return a single value

TRUE OR FALSE?

A

FALSE

They can return more than a single value