2.2 Problem solving and programming Flashcards

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

What are the three types of programming constructs?

A

sequence
branching
iteration

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

Explain what we mean by sequence as a programming construct

A

when code is executed line-by-line, from top to bottom

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

Explain what we mean by branching as a programming construct

A

when a particular block of code is met if a specific condition is met

examples are if and else statements

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

Explain what we mean by iteration as a programming construct

A

blocks of code which loop

can be either:
count controlled- blocks of code looping over a certain number of times
condition controlled- blocks of code looping until a specific condition is met

examples are DO, WHILE, FOR loops

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

Explain recursion

A

When a subroutine calls upon itself during its execution
-continues until a stopping condition is met

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

What are some advantages to using recursion? (2)

A

-code can be represented in fewer number of lines
-easier to express some functions recursively e.g. factorial

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

What are some disadvantages to using recursion (2)

A

-risk of stack overflow if memory runs out
-difficult to trace

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

What is a scope and how is this related to variables?

A

-variables can be defined with a global or local scope
-a scope is the section of code where the variable can be accessed

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

Explain what local variables are and their characteristics

A

variables which can only be accessed within the subroutine where they were defined

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

Explain what global variables are and their characteristics

A

variables which can be accessed through the whole program

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

What are some +/- of using local variables? (3, 1)

A

+won’t affect other sections of code
+deleted once subroutine ends so doesn’t take up lots of memory
+multiple local variables with same names but in different subroutines can exist

-need to keep declaring in different sections of code if needed there

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

What are some +/- of using global variables? (1, 3)

A

+useful for values that need to be used by multiple parts of the program

-if changed, it will affect other areas of code where it has been called upon
-can unintentionally edit it
-not deleted until program terminates so requires more memory

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

What is modular programming?

A

a technique used to split large/complex programs into smaller, self-contained modules

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

Why is modular programming useful? (3)

A

-easier to divide tasks between a team and manage projects
-simplifies the process of testing and maintenance (each component can be tested individually
-improves reusability of components

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

Explain a top down design/modules

A

-technique to modularise programs
-problem is broken down into subproblems until each is is represented into individual, self-contained modules which perform a specific task
-modules form blocks of code called subroutines

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

Explain functions

A

-blocks of code which perform a specific task
-functions return a value
-can pass parameters by value or by reference

17
Q

Explain procedures

A

-blocks of code which perform a specific tasks
-procedures output values
-can pass parameters by value or by reference

18
Q

What do we mean by passing a value by reference?

A

-address of parameter is given to the subroutine
-value of parameter will be updated at the given address
-changes the original data stored

19
Q

What do we mean by passing a value by value?

A

-a copy of the value is passed to the subroutine and discarded at the end
-the original value stored is unaffected

20
Q

What is an IDE?

A

integrated development environment
-provides a set of tools to make it easier for programmers to write, develop and bug code

21
Q

What are some features of IDEs? (7)

A

-stepping (executes line by line to see how each line effects program)
-variable watch (observes the contents of variable and how they change in real time through execution)
-debugging tools (provides errors in lines during run-time)
-autocompletion
-syntax highlighting
-breakpoints

22
Q

What is a class?

A

a template for an object
-defines state and behaviour for an object

23
Q

How can we define the state and behaviour of an object?

A

state- using attributes
behaviour- methods

24
Q

What is an object?

A

a particular instance of a class

25
Q

What is encapsulation?

A

when attributes cannot be directly edited (declared as private)
-can only be altered by public methods
-makes the program less complex by protected data from being edited

26
Q

How do top down designs use encapsulation?

A

each module is designed to be self-contained

27
Q

What do we mean by divide and conquer? Where could this be used?

A

problem solving technique
simplifies complex problems quickly

three parts:
-divide (problem in 1/2 with every iteration)
-conquer (each subproblem is solved, often recursively)
-merge (solutions to subproblems are recombined)

examples: quick sort, merge sort, binary search

28
Q

What are the various problem solving strategies? (7)

A

-backtracking
-visualisation
-data mining
-heuristics
-performance modelling
-pipelining
-divide and conquer

29
Q

Explain backtracking

A

-problem solving technique implemented using algorithms, often recursively
-methodically builds a solution based on visited pathways found to be correct
-if a pathway is found to be invalid, algorithm backtracks to previous stage

30
Q

Explain data mining

A

-technique used to identify patterns or outliers in large data sets collected from a variety of sources (also known as big data)
-trends spotted can aids predictions about the future

31
Q

Explain heuristics and give an example of where this may be used

A

-non-optimal, ‘rule-of-thumb’ approach to problem solving
-used to find an approximate solution when the standard solution takes too long to find
-isn’t perfectly accurate/complete

example: A* pathfinding algorithm

32
Q

Explain performance modelling

A

-mathematical methods used to test various loads on different OS
-provides cheaper, less time-consuming or safer method of testing applications

33
Q

Explain visualisation

A

-data can be presented in a way that is easier for us to understand using graphs, trees, charts etc.
-makes it possible to identify trends that were not otherwise obvious