Thursday, 28 January 2016

Revision

Binary is base 2 number system to represent numbers. Right to left each digit represents


Binary can represent negative numbers there are two way to do this:
Sign and magnitude:
  • Simplest way
  • The most significant bit represents the sign (whether it is positive or negative)
  • 1 means it is negative
  • 0 means it is positive
  • However the MSB means that the largest number for 8 bits that can be represented as 127, as the 8th bit is used for the positive or negative sign.
  • Only represent a 7 bit number
  • It is harder to do calculations as some bits are numbers and some are for signs.
  • 0 is represented twice
  • 127 to -127 range

Represent -4 in 8 bits:
4=00000100
-4= 10000100



Two's Complement:
If in the exam it says it represented in Two's Complement the whole binary number will be wrong.
  • Overcomes the shortcomings of S/M as the whole number range can be represented
  • Write out as a positive number then starting from the right hand side invert bits.
  • The most significant bit becomes a negative number
Represent -90 in binary using 8bits:
90=01011010
-90=10100110

0+0 = 0
1+0 = 1
1+1 = 10
1+1+1= 11

Hexadecimal:
  • 0 to 15 using 0-9 and A to F
  • Represented in 4 bits per hex character
Floating point Binary
  • We use this to represent really small or really big numbers accurately using 8 bits
92=
0.92 x10^2
0.92 is the mantissa this represents significant digits of that number
10 is the base
2 is the exponent (How far the mantissa is to be raised)

01101 011
Where 01101 is the mantissa and 011 is the exponent

Steps to take:
1. Convert the exponent into denary
2. The mantissa started as 0.1101. Move the decimal point 3 places to get 0110.1
3. Write 0110.1 as denary 6.5 (4+2+0.5)

If there is more than one leading 0 this will be classed as an un-normalised number. The decimal goes after the first 0
Shift by the exponent of 3
0110.1
Left bits go by 1,2,4
Right bits go by 1/2, 1/4, 1/8, 1/6


There is a trade off between accuracy and range depending on how many bits are used for the exponent and mantissa.
More bits for the mantissa = more accuracy
More bits for the exponent = more range

Thursday, 14 January 2016

1.4.2 Data Structures

What is a data structure?
A data structure is a simple way of representing data held in a computers memory.

Types of data Structures to know:
One dimensional Arrays
Two dimensional Arrays
Three dimensional Arrays
Records
Tuples
Lists
Stacks
Queues

Characteristics:
There are two categories of data structures:
  • Static or Dynamic
Static structures the size cannot be changed when the data has been compiled into the data structure
This means it could be seen as inefficient
Static structures are easier to program and on system requirements, this is because they are fixed sizes, inflexible.

