Computing A Level - Hooks

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

4.1.1.13 Local Variables in Subroutines Characteristics of Local Variables Declared Within a Subroutine: Why is it Good Practise to Use Local Variables?:

- Subroutines can have their own variables. • Only exists inside this routine. • Is only accessible within this routine. • Can be passed out of this routine into another as a parameter. • Less chance of the code coming across an error or the programmer making an error by calling the wrong variable name if similar. (less accidental errors) • Easier to debug the code to find errors. • Is easily portable for someone else to use just one subroutine etc.

Terminology.. - Node: - Edge: - Root: - Child: - Parent:

Contains the tree data. An edge/branch connecting two nodes together. The only node which has no incoming edges. The set of nodes that have incoming edges from the same node. Is the case for all nodes that are connected to it by outgoing nodes from this parent.

4.2.1.3 Fields, Records and Files Introduction: 1. Text file: 2. Binary file: Writing/Reading from/to a Text File in VB: File(Channel #, "TextFileName.txt", OpenMode.Member)

• Up until now when we save a program we are working on and close VB.net we lose any data we have entered. Sometimes we want to save the data that has been entered into the program. To do this we use a file and store all the data on backing store. Two common types of file are text file or a binary file. Is used to store just text based characters. If opened in a text editor the contents will make sense. Is used to store any type of data. If opened in a text editor the contents will not make sense. File(Channel #, "TextFileName.txt", OpenMode.Member)

4.4.1.5 Procedural Abstraction What is Procedural Abstraction?:

A representation of a computational method. It can be used to keep the actual values in a computation separate from the overall design THUS eliminating the need to change other parts of the program, if the design is changed. • In summary, the result of this is a procedure.

4.1 Fundamentals of Programming 4.1.1 Programming 4.1.1.1 Data Types Define what is meant by a 'Data Type': Where/When to Use the Following: • Integer - • Real/Float - • Boolean - • Character -

A set of data with values having pre-defined characteristics E.G/ string, integers. • A classification that identifies one of a number of various types of data that can be used in a program is a data type. A whole number. For example, -25, 3, 28596 A number with a fractional part. For example, -13.5, 0.0, 3.142 Can only take the values of True or False. A letter, number or special character typically represented in ASCII. For example, A, ? or %. **Note: the character 4 is represented differently in the computer from the integer 4 or the real number 4.0

4.1.1.11 Parameters of Subroutines Describe the Use of Parameters to Pass Data Within Programs: Subroutines with Interfaces:

Passes local variables to and from subs to manipulate them or use them in creating new data and information to store in another variable. • Frequently, you need to pass values/variables to a subroutine. The exact form of the subroutine interface varies with the programming language, but will be similar to the below: [Visual Basic] Sub SubroutineName(ByVal/Ref Parameter 1 As DataType, ByVal/ByRef Parameter2 As Datatype, ...)

4.4.4.3 Order of Complexity (A2/NEW/Big-O Notation?) Introduction: Actual Order of Complexity:

"" O(n!) = most complex. Factorials. O(An) = anything with an exponent. O(n3) = polynomial time algorithm. O(n2) = nested loop. O(nlog2n) = logarithmic algorithm. O(n) = linear search or simple loop. O(log2n) = logarithmic. E.g. Binary search. O(n0) = No matter what n is, the result will always be the same number as the operand = most simple. • The order of complexity of a problem is taken to be the growth rate of the most efficient algorithm which solves the problem using Big O notation.

Graph Terminology: - Graph = - Weighted Graph = - Vertex/Node = - Degree of a Vertex/Node = - Automation = - Edge/Arc =

A graph is a set of vertices or nodes connected by edges or arcs. Those edges can be 1 or 2 way. When axes are labelled / "Labelled graph". Therefore, the edges are given a value. .. Number of neighbours it has. Turning an abstraction into a form that can be processed by a computer... The connection between two nodes/vertices.

Records:

A record type groups together a number of variables which need not be of the same type. Structure TBook Dim Title As String Dim ISBN As String Dim Price As Decimal Dim YearOfPublication As Integer End Structure

4.2.4.1 Graphs (A2/NEW) Introduction: Typical uses for graphs include:

Abstraction of a map can produce a graph model. • To represent computer networks, with nodes representing computers and weighted edges to show the bandwidth between them. • Roads between towns, with weighted edges to show the distances, rail fares or journey times. • Tasks in a project, some of which have to be completed before others. • States in an FSM. • Web pages and links.

4.1.2.2 Procedural-Oriented Programming Describe the Structured Approach to Programming and Design: Designing Structured Programs:

Aims to improve clarity and maintainability of programs. • Makes use of local variables, • Makes use of white space and indentations, • Does not use "End" or "Goto" to finish a procedure, • Makes use of meaningful identifiers. • Top-Down Design = technique of breaking down a problem into smaller tasks to be performed. Each of these tasks is then further broken down into separate subtasks and so on until each subtask is sufficiently simple to be written as a self-contained subprogram.

• String - • Date/Time - • Pointer/Reference - • Records - • Arrays -

Anything enclosed in quote marks. For example, "Peter", "123". A Date or Time can be stored here. For example, if it must store both, 02/04/2016 00:00:00 etc. "" "" Where more than one separate data value can be stored under one name, at a different position. For example, at Index 0 is "Penelope", at Index 1 is "0.50", and at Index 2 is "Paid".

Implementing a Graph: • Adjacency Matrix. • Adjacency List.

As a 2D array. Drawn as a grid, with a 1 if a node neighbours, and a 0 if not. Therefore, stores everything. -ve = if the matrix has many nodes without many neighbours then its storing lots of 0s = wasted space. +ve = easier to be created because everything is stored and its quicker to do. Mentions Vertex number and then records the numbers of its neighbouring nodes. -ve = more difficult to change what is stored because not everything is. +ve = stores just what you need/connected to. Note: Weighted graph/list = have to store neighbour and the value of the edge.

BNF Examples See notes for Syntax Diagram tools...

BNF: • Structure - composed of a list of statements of the form; LHS ::= RHS where ::= is interpreted as 'is defined by' E.g. <point> ::= . <point> is a meta-component/syntactic variable. | means 'or', another meta-symbol. E.g. <digit> ::= 0|1|2|3|4|5|6|7|8|9 1. Write the BNF definition of a variable which could be a single letter of letter followed by a digit. <variable name> ::= <letter> | <letter><digit> <letter> ::= A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z <digit> ::= 0|1|2|3|4|5|6|7|8|9

Inheritance = Association aggregation =

By means of inheritance, new classes (descendants) can be derived that inherit properties and methods from a parent-class. They can have new properties and methods of their own too. The class you start with is called the base class. • In Summary: a class shares properties and methods of a parent class. • Uses an "Is a" relationship between 2 classes. E.g. a Human is a Mammal. This is a type of association. It can occur when a class is a container of other classes, but the container classes don't have a strong life-cycle dependency on the container. For example, - A player who is part of a team does not cease to exist if the team is disbanded... • As opposed to Inheritance, this has a "Has a" relationship. E.g. a Teacher has a student, and a student has a teacher. • Therefore, there is no ownership between the two objects and each has their own lifecycle and can be created and deleted independently.

4.4.1.11 Automation What is meant by the term 'Automation':

Deals with building and putting into action models to solve problems / Once abstraction has been used effectively and the problem to be solved has been simplified an algorithm can be designed. This algorithm can then be automated which means implementing a solution on a computer. • For example, you could model the financial implications of running an ice-cream van at a given venue for a week... You'd need to think of: • creating and implementing algorithms related, then execute them and test the results...

4.4.1.8 Problem Abstraction/Reduction What is Problem Abstraction/Reduction?:

Details here are removed until the problem can be represented in such a way that is possible to solve! Because the problem reduces to one which has been previously solved.

4.4.1.7 Data Abstraction What is Data Abstraction?:

Details of how data is represented/stored in the computer is hidden in this case [which allows new kind of data objects to be constructed from previously defined types of data objects.] • It is a methodology that enables us to isolate how a compound data object is used from the details of how it is constructed. • For example, when using real or float numbers in a program, we do not care for how these are actually represented in the computer!

4.3.6.1 Dijkstra's Shortest Path Algorithm (A2/NEW) Introduction: Trace it: How does it work? What is this applied to and why?

Dijkstra was a Dutch computer scientist. His algorithm is designed to find the shortest path between one particular start node and every other node in a weighted graph. The algorithm is similar to a breadth-first search, but uses priority queue instead of FIFO queue. "" "" ""

4.1.1.8 Random Number Generation in a Programming Language [Visual Basic] Example:

Dim Rnd as New Random For x = 1 to 3 Number = Rnd.Next(1, 10) [10 not inclusive] x = x + 1 Next

4.3.4.1 Linear Search Time Complexity of Linear Search Algorithm:

Example: We wish to find a particular item in a list containing 500 000 items. Consider the worst-case scenario, assuming it takes one millisecond (0.001s) to make a comparison: Number of comparisons needed = Up to 500 000 if the item wanted is the last... Time taken to find desired item = 500 000 x 0.001 = 500 s (over 6 minutes!)

4.3.4.2 Binary Search Time Complexity of Binary Search: Trace:

Example: We wish to find a particular item in a list containing 500 000 items. Consider the worst-case scenario, assuming it takes one millisecond (0.001s) to make a comparison: Number of comparisons needed = log2 500 000 = 19 (219 = 524 288) Time taken to find desired item = 19 x 0.001 = 0.019 s Procedure P (Low, High, x) Found <- False Repeat Middle <- Int ((High + Low) /2) If List(Middle) = x Then Found <- True Else If x > List(Middle) Then Low <- Middle + 1 Else High <- Middle - 1 End If Until Found = True Or Low > High End P

4.4.2.1 Finite State Machines with and without Output What is a Finite State Machine?: Rules: Usage of FSMs:

It is a model of computation used to design computer programs and sequential basic circuits. • It's an abstract model of how a machine reacts to external events, not a physical machine e.g. washing machine... Changes from one state to another when triggered by some state and only has a finite total of states. 1. Can only be in one state at any one time. 2. Can change from one state to another in response to an event/condition - called Transition. 3. The FSM is defined by a list of its states and conditions for each transition. • Widely used in modelling the design of hardware digital systems, compiles and network protocols. • Also, used in the definition of languages and whether a word in a language is acceptable, etc. • An FSM with no output is known as a Finite State Automaton. Has a start state and a set of accept states which define whether it accepts/rejects finite strings or symbols. • If, when you are in a particular state, the next state is uniquely determined by the input, it is a deterministic final state automaton. *Accept/stop states have double circles.

What Does it Mean if Something is Nested?: Why is It Beneficial to Use More Meaningful Identifier Names?:

Inside something/another structure. For example, a nested iteration means a loop within another loop, such as a while loop within a for loop. • It's easier to understand what is going on and use correct variable names/Less Confusion. • Easier for someone else to read your code and understand it. • Easier to correct mistakes.

4.2.3 Stacks 4.2.3.1 Stacks (A2/NEW) Introduction: Application: Describe the following operations: • Push - • Pop - • Peek/Top - • Test for an empty stack - • Test for a full stack -

LIFO data structure, Last In First Out. Use could be such that when you go back a page in your web browser, it takes the first URL off the stack - most recently visited since, to reload to your web browser. • Can be implemented as either a static or dynamic data structure. Static needs 2 variables to be stored with it; one to record the max size of the array and one to record how many items are currently in it. Adds a new item to the top of the stack. Removes and returns the top item from the stack. Returns the value of the top element on the stack, without removing it. Tests to see whether the stack is empty, and returns a Boolean value. Tests to see whether the stack is full, and returns a Boolean value.

Graph Terminology: - Undirected Graph = - Directed Graph/Digraph = - Path = - Closed Path = - Cycle =

No set direction to follow from one node to another/axes do not have a direction they can travel - you can travel any way to any other neighbouring node. Therefore, edges are bidirectional. Axes have set directions you can follow - there are set ways of travelling from one node to another dependent on the direction of an edge connecting two nodes together. Sequence of edges between two particular nodes. Start and end at the same node. Closed path where all the edges are different.

4.4.1.9 Decomposition What is meant by the term/process 'Decomposition':

The breaking down of a complex problem into a number of sub-problems, each of which performs an identifiable task.

Pseudocode • Assignment: • Comments: • Nested Selection Inside Iteration: • Plain Selection: Other Information:

NumOK := false OR NumOK ← false Anything after a # While If - Then - Else Repeat - Until IF answer = 'Computer Science' THEN OUTPUT 'Of course it is!' ELSE OUTPUT 'Try again!' Pseudocode: is used in the Design stage and it allows the designer to write algorithms without the need to worry about the syntax of a particular language. Once the pseudocode has been written it can be converted to a programming language. This is the Implementation stage. R ← USERINPUT Area ← pi * r^2 Circumference ← 2 * pi * r OUTPUT Area OUTPUT Circumference • A program is a description in a programming language of a process that achieves some task that is useful to someone

4.2.2 Queues 4.2.2.1 Queues (A2/NEW) Introduction:

Queues are of a FIFO data structure. New elements only added to the rear/end of the queue, and elements only retrieved from the front/beginning. Described as "an ordered collection of items which are added at the rear of the queue and remove from the front." > Of a linear queue, the front and rear pointers are what move, not the elements.

Dynamic VS Static Data Structures: • Dynamic - • Static -

Refers to a collection of data memory which has the ability to shrink in size - the size of the structure does not have to be specified in advance of run time. This is managed with the aid of the heap, a portion of memory from which a free index can be assigned as the NEXT FREE variable value to anything added to the structure, and can take on an index value if an item is removed. - Useful for implementing data structures lie queues when the maximum size isn't known in advance. Fixed in size, the size of the data structure must be specified in advance of run time.

4.4.2.3 Regular Expressions (A2/NEW) Introduction: Uses include: Symbols:

Regular expressions are a tool that enables programmers and computers to work with text patterns. Matching patterns in text files (e.g. when searching for a word in a word processing program), by compilers to recognise the correct format of a variable name or the syntax of a statement and by programmers to validate user input (e.g. to check that a postcode or email address is of the correct format). • Programs like Java and Python support the use of regular expressions. • Regular expressions are often referred to as 'patterns'. See notes...

4.1.1.12 Returning a Value/Values from a Subroutine Returning Values - Returning a Value -

Returning Values - Use a Subroutine in Visual Basic and switch to ByRef instead of ByVal. Returning a Value - Use a Function in Visual Basic with the 'Return' command of the value at the end.

4.4.5.1 Turing Machine (A2/NEW) Introduction: How Can it Be Expressed?: Importance of the Turing Machine:

The Turing machine consists of an infinitely long strip of tape divided into squares. It has a read/write head that reads symbols from the tape and makes decisions about what to do based on the contents of the cell and the machines current state. • Thought of as a primitive, abstract computer. Theoretically, anything that can be represented as Turing Tape is computable. It's an FSM with the addition of an infinite memory on tape. A Turing machine must have at least one state, known as a halting or stop state, that causes the machine to stop for some inputs. "" ""

4.4.1.10 Composition What is meant by the term/process 'Composition':

The combining of several procedures to form compound procedures. It can also mean combining several objects to form compound data. • For example, records or data structures such as a tree or queue. • Bottom-up testing where subroutines are tested individually and then these are combined into sub-systems which are then tested etc.

4.4.1.6 Functional Abstraction What is Functional Abstraction?:

The result of this is from firstly, a procedural abstraction, and then another which disregards the particular computation method. • The particular computation method is hidden in this type of abstraction, because it is of no concern to the user. • For example, using a database, you sort records in a certain way, but you don't actually know how this is done, it just happens.

Terminology: - Subtree: - Leaf-node: Implementation of a Binary Search Tree: - One 3D Array. - Three 1D Arrays.

The set of nodes and edges comprised of a parent and all descendants of the parent - a subtree may also be a leaf. A node that has no children. • Beginning 1, stores Data. Beginning 2, stores to the Right of the data. Beginning 3, stores to the Left of the data. • 3 Separate for; Data, Array position for data on the right, Array position for data on the left.

4.1.2.3 Object-Oriented Programming (A2/NEW) Introduction: See notes for help/diagrams/reminders...

This is where the world is viewed as a collection of objects. It might be a person, animal, or event for example. An object-oriented program is composed of a number of interacting objects, each of which is responsible for its own data and the operations on that data. Program code in this case creates the objects and allowed them to communicate with each other by sending messages and receiving answers.

4.4.1.2 Following and Writing Algorithms What is meant by the term 'Algorithm':

What is meant by the term 'Algorithm': A set of rules or a sequence of steps specifying how to solve a problem. It always terminates. • For example, a cooking recipe...

4.3.5.2 Merge-sort Time Complexity of Merge-sort Algorithm: Trace:

You 'bubble up' the largest/smallest item, then the second largest/smallest, then the third, and so on, until no more swaps are needed and the data is ordered. • The merge sort uses divide and conquer to sort items and is very efficient for a large list. The basic steps are: - Divide the unsorted list into n sublists each containing one item - Continually merge sublists producing new sorted sublists until only one sublist • The merge process works like this: - Compare the first item in leftlist with first item in rightlist - If item in leftlist< item in rightlist, add item in leftlist to mergedlist and read next item in leftlist - Else add item in rightlist to mergedlist and read next item in rightlist Time Complexity of Merge-sort Algorithm: O (nlogn) Pros: Very efficient for large list Cons: More complex to implement Numbers <- [45,62,13,98,9,50] NumItems <- Len(numbers) FOR I <- 1 TO NumItems FOR J <- 1 TO (NumItems - 1) IF Numbrs(j) > Numbers(J + 1) THEN Temp <- Numbers(J) Numbers(J) <- Numbers(J + 1) Numbers(J + 1) <- Temp END IF ENDFOR OUTPUT Numbers ENDFOR

4.1.1.5 Boolean Operations in VB See notes for tables and diagrams. AND OR XOR NOT NAND NOR

...

4.1.1.4 Relational Operations in VB • Equal To • Not Equal To • Less Than • Greater Than • Less Than or Equal To • Greater Than or Equal To

= <> < > <= >=

Define what is meant by a 'Hierarchy Chart': What Are the Limitations of Using Hierarchy Charts?:

A tool for representing the structure of a program, showing how the subprograms relate to each other to form the complete solution/program. It is depicted as an upside-down tree structure. • The idea is that you keep breaking the problem down until the smaller problems can be easily solved. This is known as divide and conquer. A Hierarchy Chart shows this process pictorially. It does not show the detailed program structures required in each module. For example, it doesn't show selection and iteration. • This is what a STRUCTURE CHART is therefore then for...

4.3.2.1 Simple Tree-Traversal Algorithms (A2/NEW) • Pre-Order: • In-Order: • Post-Order: Uses of tree-traversal algorithms include: *Chapter 44 in textbook*

Drawing an outline of the tree starting left of the root. As passing the left of a node, you output the value. Used to produce prefix notation, used in functional programming languages. Starting left of the root, draw an outline. As you pass underneath each node, output the value. This visits all the nodes in sequential order. Starting left of the root, draw an outline. As you pass to the right of a node, output the data in that node. This is used in program compilation to produce Reverse Polish Notation.

What is the concept of 'Abstraction': • Representational Abstraction • Abstraction by Generalisation

It can be defined as "a representation arrived at by removing unnecessary detail" For example, ANY computer model of say, a flight simulator, IS an abstraction. For example, London tube map model. Simple model of the actual geography of the Tube Stations. • NOTE: The more you simplify your model, the less likely it becomes that the model will mimic reality due to stripping away details that could be important... Grouping by common characteristics to arrive at a hierarchical relationship of the 'is a kind of' type.

Circular Queue Implementation:

• To overcome the limitations of a linear queue, is to use a circular queue, so when the array fills and the rear pointer points to the last element of the array, say q[5], it will be made to point to the first element/q[0] when the next item joins the queue, assuming this cell is empty. This solution is less flexible than a dynamic structure if the max number of items isn't known in the beginning, and requires more effort by the programmer.

Used For: Overflow: Underflow:

• To store return addresses, parameters and register contents when subroutines are called (see below) • In evaluating mathematical expressions held in reverse polish notation If the stack is implemented as an array, an attempt to push an item onto a full stack would cause overflow, so an error message can be given to the user to avoid this. If the stack pointer is -1, the stack is empty and underflow will occur if an attempt is made to poop an item from the stack.

Class = Object = Instantiation = Encapsulation = Summary:

Is a blueprint/template for an object, and it defines the attributes and behaviours (methods) of objects of that class. An instance of a class. Creation of a class, making a single object each time you instance the class. An object encapsulates both its state (values of its instance variables) and its behaviours or methods. All the data and methods of each are wrapped into a single entity so that if the attributes and behaviours of one object cannot affect the way in which another object functions - they are concerned solely with themselves - selfish! Bundling together of properties and methods into an object. • In other words, the term encapsulation is used to describe the process of combining the properties and the methods that manipulate it and bundling them into an object.

4.4.1.3 Abstraction Computational Thinking:

Is a vital skill for a programmer and it involves thinking about how a problem can be solved. The 2 steps to solving a problem are: 1. Stating the problem in such a way that it is potentially solvable using an algorithm 2. Attempting to construct an efficient algorithm to solve the problem • Computational thinking involves thinking logically and applying the tools and techniques of computing to think about, understand, formulate and solve problems. Computing is sometimes referred to as the automation of abstractions.

A TM Has Six Components: Universal Turing Machines:

1. Input alphabet 2. Output alphabet 3. Tape that is infinite in length 4. Tape head used to read contents of tape one cell at a time 5. Finite set of states including start state 6. A program in the form: (Current state, Input symbol) = (Next state, Output symbol, Movement) The problem with TMs is that a different one must be constructed for every new computation to be performed. - With a Universal Turing Machines (UTM), U is an interpreter that reads the description M of any arbitrary Turing machine and faithfully executes operations on data D precisely as M does. - The description M is written at the beginning of the tape followed by D. The read/write head must start on M and then move between M and D as M is executed. The UTM can go on then to simulate M by using the input D. - A UTM can thus simulate any other Turing Machine.

FSM viewed as: Expressed using:

A Turing machine can be viewed as a computer with a single fixed program, expressed using • A finite set of states in a state transition diagram (essentially the diagram we use for mapping FSM's!) • A finite alphabet of symbols e.g. a binary alphabet of a, 1 and ☐ (the latter meaning a blank) - In other words, on each cell of the infinite tape is written a symbol. The symbols that are allowed on the tape are finite in number and include the blank symbol. - Each Turing machine has its own alphabet (finite set of symbols), which determines the symbols that are allowed on the tape. - The Turing machine has a tape head that is positioned over a cell on the tape. This tape head is able to read a symbol from a cell and write a new symbol onto a cell. The tape head can also move to an adjacent cell (either to the left or to the right). - A Turing machine has a finite number of states and, at any point in time, a Turing machine is in one of these states. When a Turing Machine begins running, it is in its start state and its tape head is positioned over one of the cells on the tape; the symbol on this cell is the current symbol. A Turing machine halts when it moves into one of the halt states.

Define what is meant by a 'Structure Chart': Therefore, What Are the Advantages of Using Structure Charts?: What Are the Overall Advantages of Using the Structured Approach to Programming and Design?:

A more detailed hierarchy chart. Shows import and export of data, iteration and selection, Boolean points. It is much more detailed! • Easier to read and understand what exactly is happening when. • Easier for someone else to understand your code because the block of code will be separated by white space making each task more identifiable. • Comments will also help you and someone else understand your code. • It can help to make finding errors easier/better off to not make mistakes first time round.

4.2.5 Trees 4.2.5.1 Trees (Including Binary) (A2/NEW) Introduction: • A tree is ... • A rooted tree ... • A binary tree is ... • A binary search tree is ...

A tree is a data structure. They ahve no cycles and are undirected. ...A connected, undirected graph with no cycles. A tree doesn't have to have a root. ... A root, branches and leaves. One vertex has been designed as the root and each edge leads/is directed away from this root. ... A rooted tree in which each node has a max of two children. Therefore, each node can have only 0, 1 or 2 kids. ... A binary tree that holds items in such a way that the tree can be searched quickly and easily for a particular item, and items can be easily added, and the whole tree can be printed in a sequence. It is again a typical use of a rooted tree.

4.1.1.6 Constants and Variables in a Programming Language [Visual Basic] Define what is meant by a 'Variable': Define what is meant by a 'Constant':

A variable is a memory storage location of data that can change during normal execution of the program. Therefore, variables can change, but this isn't always the case. The variable name for a data item is also referred to as the 'identifier'. A constant is a set value stores under an identifier that can only change if the user does so manually, therefore it cannot be altered during normal execution of the program.

4.4.4.5 Classification of Algorithmic Problems (A2/NEW) Non-Computable: Decision Problem: Undecidable: Tractable: Heuristic Approach:

An algorithmic problem that admits no algorithm. It is not computable because no solution can be produced. A Y/N algorithmic problem. For example, an algorithm which decides if a number is a prime or not. If a Decision problem has an algorithmic solution, it is said to be decidable. A non-computable decision problem. E.g. you know the answer but cannot compute a solution, such as "This statement is false." True/False? - It does not have an algorithmic solution/is non-computable. A problem that can be solved within a reasonable amount of time (polynomial time). Intractable: A problem that is computable but for which no reasonable time solution has been found (polynomial time). E.g. the Travelling Salesman problem, where 5 cities means for 24 routes, but 23 cities would take 51 years to solve... => Educated Guess/Approximations. Using knowledge and experience to guess at a solution to an intractable problem. This will not necessarily result for the most optimal solution to an intractable problem, but a sufficient solution all the same.

4.2.1.2 Single and Multi Dimensional Arrays What is a Single Array?/One-Dimensional: What is a Multi-Dimensional Array?:

An array is defined as an finite, ordered set of elements of the same type. Finite means there is a specific number of elements in the array - that it has a capacity to store - and ordered implies there is a first, second, third, etc. An array can have two or more dimension. A two-dimensional array can be visualised with a table. It helps the user cut down on the number of other variables needed, such as values stored in two separate arrays, could be pushed into one if made 2 dimensional.

How Can the Following Items Be Used in Programming? • Assignment - • Iteration - • Selection - • Subroutine (Procedure/Function) -

An assignment statement assigns a value to a named location in memory. A named memory location is called a variable. Means repetition. Refers to the looping of code a number of times. Depending on whether the loop is definite or indefinite, it will either have a set number of repeats to complete or will wait for a condition to become true to finish the looping. For example, For statement/While statement/Do statement. Executes a section of code depending on a Boolean result/condition to be met. Conditions are usually formed using relational operators (Boolean signs, e.g. <> or >...) For example, IF statement. Is a named block of code which performs a specific task within a program. Two types; procedures and functions for most high-level languages.

Files in VB - Member's:

Append = File opened to append to it. Binary = File opened for binary access. Input = File opened for READ access. Output = File opened for WRITE access. Random = File opened for random access.

4.4.4.7 Halting Problem (A2/NEW) What is the halting problem?: Significance of the halting problem for computation:

Can you write a program that can tell if another program will halt or get itself into an infinite loop? Therefore, how long should you wait? (Leave the computer running forever or call it quits?) E.g. Is there an off perfect number? Where a perfect number has, all factors excluding itself, add together to make the number in question. E.g. 6 = 1+2+3. ""

4.1.1.3 Arithmetic Operations in VB 1. Addition 2. Subtraction 3. Multiplication 4. Real/Float Division 5. Integer Division, including remainders 6. Exponentiation 7. Rounding 8. Truncation

For example, 2 + 4 For example, x - y For example, T1 * 3 For example, 7 / 3 Works by using Div (/) This is where division takes place, and the value returned is the remainder left over after the division has been carried out. For example, 20 / 3 ... the remainder is 2 (a 3 fits into 20, 6 times.) Works by using Mod (\) This is powers/indices For example, 2^3 | 23 This is ... For example, Rounded <- Round(VariableName, 3) #3 meaning to 3 dp This is where a real number is rounded down to the next whole number. For example,

4.4.1.4 Information Hiding What does this mean?/What is it?:

Hiding design details behind a standard interface For example, an interface which hides the system behind it so the user isn't confused by a load of code they cannot understand and can work their way around the system. [Abstraction means to leave out unnecessary details.]

Composition aggregation = Polymorphism = Overriding = ** Difference between Overriding and Polymorphism? Which is an example of which?

Composition aggregation is a stronger form of aggregation. If the container is destroyed then every instance of the contained class is also destroyed. For example: - If a hotel is destroyed then every room in the hotel is destroyed. An example of this is Overriding. This is an example of Polymorphism. This means that a method, for example, inherited by a subclass from a parent class, may have a different implementation than the same named method the parent class has.

Procedural & Functional help... See notes too!

Consider the process of summing natural numbers. If we add all the natural numbers up from 1 to n the sum can be calculated using the following two computations: • Sum n = ½ n (n+1) • Sum n = 1 + 2 + 3 + ... + (n-1) + n Both these equations are examples of procedural abstraction. They describe procedures and are examples of abstraction because they are both general equations in terms of n and the actual numbers to be used in the calculation are omitted. In order to achieve functional abstraction, we need to add on an extra layer of abstraction: Now we are not interested in how the sum of n numbers is to be computed. We could use either implementation and it would not affect anything. The computation method is hidden. The only thing we are concerned with is input(s) and output.

4.2.1.4 Abstract Data Types/Data Structure (A2/NEW?) Summary:

Data type whose properties are specified independently of any particular programming language • ADTs are data structures whose properties are specified independently of any particular programming language. An ADT is a way of looking at a data structure. It focuses on what it does and ignores how it does it. • A stack and a queue are examples of ADTs. Stacks and queues can be implemented using an array or a linked list. This demonstrates the abstract nature of stacks and queues and how they can be considered separately from their implementation.

4.1.1.2 Programming Concepts How Can the Following Items Be Used in Programming? • Variable Declaration • Constant Declaration • Sequence.

For example, "Dim x As Integer" For example, "Const 4.25 As Double" Just 2 or more statements following one after the other, in order of writing.

4.4.3.1 Back-Naur Form/Syntax Diagrams (A2/NEW) Meta-Languages: Syntax of a Language: (Explanation for the need of BNF)

In order to translate e.g. Python into Machine code, all the rules of the language must be defined unambiguously (manner open to only 1 interpretation). This is one reason why it is hard to get computers to understand 'natural language' e.g. English, as they are too imprecise and ambiguous with grammar and syntax. In Comp Sci, this is defined as the set of rules that define what constitutes a valid statement. It would be possible to define a valid identifier in a programming language using regular expression - but lengthy and time consuming. And some language constructs involving e.g. nested brackets, can't be defined this way. HENCE the need for meta-languages, such as Back-Naur Form. Many constructs that could be written with Regex can be done so with BNF more succinctly (clearly and briefly/concisely). (Syllabus point: why can BNF represent some languages which regular expressions cannot?)

User-Defined Data Type: Language-Defined Data Type: Define what is meant by the term 'Scope':

Is something that the user of the program creates and defines a set of data values as. Means it is built into and recognised by the computing language used. The scope of a variable refers to the visibility of a variable and which parts of the program can see it. Some variables have a global scope and some have a local scope. Local scope means only the sub it is used in can see it. Global means every subroutine can see it.

Paradigm #4: Functional - Paradigm #5: Logic / Declarative - Paradigm #6: Event driven -

Program consists of functions which are the fundamental building blocks of a program e.g. Haskalla. Statement are written as a series of functions. which accept input data as arguments and return an output. Using a declarative language that consists of facts and rules about a particular subject instead of a sequence of instructions. E.g. SQL, where you give statements that describe the problem to be solved, and the language implementation decides the best way of solving it for you. The flow of program execution is determined by events. For example, a subroutine is executed in response to events such as the click of a button. VB.net is an example of an event driven language.

Hand-Tracing Algorithms:

Trace tables are used to test algorithms to make sure that they contain no logical errors. The process of hand tracing an algorithm involves working through the algorithm on paper line by line and recording the values of all the variables so you can see clearly what an algorithm produces.

Linear Queue Implementation:

• 2 ways to do so. 1. As items leave, all others move up one space so the front of the queue is always the first element of the structure. E.g. q[0]. With a long queue = requires significant processing time. 2. It can be implemented with pointers to front and rear. An integer is needed to hold the size of the array and a variable to give the number of items currently in it - can work out how much free space there is. Problem arises as things are deleted from the front as nothing moves up, just the pointers change, and so the free memory is not filled again...

4.1.1.15 Role of Stack Frames in Subroutine Calls (A2/NEW) The Role of call Stacks in subroutines: How is a call Stack used to hold return addresses?: - - -

• A major use of the stack data structure is to store information about the active subroutines while a computer program is running. • The call stack keeps track of the address of the instruction that control should return to when a subroutine ends (return address). Subroutines could be nested so the stack may need to hold several return addresses so that control makes sure each routine completes fully. • For recursion, each time the subroutine calls itself again, a return address is pushed onto the stack, and each time a subroutine ends, the return address is popped off. If the programmer makes a mistake and the recursion never ends, the memory of the stack will become full and the stack will overflow, the program will crash!

4.1.2 Programming Paradigms 4.1.2.1 Programming Paradigms (A2/NEW) What is meant by programming paradigms?: Paradigm #1: Procedural paradigm - Paradigm #2: Object-oriented paradigm - Paradigm #3: Imperative -

• A style of computer programming - different computer languages support tackling problems in different ways - there are several to look at. Such as Python or Pascal, have a series of instructions that tell the computer what to do with the input in order to solve the problem. Such as Java. User uses objects, which are data items with all the processing possible on the data item attached to it. ava, C++ and Delphi are examples of object-oriented languages. Objects then are examples of a class where each instance of an object shares common properties, known as fields, although the values of the fields may vary, and methods. Instructions executed in programmer defined sequence.

4.1.1.16 Recursive Techniques (A2/NEW) Use of recursive techniques in programming:

• A subroutine is recursive if it is defined in terms of itself. The process of executing the subroutine is recursion. • A recursive routine has 3 characteristics; 1- stopping condition or base case must be included, which when met, means the routine won't all itself and will start to unwind. 2- for input values other than the stopping condition, the routine must call itself 3- the stopping condition must be reached after a finite number of calls.

Priority Queue Implementation:

• Acts like a queue in that items are de-queued by removing them from the front of the array, but the logical order of the items is determined by their priority, with higher priority at the front and decreasing throughout/lowest at the rear. Therefore, it is possible for new items to join at the beginning instead of tagging on at the back. • Such as queue would be implemented by checking priority of each item in the array, starting at the rear and moving it along one place until an item with the same or lower priority is found, at which point the new item can be inserted.

4.3.3.1 Reverse Polish - Infix Transformations (A2/NEW) Introduction: Advantages & Uses: Precedence of operators acting upon operands:

• Also called Postfix. Developed by a Pole named Jan Lukasiewicz. • Method of writing arithmetic expressions that are particularly suited to computerised methods of evaluation. Eliminates the need for brackets un a sub expression, produces expressions in a suitable form for evaluation using a stack and it is used in interpreters based on a stack e.g. Bytecode and Postscript. • The way we would normally write an arithmetic expression is called Infix. The output value after RPN is called Postfix. = ( +-) */ ^ exponentiation/powers/indices, meaning e.g. 3^2 = 32 ~ unary minus, meaning e.g. -3+2 Rule: .... * before + or???...

4.3.5.1 Bubblesort Time Complexity of Bubblesort Algorithm: Trace:

• Bubble sort is a simple sorting algorithm. It works by repeatedly stepping through the list to be sorted, comparing two items at a time and swapping them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted. The algorithm gets its name from the way smaller elements "bubble" to the top of the list. Time complexity: O (n2) Pros: Very simple and easy to implement Cons: Inefficient for large lists Procedure P () i: Integer Swapped: Boolean Repeat Swapped ← False For i ← 1 to n - 1 do If List (i) > List (i + 1) Then 'Swap the records Swapped ← True End if Next i n ← n - 1 Until n = 1 or Swapped = False End P Procedure Swap(x: Int, y:Int) Temp: Integer Temp <- x x <- y y <- Temp End Swap

What is the Difference?: What are the Advantages of Using Named Constants?:

• Constants cannot change during the execution of a program, whereas variables can - but the latter doesn't always happen. • Less confusing. • Someone else can easily read and understand the code. • If you wish to change it, all you do is set the new constant value where the constant is declared and it will update all thru the program.

4.4.2.4 Regular Language (A2/NEW) Reason for:

• English is a natural language. You learn to speak it. They have common features - Comparising of a set of words. - Governed by rules that define grammar/syntax of a language. However, the syntax of a natural language is not always unambiguous, complete or concise. • Formal Language consists of - An alphabet - Rules of Syntax. For the formal language, the alphabet is a finite set and the syntax is clearly defined - unambiguous. Therefore, they are used to describe things like programming languages. BNF and RPN count under here.

How Do Functions Differ?: What Are the Advantages of Using Subroutines in Programs?:

• Functions return a value/values, subroutines do not but they do still carry out process needed during the execution of a program. In a large program - • Small enough to be understandable as a unit of code THUS relatively easy to understand, debug and maintain. • Can be tested independently which shortens the time taken to get a large program working. • Can be reused with confidence in different programs and also called more than once. • A large project becomes easier to monitor and control • Quicker to write a program with many working on it as each write a small subroutine simultaneously that fits together.

4.1.1.14 Global Variables in VB Contrasting Local Variables against Global Variables:

• Global variables are the default type used by Main Sub and can be accessed anywhere in the program. • Locals only exist whilst the subroutine is running. They cannot be used outside of the subroutine.

4.4.4.6 Computable and Non-Computable Problems (A2/NEW - Links with Turing Machine - Definition of Computable)

• If no algorithm exists to be able to solve a problem then it is said to be non-computable. (non-solvable) For example, the Tile Problem. • Turing's hypothesis (also known has Church's thesis) is a widely-held belief that a function is computable if and only if it can be computed by a Turing machine. This implies that Turing machines can solve any problem that a modern computer program can solve. In other words, if a problem cannot be written for use by a Turing machine, it cannot have a programmed solution by a modern-day computer - hence it being a non-computable problem. If a problem can be reduced to 0s and 1s, it is computable. If an algorithm exists, there is an equivalent Turing Machine for it...

4.1.1.10 Subroutines (Procedures/Functions) Introduction: What is meant by the term 'Subroutine':

• In Computing when solving a problem, breaking it down into smaller sub-problems is the key to finding a solution. This process is called step-wise refinement. We need to break programs down into subroutines. A subroutine can either be a procedure or a function. A procedure is a set of instructions that performs a specific task. A procedure is called with an instruction. A function is very similar to a procedure but returns a single value and is called from within an expression. A subroutine is a sequence of program instructions that perform a specific task, packaged as a unit. It is a named block of code which is not in use until called and running during the execution of the program, and sits outside the main block of coding. It can be called within other subroutines.

Typical uses of rooted trees include: Uses of Binary trees include:

• Manipulating hierarchical data such as folder structures or moves in a game. • Making information easy to search. • Manipulating sorted lists of data. A binary tree is useful for storing items that arrive in random order but that need retrieving quickly e.g. a dictionary for a word processor. By performing an in-order traversal the items in the tree can also be retrieved in alphabetical or numerical order.

Examples of FSMs: State Transition Tables: Mealy Machines:

• Mobile phone • Wireless router • Controllers e.g. traffic lights, London Underground turnstiles, lifts • Personal Video Recorder (e.g. Sky Box) • This is an alternative way of representing an FSM. Usually shows; current state, input, output, next state. See notes for more help & a diagram. Named after George Mealy, is a type of FSM that's outputs are determined by the current state and the current input.

Advantages of OOP: Disadvantages of OOP:

• No shared global data structures because communication between objects is via messages • Modification of an object's structure will have no effect whatsoever on any other part of the program • Inheritance saves much repetitive code • Can sometimes run slow because of the vast cross-referencing between objects • An object-oriented design is not always the most appropriate. Sometimes a functional design would be the most appropriate

Where Could Either Be Used Appropriately?: Example of the use of a Single Array in VB: Example of the use of a Multi-Dimensional Array in VB:

• One-dimensional = useful way of representing a vector. • Two-dimensional = useful way of representing a matrix. • An n-dimensional = set of elements with the same data type that are ordered. ...

Uses: Operations:

• Output waiting to be printed is typically stored in a queue on a disk. E.g. people sending documents to be printed simultaneously, means whoever printed first, gets their first. • Characters typed at a keyboard, held in a queue in a keyboard buffer. • Queues are useful in simulation problems (one which attempts to model a real-life situation so things can be learnt about it) - E.g. Program simulating customers arriving at random times to check-outs in supermarkets, and taking random times to pass thru. Using a sim means the optimum number of check-outs can be discovered. • Adding an item - enQueue(Item) • Removing an item - deQueue(Item) • Testing whether the queue is empty - isEmpty() • Testing whether the queue is full - isFull()

How is a call Stack used to hold parameters?: How is a call Stack used to hold local variables?:

• Parameters required for a subroutine when called may be held on the call stack. Each call to a subroutine will be given a separate space on the call stack for these values. [local variables for subroutine] [return address] [parameters for subroutine] -> all three of these make up one frame of the Stack for a subroutine. • A subroutine frequently uses local variables which are known only within this sub. These may be held in the call stack. Each separate call to a subroutine gets its own space on the stack, like above with parameters. Storing local variables on the call stack is more efficient than using dynamic memory allocation, which uses heap space. **A call stack is composed of stack frames. Each stack frame corresponds to a call to a subroutine which hasn't terminated yet.

4.4.1.1 Problem-Solving Developing Solutions to Simple Logical Problems: Checking Solutions to Simple Logical Problems:

• Solving logic problems shows good computational thinking as it means you think logically about how to combat the issue and apply techniques for solving it. ""

4.3.1.1 Simple Graph-Traversal Algorithms (A2/NEW) Breadth-first & application: Breadth first searches are used to solve many real-life problems including: Depth-first & application: Depth first searches are used to solve many real-life problems including:

• The breadth first traversal algorithm begins at the root node and explores all neighbouring nodes. Then for each of those nearest nodes it explores their unexplored neighbours and so on (uses a queue) • Shortest path problem between two points (Dijkstra). This is really important in GPS navigation systems and computer networks • Facebook. Each user profile is regarded as a vertex in a graph and two vertices are connected if they are each other's friends • The depth first traversal algorithm begins at the root node and explores as far as is possible along each branch before backtracking (uses a stack) • Job scheduling. This is where a series of tasks need to be performed and certain tasks must be completed before the next one begins • Solving problems such as finding the way out of a maze and working out possible chess moves

4.2 Fundamentals of Data Structures 4.2.1 Data Structures and Abstract Data Types 4.2.1.1 Data Structures What Are Data Structures?: (Concept):

• a way of storing data in an efficient and organized way inside the computer. A collection of programming constructs and elementary data types, such as integer, real, Boolean, organised to facilitate processing in some way. Languages like VB and Pyton have some built-in structured data types like string, array or list and record.


Ensembles d'études connexes

Chapter 59 Iggy Practice Questions, Chapter 58 Iggy Practice Questions, Med-Surg Chapters 59 & 60, Gastro Nclex Questions, Nclex Review: Lower GI Problems - Intestinal Obstruction, Nclex Review: Lower GI Problems- ileostomy, Total Parenteral Nutritio...

View Set

Simulation Lab 2.1: Module 02 Zenmap (nmap)

View Set

Chapter 6 - Bones and Bone Tissue

View Set