2.2 - Problem solving and programming Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What Is an IDE? Explain.

A

Intergrated development environment.
Software enables you to enter/edit/interpret + run your programs.

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

What are the 3 things a debugging facility can do?

IDE

A
  • Set a breakpoint in a program; causes program to stop on that line.
  • Set a watch on a variable so that its value is displayed each time it changes.
  • Step through a program one line at a time.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why do you use a debugging facility?

IDE

A

Helps you find logic errors in a program.

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

What 4 features of an IDE make coding quicker & easier?

A
  • Adding line numbers.
  • Automatically indenting code.
  • Auto-completing commands.
  • Commenting/uncommenting a region.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What happens when you interpret or compile a program?

A

Syntax errors will be reported.

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

Why is your program still not running after correcting the syntax errors?

A

They may be logic errors.

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

Define an algorithm

A

A sequence of instructions that can be follwed to solve a problem.

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

What are the 3 components of an algorithm?

A
  1. Input.
  2. Process.
  3. Output.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the 4 characteristics of Pseudocode?

A
  • Writes intructions in statements that are between English + programing languages.
  • They are guidelines but no strict rules.
  • Aid thinking out steps needed before starting to code.
  • Makes coding easier.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is = used for?

(Pseudocode)

A

To assign

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

What is + - * / ** (exponentiation) used for?

(Pseudocode)

A

Used for common arithmetic.

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

What is an identifier?

A

A name that points to a memory location.

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

What is an assignment?

A

Assiging a value to the memory location

e.g.
Start
score = 0
score = score + 1
End

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

What is a statement?

A

A single instruction

Programs have a series of instructions.

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

What are the 3 advantages of pseudocode?

A
  • Don’t need to follow a specific structure or syntax of a language.
  • Easy to understand.
  • It is easy and quick to convert to a programming language.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a programming construct?

A

It controls how statements in a program are executed.

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

What are 3 constructs?

A
  • Sequence
  • Selection
  • Iteration
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is a variables?

A

It is a named container to store values which can change at any point during the program. It is held by the computer in a memory location.

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

What is a input()?

A

Used to set data into the computer program.

It is an inbuilt function.

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

What is a sequence?

A
  • line of code, one after the other.
  • Group of statements executed once in the order they appear.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is int?

A

Integer

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

What is str?

A

String.

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

What is Char?

A

Character

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

How does Selection work?

A

Programs have sets of instructions that are carried out one after another. Sometimes more than 1 path to follow. So a decision needs to be made -> this is the selection.

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

What happens in an if statement?

A
  • If this happens do this.
  • (programming syntax)
  • If statements always end in a colon :
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

When are IF & ElSE used?

A

when the answer to the question is false.

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

What are the 3 features of a constant?

A
  • You cannot assaign to a constant.
  • It reduces the risk of error.
  • Constant value has to be changed in the source code + recompiled.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What is ELIF?

A

Allows you to have 3+ option/choices.
Selection allows more than one path.

ELIF = ELSE IF

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

What is Mod?

A

It is an operator used to find the remainder of an integer.
e.g. x = 17 mod 3, x = 2

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

What is div?

A

It returns the integer part after a calulation.

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

What is a subroutine?

A

A set of instructions with a name?

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

How does a subroutine work?

A
  • program execution starts at the first statement.
  • Program flow will ‘Jump’ to the subroutine called.
  • When subroutine has finished, the program will continue from where it was called.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What is a function?

A

A subroutine that must always return 1 values.

(Can do this in a return statement).

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

What is a procedure?

A

A subroutine that doesn’t have to return a value but can return multiple.

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

What happens when a variable is in scope?

A

Values can be accessed.

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

What are module libaries?

A
  • Come with a set of pre defined subroutines.
  • Have to be imported at the start of the program.
37
Q

How is data passed to the subroutines?

A

Through arguments/paramaters that are in parentheses.

38
Q

When do Parameters appear?

A

In subroutine DEFINITIONS.

Always have commas inbetween parameters.

39
Q

When do arguments appear?

A

In subroutine CALLS.

40
Q

What does it mean for all arguments to be passed by value?

(Happens in python etc)

