1.3 algorithms Flashcards

1
Q

o(n)

A

the time is takes is directly proportional to the size of the data

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

o(1)

A

always takes the same time and the same number of steps (memory) regardless of the amount of data input

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

o(n^2)

A

as the number of items steadily increases, the time taken increases more rapidly therefore, the curve gets steeper

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

o(2^n)

A

time doubles for each addition to the data set - time is increasing exponentially

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

o(log2n)

A

as the number of items steadily increases, the time taken increases by smaller and smaller amounts

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

o(nlog2n)

A

divide and conquer
the graph is like a massive quadratic with less of a curve

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

explain the purpose of procedures (sub-routines)

A
  • algorithms/programs can be broken down into smaller parts
  • these are names reusable pieces of code that can be called any number of times within an algorithm/ program to perform a specific task
  • procedures are used to avoid the duplication of code
  • each procedures can be individually tested/ debugged
  • procedures are used to make an algorithm/program more efficient and secure (try not to use this point)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

the difference between local and global variables

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

what is meant by passing by reference and why is it used

A
  • where a address is passed via a parameter into a subroutine and the original value is passed and used by that subroutine
  • this is used if any changes made in the subroutine needs to be stored in the original value/variable outside the subroutine
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what is meant by passing by value and why is it used

A
  • where a value is passed via a parameter into a subroutine and a copy of the value is created for the duration of the subroutine cell
  • this ensures that the original value passed to the subroutine cannot be changed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

why is self documenting identifiers important and give an example

A
  • allows code to be followed and understood more easily
  • reduces the need for the additional documentation to be produced, such as additional annotation or software manuals
  • example: VAT or firstname
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

why is program layout important and give an example

A
  • allows blocks of code and constructs to be followed and identified more easily
  • a consistent program layout helps improve the quality of the software and allows developers to maintain quality and standards
    -example: indentation to identify the start and end of constructs such as IF statements, Loop/nested loop structures
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

why is annotation is important and give an example

A
  • allows developers to record the development process and logic with the actual code
  • many developers could be working on the one project and each developer needs to understand the logic between one and others code
    -example: X DIV 2 ‘calculates if X is even or odd
16
Q

why is it good programming practice to use constants, meaningful names for variables and annotation in computer programs

A
  • they can be set once and then used many times throughout the program and if they change then they only have to be changed once. (constants)

-it is clear what the variable is holding and aids program readability (meaningful names)

-other programmers will find the code easier to follow (annotation)

17
Q

benefit of passing by value

A
  • avoids problem of unintended side affects where the parameter has its value changed in the main program as well as in the procedure
18
Q

benefit of passing by reference

A
  • avoids the larger amount of processing/storage (associated with passing by value, possibly large amounts of copying)
    -allows change to be passed back to the calling program
19
Q

what is the purpose of validation and give an example

A
  • is the process of checking if the data entered is sensible in the context in which it is being used
    -reduces the possibility of entering invalid data into a system

example:
range checks on dates

20
Q

2 situations where a linear search will generally perform faster than a binary search

A
  1. when the number of items to be searched is very small
  2. the search value is one of the first items in the array
21
Q

1 situation where a binary search will generally perform faster than a linear search

A
  • when there is a large sorted data set
22
Q
A
23
Q
A
24
Q
A
25
Q
A