Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lesson Objectives Aims – Know about…

Similar presentations


Presentation on theme: "Lesson Objectives Aims – Know about…"— Presentation transcript:

1 Lesson Objectives Aims – Know about…
Arrays (of up to 3 dimensions), records, lists, tuples. (b) The following structures to store data: linked-list, graph (directed and undirected), stack, queue, tree, binary search tree, hash table. (c) How to create, traverse, add data to and remove data from the data structures mentioned above. (NB this can be either using arrays and procedural programming or an object-oriented approach).

2 Data must be stored in any program for it to do something useful
Data structures Data must be stored in any program for it to do something useful Selection of correct data type is essential, but correct data structure is equally important There are two types: Static Dynamic

3 Static data structures
Size is pre-determined and set, it cannot be changed in the program Limited in how useful they can be due to inflexibility and a need to know exact requirements before the program runs This can be seen as part of how “strongly typed” a language is

4 Strong typing A strongly typed language will expect all data types to be explicitly defined This can extend to: Stating the size of an array The size of strings (pascal… why?!) However, this can be a good thing as such code can be considered almost completely “safe” as it is totally predictable and cannot “outgrow” the system limitations Compilers should catch most typing/casting errors before the code can even run.

5 Dynamic structures Dynamic data structures allow storage to grow and shrink as necessary This is obviously preferable – you don’t need to know the exact requirements at compile time Dynamic structures will have slightly different overheads and requirements to static structures and may also make use of static structures as the “building blocks” of their structure!

6 Array – 1d A basic table Dim colours(4) as string
Each element has an index Set: colours(2) = “red” Get: console.writeline(colours(2)) 1 2 3 4 green Blue red Purple orange

7 Array – 2d A table… Dim SalesFigures(12,3) as decimal (row,column)
Set: SalesFigures(11,2) = “32000” 1 2 3 …. 11 32000 12

8 Array – 3d A set of tables… Dim SalesFigures(3,12,3) as decimal
(table,row,column) Set: SalesFigures(3,2,5) = “32000”

9 1D Array 2D Array 3D Array

10 Probably… In the exam, indexes would be 1D - (index – row) 2D - (column, row) 3D - (table, column, row) VB is special…

11 Records A custom data structure which allows data of different types to be stored and accessed through a common name Person.name = “dave” Person.weight = 85 VB calls this a “structure” – it’s the same thing

12

13 Tuples Like a record but cannot be changed Can contain data of varying types Can be referenced by index as an array, but is NOT an array – an array is one data type only.

14

15 Depends on the language…!
Lists Depends on the language…! IF they are static then they work like arrays but allow different types of data to be stored IF they are dynamic, then… No fixed size May have a set data type… may not!

16 Dynamic data structure Each piece of data is a “node” in the list
Linked list Dynamic data structure Each piece of data is a “node” in the list Each node contains a pointer to either: The next element Null The list requires a starting pointer

17 Linked lists Diagram time… Adding Removing Inserting…?

18 In VB… Dim myList as new list(of string) Can be anything – list of objects even. Mylist.add(item) Mylist.remove(item)

19 Queues First in First Out data structure Can grow and shrink dynamically Will require a pointer to the “head” and “tail” Often implemented as a linked list!

20 In vb… Dim myQ As New Queue() myQ.Enqueue("Hello")’stores at the tail Var = myQ.Dequeue()’gets from head of the queue

21 I’m bored now You lot have done very little recently.
Task 1: make notes on and be ready to explain: Hash tables Stacks Binary Trees Graphs You will need code examples in VB too. I will add YOUR notes to this presentation

22 Then… Get the programming tasks from the shared area Do them I DO expect this handed in, it WILL affect my judgement of your suitability to continue next year. Really. Code in. Everyone.

23 Uses a hashing algorithm to:
Hash Tables Uses a hashing algorithm to: Generate a unique value for given data This value links to an index in the hash table This means data can be stored anywhere (basically) in the table, but… Can be found VERY quickly because a hashing algorithm will produce the same output for a given input.

24 Collisions In small data sets there is more likelihood of collisions Collisions are dealt with by creating a linked list (or other suitable data structure) at each entry in the table where there is more than one piece of data to be stored

25 stacks FILO – First in, Last Out Adding data: Remove Data:
Stack must not be full Otherwise stack overflow New item added to the top of the stack (Push) Stack pointer increased by 1 Remove Data: POP operation Stack pointer Decreased

26 Uses of Stacks: Backtracking (undo) Reversing data
Storing states (CPU, Interrupts etc)

27 Nodes can be named (parent, child, root, leaf) Storing data:
Binary tree Made up of nodes (data) Nodes can be named (parent, child, root, leaf) Storing data: Left usually smaller Right usually larger Searching: Starts at root node Complexity logn

28 Adding nodes Given this tree… Add the breed “poodle”

29 Method Start at root node – Poodle > Harrier Go down to the next node Poodle < Rottweiler so go LEFT Next node – Poodle < Pug so go LEFT and add the node to the LEFT underneath PUG

30 Poodle

31 Finding a node Same method as before – find “Whippet” Start at root, Whippet > Harrier so go RIGHT Whippet > Rottweiler so go RIGHT Node = Whippet = found.

32 Graphs A structure consisting of Vertices and Edges (nodes and connections) Connections can be directional Nodes (vertices) can have multiple connections to other nodes Used to model real world network like structures such as roads, computer networks, railways etc. Often used to calculate distances/times and so on – Logistical operations!

33 Review/Success Criteria


Download ppt "Lesson Objectives Aims – Know about…"

Similar presentations


Ads by Google