A
  • Actual value of the argument in calling statement in copied to the variable parameter in the subroutine. Any calculation performed on the parameter in the subroutine will not affect the value of the corresponding argument in the calling routine.
41
Q

What does it mean for that arguments can be passed by value or reference?

(Some programming languages)

A
  • The address of the argument in the calling statement is passed to the corresponding parameters in the subroutine. So any calculation perfromed on the parameter in the subroutine will change the value of the corresponding argument in the calling routine.
42
Q

Define local variables.

A
  • Subroutines own variables etc.
  • Can only be used in that subroutine & created when a name is used on the left hand side of the assignment statemnt in the sub routine.
43
Q

Define global variables.

A

Defined in main program + used in any subroutine called from the main program.

44
Q

What is the scope of local variables?

A

The subroutine in which it is declared.

45
Q

What are the advantages of local variables?

A
  • Subroutine independent of a particular program + reused in different programs.
  • No chance of accidentally changing a variable in the main program so that it is used in a subroutine or vice versa.
46
Q

What are the advantages of local variables?

A
  • Subroutine independent of a particular program + reused in different programs.
  • No chance of accidentally changing a variable in the main program so that it is used in a subroutine or vice versa.
47
Q

What is modular programming?

A
  • Breaking down major tasks into smaller subtasks.
  • Further broken down until each ‘module’ performs a single function.
48
Q

What are the advantages of modular programming?

A
  • Programs more easily + quickly written.
  • Subtasks easier to program + manage.
  • Each module can be individually tested.
  • Modules can be reused several times in a program.
  • Large programs easier to debug + maintain.
49
Q

When is a problem considered computable?

A

If an algorithm exists to solve it.

50
Q

What was the halting problem?

A
  • Developed by Alan Turing in 1936.
  • Confirms there are some problems that cannot be solved by a computer.
  • ## Showed there were more limits on algorithms than; Existing hardware, Memory size, Processor speed etc.
51
Q

What are the limits of algorithms?

A
  • May require more memory than feasible therefore unsolvable.
  • Could have exponential complexity.
52
Q

What is exponential complexity?

A
  • Problem requires an exponential amount of work to be done.
  • Using faster/more processors don’t make a difference.
53
Q

What is a tractable problem?

A

Any problem solvable in polynomial time or better.

54
Q

What is an intractable problem?

A

It cannot be solved in polynomial time or better. (Can still be solved by an algoritm but if input size increases to anything other than a small data set, it can’t be solved in a reasonable time frame).

55
Q

How can you solve a intractable problem?

A

Using heuristic methods.

56
Q

What features of tractable problems make them suitable for solving?

A
  • Enumeration.
  • Automation.
  • Simulation.
  • Decomposition.
  • Abstraction.
  • Theory/Mathematics.
57
Q

What are the features of abstraction + decomposition?

A

Simplify the complexity of a problem + break it down. Far easier to write an algorithm to solve a problem.

58
Q

What are the features of Enumeration?

A

Designing an algorithm that performs an exhaustive search and attempts all possible solutions until the correct one is found.

(Commonly used for puzzles)

59
Q

What are the features of a theoretical approach?

A
  • Easy to represent using mathematic equations if the problem can be made into pure theory.
  • As computers are great at maths they are great problems to be solved.
60
Q

What are the features of Simulation + Automation?

A
  • Process of designing a model of a real life system to attempt to understand its behaviour.
  • Automation = Building problem-solving models + putting them into action.
  • Uses alot of abstraction and turn complex problems into ones easily solved by algorithms.
61
Q

What is problem recognition?

A

The ability to define a problem and determine exactly what it is.

62
Q

What are the 5 questions to ask when solving a problem?

A
  1. Is there a problem that needs to be solved?
  2. If so, what exactly is the nature of the problem?
  3. What data do you need to acquire in order to fully understand the problem?
  4. What are the variables that could alter the current state of the problem?
  5. What processes and techniques that could solve the current problem should you take into consideration?
63
Q

What is problem decomposition?

A

The process of taking a large problem and breaking it down into several smaller problems. This happens until each section is a single task/action which can be coded as a PROCEDURE, MODULE, FUNCTION or METHOD.

64
Q

What approach should you use to break down a problem?

A