Dynamic:
Dynamic structures, data can vary in size to fulfil all of memory. Memory is allocated dynamically (as the program is executed, therefore changes in size.
Disadvantage= memory allocation is dynamic possibility of data overflow, exceeding the limit.
Advantage= makes the most efficient use of memory


Static:
Memory is allocated at compile time in fixed sizes
Advantages= Memory allocation is fixed and so there is no problem with adding and removing data items.
Disadvantages= Can be very inefficient as the memory for this data has been set aside whether its needed of not during execution of the program.
Advantages= Easier to program as there is no need to check on data structure size at any point.

Key operations:
Sorting data - e.g. by a unique key
Searching data- using a specific item to search.
Append date (based on primary key

Big O Notation measures the efficiency of data structures.
www.bigocheatsheet.com


Arrays- Their dimensions

One-Dimensional

All arrays have one unique identifier
There is also an index number - these are 0 based, therefore they always start at 0
Each piece of data within any data structure is called an element.

To code an Array
You use [] square brackets to code the start and the end

To access or change data you simply call the index n umber of the data that you want.
Arrays are static data structures so their sizes do not change once compiled from the programming language.


Two Dimensional
Arrays can have double dimensions.
It is an array within an array
There is a unique identifier
Square brackets used to open first array
The second set of square brackets are used to create the table.
ALL THE DIFFERENT SQUARE BRACKETS MEAN A DIFFERENT ARRAY WITH THE ARRAY IS STARTING!

To separate an array we use an X and Y column
Therefore you need to have 2 index numbers,
X always comes first as if it were a graph

Three Dimensional
There is an X Y and Z axis.
These consist of an array that is inside of an array which is also inside of an array.
Similar to a cube of data.

Different brackets code different data structures!
Array values are stored in a contiguous way (one after the other) and 2D arrays are allocated in row order (first row and then second)
Arrays can be Global or Local variables.
It is impossible to remove all elements from an array once it has been created however you can set the elements to NULL (which means none in python)


For loops have a predefined amount of times to loop
However a WHILE loop doesn't know how many times it needs to be executed.


Records, Lists and Tuples:
Records:
  • A record is a data structure
  • It is always sorted by a type of attribute
  • They do not have to be the same data type
  • When you want to access data within a data structure like a record you always have to access it through its attribute
  • To do this you use a dot system (address_book.first_name)
  • Data found within a data structure is unordered unless you use indices, these can be used to order them.
  • Only numbers can be ordered in a data structure.
  • Attributes make the data more user friendly
Lists:
  • Lists can be used in Python in order to create arrays
  • These and Tuples are very similar however there are some key minor differences:
  • In the exam you can identify a list as they use square brackets
  • These sit halfway between an array and Tuple (in appearance and characteristics)
  • These can hold different types of data types like Tuples
  • Unlike Tuples these can be edited once they have been assigned (just like arrays)
  • These require an index number to retrieve data (Makes it harder to use as attributes are easy to understand instead of index numbers)
  • Lists are mutable (items can be edited or deleted)

Tuples:
  • These are similar to records
  • They are used to group data together
  • Very similar to a one dimensional array however there are differences:
    • Tuples are immutable once they have been assigned (cannot be changed)
    • Unlike arrays the data types don't have to be the same
    • In the exam you can identify a Tuple as it uses normal brackets
  • Items are retrieved again using an index like an array
  • You cannot add or remove items as these are immutable they can not be changed in anyway.
  • Most commonly used where it is important that data can be accessed but not changed!

Dictionary brackets-{}
Tuples brackets-()

Stacks:
  • These are good for linear data
  • These operate on a LIFO data structure (Last in, First Out)
  • Add data from the top and remove from the top (Pancake stack on a plate, the last on the plate: Last cooked, is the first eaten!)
  • Adding data to the stack is called Pushing
  • Removing data from the stack is called Popping
    • These terms are used with the Little Man computer
  • Stacks are implemented using an array
  • A stack within computers memory system is implemented using pointers.
  • Pointers are only used to located the top of the stack
  • Stack pointers use a base 0 number system.
  • Pushing or popping always takes place at the top of the stack
  • If you have a pop instruction the stack pointer moves by -1
  • If you have a push instruction the stack pointer moves by +1
  • Errors can occur at the bottom or the top of the stack;
    • if the stack is full and you try to push another piece of data there will be a stack overflow error
    • if the stack is empty and you try to pop another piece of data there will be an error

Example:
IF stack pointer =maximum:
        THEN repot stack full
         STOP
ELSE:
         increase stack pointed by 1
         set stack (stack pointer) to data
END-IF


IF stack pointer =minimum:
        THEN repot stack empty
         STOP
ELSE:
          set data to stack (stack pointer)
         decrease stack pointed by -1
END-IF


Queues:
  • First in first out
  • The most recent piece of data to the queue is the last piece of data to be taken out
  • There are two pointers:
    • One to monitor the back of the queue where data is added
    • one for the front of the queue where data will be removed from
  • The data within a queue does not physically move forward in the queue (this is because it will be inefficient), instead the two pointers are used to denote the front (data removed) and back (data added) of the queue, and these pointers move.
  • The pointers are designated ranges so they know where to move.
  • These are a circular data structure- unlike stacks.
  • The end pointer can be 'before' the start pointer, but as the queue is a circular data structure it will read from the start, then go back to the beginning to read to the end point






The Questions:
2. A stack contains the values 3,4,5 with a 3 being the start/ the first value in the stack stored and the 5 being the last. Show how the stack changes when the following sequence of commands is used:
         POP
         PUSH 7
         POP
         PUSH 8
         PUSH 9


 
 
 
 
 
9
5
 
7
 
8
8
4
4
4
4
4
4
3
3
3
3
3
3


3.  A queue contains the values 3, 4, 5, with 3 being 3 being the first value stored and 5 the last, Show how the queue changes after the following commands:
        POP
        PUSH 7
        POP
        PUSH 8
        PUSH 9

3
4
5
 
 
 
 
4
5
 
 
 
 
4
5
7
 
 
 
 
5
7
 
 
 
 
5
7
8
 
 
 
5
7
8
9

Tuesday, 12 January 2016

Software Development


The Waterfall Cycle

T- Technical
E- Economic, whether or not the product will fit into the price range of the company.
L- Law, these are implements set in place which need to be obliged with.
O-Operational, this is how the system works and whether it is reliable when it runs, you need it to run multiple times.
S-Schedule, The amount of time that you have to design and produce the product, for example landing on mars and having a 30 years time frame.

Analysis:
The result of this is a requirement specification and a user requirement doc.

Testing:
How and when you are going to test it and what the results are.

Installation:
This is detailing how it can be installed.
Can cover hardware and software

Evaluation:
Reflecting on the project, what went well and what didn't go as well.

Maintenance:
Is creating updates and fixing broken hardware.
These maintenance changes may take years.

Disadvantages of the Waterfall Model:
  • Once in the testing stage it is very hard to go back this can be very expensive if you want to go back and make changes
  • It isn't a very suitable model for large ongoing projects.
  • It is a risky system
  • The installation phase may not work therefore this is very costly.
  • You cannot do two stages in the cycle at once, the processes move linear through stage by stage this isn't useful as there is no feedback loop so minor errors aren't easily spotted.
Alternative models to the Waterfall Cycle:

Spiral Model:
  • In this model there is a constant cycle of planning and analysing, there are shorter iterations in each of the loops.
  • There is no defined starting point therefore you can easily move between stages in the model, you can feedback between the stages.
  • You do each stage more than once to return working software.

The Rapid Application Development:
  • There is a prototype created (Which is an example model, in a smaller scale)
  • with this prototype many tasks will be taken to test the demand for the product, to see whether clients like the idea or not, also you can test how well the prototype will work.
  • The prototype will be developed and tested and then showed to the customer who will decide whether it is appropriate for their needs, this is good as the customer is allowed to see the product quickly.
Extreme Programming:
  • This type of programming in carried out with pairs working on each part of the task.
  • You pre plan the tests and determined the results before you actually run the testing stage in the cycle.
  • There is continue integration, meaning continuously updating the code and adding new parts.
Agile Methodologies :
  • Sprint - This task takes no more than 2 weeks, the task in divided into a series of sections to be carried out.
  • Scrum - There are small teams of 7 people no more, and within the team there are defined roles and each day they come together for a stand up meeting and they only talk about 3 things;
    • what they did yesterday.
    • what they are going to do today.
    • Any issues that they have.
  • The client can see the product in small releases after a few tasks are completed to make any necessary changes as soon as they are required.
  • There is feedback between the stages.

Games that will be playable on phones and applications will be RAD
Fitness trackers could be spiral or waterfall as they needed to be tested after each stage of programming as well as not being produced with any risks they need to be able to be tested and given feedback from clients.