A top-down, heirachial approach.
(Harder to break down event-driven programs this way, e.g. graphical user interfaces).

65
Q

What is step-wise refinement?

A

Produces a top-down modular design so that there are small independent modules which can be written by a single person/small team. Modules can also be tested in isolation before being intergrated back into the solution.

66
Q

What is divide and conquer?

A

It reduces the size of the problem with each successive iteration.

67
Q

How does divide and conquer work?

A
  1. Take a problem - or more typically a data set.
  2. Apply some rules.
  3. Based on the outcome of the rules, discard any data that doesn’t match.
  4. Repeat the process with the data that is left.
68
Q

What is an example of divide & conquer?

A

The binary search algorithm. Because with every half you discard half of the items from the data set so that it is easier to locate a specific item.

69
Q

What is abstraction?

A

The process of seperating ideas from reality. Hiding uneasersary details and only showing the important ones to the context.

70
Q

What do you need to consider when using abstraction?

A

Consider which problems are important to the solution.

71
Q

What are examples of abstraction?

A
  • Computer Games: What makes it more realistic & recognisable? What should be left out to make it fluid & enjoyable?
  • Life simulator: Replicates aspects of normal life like building a career but leaves out unimportant parts like the journey to & from work.
72
Q

How can backtracking be used to solve a maze?

A
  1. Proceed forwards until you reach a junction.
  2. Pick a random route and follow it until you reach a dead end.
  3. Retrace your steps until you get back to the most recent junction with unvisited routes.
  4. Take a different route.
  5. Repeat the steps

(Similar to depth first graph traversal)

73
Q

What is backtracking?

A

A method used to solve a problem where you will examine more than one possible route.

74
Q

What is data mining?

A

Analysing vast amounts of data gathered from a variety of sources to discover new trends and information.

75
Q

What is big data?

A

An extreamly large data set.

76
Q

What can you do with big data?

A

Analyse it computationally using data mining techniques to reveal patterns/trends/associations especially in relation to human behaviour and interactions.

77
Q

Using the example of a supermarket what pieces of data can they gather about you?

A
  • What you purchase.
  • When you purchase.
  • How long you remain in the store.
  • How much you spend in one visit.
  • Which brands you prefer.
  • How often you visit.
  • ## Which offers you buy.
78
Q

What applications is data mining used by?

A
  • Companies -> to maximise their profits.
  • Weather modelling.
  • Business & Economics.
  • Stock Market.
  • Science & Engineering.
  • Medical Research.
  • Law Enforcement.
79
Q

What are heuristics?

A
  • Approach to problem solving where you try to find a “good enough” solution as it can be unrealistic or impractical to find the optimum solution.
  • E.g. having a high enough probability even though not 100% will be good enough.
80
Q

What is a benefit of the heuristic approach?

A

It allows many intractable problems to be solved by sacrificing the optimum answer for one that is good enough.

81
Q

What is performance modelling?

A
  • Process of approximating how models perform using mathematics.
82
Q

How do you performance model?

A

You use simulations + mathematically approximations within the simulations without having to perform detailed testing which may be prohibited due to time frame or costs.

83
Q

Example of performance modellying by a company.

A

Trying to test new high-tech, cloud based server farm at high capacity.
- May have to send millions of requests, max out its bandwidth, storage + processers to see how it deals with stress.
- But it is hard + expensive to replicate.
- Instead close monitoring of low level interactions taking place in the server and using mathematical modelling to calculate how the servers perform.

84
Q

What is pipeling?

A

Splitting a task into more manageable chunks whilst overlapping these small processes to speed up the overall process.

(Use the analogy of a robotic assembly line at a factory)

85
Q

What is an example of pipeling?

A

Executing a program in the CPU.
- 1 processor core fetches the instruction.
- Other cores do decoding and executing.

86
Q

What is visualisation?

A

Allows us to create a mental image of what a program will do or how it will work.

87
Q

How is visualisation usually done by humans?

A
  • Either use text to describe the image to a minute detail then we can picture it.
  • Or instantly see it through an image.
88
Q

How is visualisation applied to computing problems?

(E.g. Binary trees)

A

Drawing a diagram of the information in a table describing a binary tree makes it easier to understand the structure.