Presentation is loading. Please wait.

Presentation is loading. Please wait.

Overzicht Informatica

Similar presentations


Presentation on theme: "Overzicht Informatica"— Presentation transcript:

1 Overzicht Informatica
College 10 – Oktober 31 Computer Science an overview EDITION 7 / 8 J. Glenn Brookshear

2 C H A P T E R 8 (was Chap. 7) Data Structures
Abstractions of the actual data organization in main memory Allow users to perceive data as ‘logical units’ (e.g.: arrangement in rows and columns)

3 Data Structure Basics: Pointers
pointer = location in memory that contains the address of another location in memory so: pointer points to data positioned elsewhere in memory F02A FF8C 64B0

4 Static versus Dynamic Data Structures
shape & size of structure does not change over time example in C: int Table[2][9]; Table: Dynamic: shape & size may change example: Stack 48 97 17 Stack: 32 65

5 Arrays Example: to store 24 hourly temperature readings…
… a convenient storage structure is 1-D homogeneous array of 24 elements (e.g. in C: float Readings[24] ) In main memory: … x + 23 Address of Readings[i] = x + (i-1)

6 Two-dimensional Arrays
Sometimes 2-D homogeneous arrays are more useful (e.g. in C: float Table[4][5] ) => Address of Table[i][j] = x + (nr_of_columns × (i-1)) + (j - 1) => Example: address of Table[3][4] = x + 13

7 Opdracht: Suppose an array with 6 rows and 8 columns is stored starting at address 20. If each entry in the array requires only one memory cell, what is the address of the entry in the 3rd row and 4th column? What if each entry requires two cells? If 1 cell per entry: address at [3, 4] : × (3-1) + (4-1) = 39. If 2 cells per entry: address at [3, 4] : × (8 × (3-1) + (4-1)) = 58.

8 3D: place each 2D plane consecutively in memory
Opdracht: Describe a method for storing 3-D homogeneous arrays. What addressing formula would be used to locate the entry in the i-th plane, the j-th row, and the k-th column? 2D: 3D: place each 2D plane consecutively in memory Addressing formula (with x as start address): x + r × c × (i - 1) + c × (j - 1) + (k - 1)

9 Lists To store an ordered list of names we could use 2-D homogeneous array (in C: char Names[10][8]) However: addition & removal of names requires expensive data movements!

10 Linked Lists Data movements can be avoided by using a ‘linked list’, including pointers to list entries

11 Deleting an Entry from a Linked List
A list entry is removed by changing a single pointer:

12 Inserting an Entry into a Linked List
A new entry is inserted by setting pointer of (1) new entry to address of entry that is to follow (2) preceding entry to address of new entry:

13 Opdracht: Which of the following routines correctly inserts 'NewEntry' immediately after the entry called 'PreviousEntry' in a linked list? Routine 1 1. Copy pointer field of 'PreviousEntry' into the pointer field of 'NewEntry'. 2. Change pointer field of 'PreviousEntry' to the address of 'NewEntry'. Routine 2 1. Change pointer field of 'PreviousEntry' to the address of 'NewEntry'. 2. Copy pointer field of 'PreviousEntry' into the pointer field of 'NewEntry'. Previous (1) (2) => routine 1 is correct

14 Disadvantage of contiguous array structures:
Stacks Disadvantage of contiguous array structures: insertion / removal requires costly data movements Still okay if insertion / removal restricted to end of array: stack (with push & pop operations)

15 If maximum stack-size unknown:
A Stack in Memory Here: conceptual structure close to identical to actual structure in memory If maximum stack-size unknown: pointers can be used ( => conceptual = actual structure )

16 Queues List where insertions take place at one end, and deletions at the other: ‘queue’ To serve ‘objects’ in the order of their arrival (waiting-line)

17 Problem with queue shown so far:
Queue “crawling” (1) Problem with queue shown so far: queue moves downward in memory, destroying any other data in its path:

18 Queue “crawling” (2) Can be overcome by:
circular movement of insertions / deletions through pre-designated area of memory: Conceptual view of circular queue

19 Many, many more possibilities
Opdracht: Describe a data structure suitable for representing a board configuration during a chess game Simplest: 8×8 homogeneous array, where each entry contains one of the values {empty, king, queen, bishop, knight, rook, pawn} Other: 2×16 homogeneous array: 1st dimension used to distinguish between black / white; 2nd to enumerate remaining pieces of one color, incl. board position. To save memory space this 2nd dimension could be implemented as a linked list. Many, many more possibilities

20 Chapter 8 - Data Structures: Conclusions
Pointers: basic aid in definition of dynamic data structures Often used data structures: Arrays (multi-dimensional) Lists (contiguous & linked) Stacks Queues (crawling & circular) Trees (not discussed…)

21 ‘C H A P T E R’ 9.5 (was chap. 8) File Structures
Abstractions of the actual data organization on mass storage (hard disks, tapes, cd’s…) Again: differences between conceptual and actual data organization

22 Files, Directories & the Operating System
OS storage structure: conceptual hierarchy of directories and files directory tree files

23 Files: Conceptual vs. Actual View
View at OS-level is conceptual actual storage may differ significantly!

24 Text Files Sequential file consisting of long string of encoded characters (e.g. ASCII-code) But: character-string still interpreted by word processor! File in “Notepad” Same file in “MS Word”

25 From actual storage to conceptual view
Interpretation by Application Program Sequential buffer sequential view Assembly by Operating System actual storage

26 Disadvantage of sequential files:
Quick File Access Disadvantage of sequential files: no quick access to particular file data Two techniques to overcome this problem: (1) Indexing or (2) Hashing loaded into main memory when opened Indexing: Indexed File Index keys

27 Disadvantage of indexing is… the index
Hashing Disadvantage of indexing is… the index requires extra space + includes 1 extra indirection Solution: ‘hashing’ finds position in file using a key value (as in indexing)… … simply by identifying location directly from the key How? define set of ‘buckets’ & ‘hash function’ that converts keys to bucket numbers key value bucket number … N hash function

28 Hash Function: Example
If storage space divided into 40 buckets and hash function is division: key values 14, 54, & 94 all map onto same bucket (collision) Key values

29 Key field value can be anything

30 Handling Bucket Overflow
When bucket-sizes are fixed: buckets can fill up and overflow One solution: designate special overflow storage area not fixed in size!

31 Opdracht: If we use division as a hash function and have 23 buckets, in which bucket should we search to find the record whose key is interpreted as the integer value 101? 101 bucket number: 9 … … Division: 101 / 23 = 4, remainder 9

32 Opdracht: a) What advantage does an indexed file have over a hash file
Opdracht: a) What advantage does an indexed file have over a hash file? b) What advantage does a hash file have over an indexed file? a) When key unique: index directly points to required data, while hashing oftens require an additional (sequential) bucket search (incl. bucket overflow). b) No additional index file storage is required.

33 Chapter 9.5 - File Structures: Conclusions
abstractions of actual data organization on mass storage Changes of ‘view’: actual storage -> sequential view by OS -> conceptual view presented to user Quick access to particular file data by (1) indexing (2) hashing (requires no index, but requires bucket search!)

34 C H A P T E R 9 Database Structures
(Large) integrated collections of data that can be accessed quickly Combination of data structures and file structures

35 Historical Perspective
Originally: departments of large organizations stored all data separately in flat files Problems: redundancy & inconsistencies

36 Integrated Database System
Better approach: integrate all data in a single system, to be accessed by all departments

37 Disadvantages of Data Integration
Control of access to sensitive data?! Bijvoorbeeld: personeelszaken heeft niets te maken met persoonlijke gegevens opgeslagen door de bedrijfsarts! Misinterpretation of integrated data Supermarkt-database zegt dat een klant veel medicijnen koopt. Wat betekent dit? Wat als deze klant solliciteert op een baan bij de supermarkt-keten? What about the right to hold/collect/interpret data? Heeft een credit card company het recht gegevens over koopgedrag van personen te gebruiken/verkopen?

38 Conceptual Database Layers
Operating System Actual data storage Data seen in terms of a sequential view Compare:

39 The Relational Model Relational Model
shows data as being stored in rectangular tables, called relations, e.g.: row in a relation is called ‘tuple’ column in a relation is called ‘attribute’

40 Issues of Relational Design
So, relations make up a relational database… … but this is not so straightforward: Problem: more than one concept combined in single relation

41 Redesign by extraction of 3 concepts
Any information obtained by combining information from multiple relations

42 Example: Finding all departments in which employee 23Y34 has worked:

43 Relational Operations
Extracting information from a relational database by way of relational operations Most important ones: (1) extract tuples (rows) : SELECT (2) extract attributes (columns) : PROJECT (3) combine relations : JOIN Such operations on relations produce other relations so: they can be used in combination, to create complex database requests (or ‘queries’)

44 The SELECT operation

45 The PROJECT operation

46 The JOIN operation

47 Opdracht: X relation U V W A Z 5 B D 3 C Q 5 Y relation R S 3 J 4 K
RESULT X.U X.V X.W Y.R Y.S A Z J A Z K C Q J C Q K RESULT := PROJECT W from X JOIN X and Y where X.W > Y.R SELECT from X where W=5 PROJECT S from Y

48 Opdracht: PART relation MANUFACTURER relation Bolt 2X 1
PartName Weight Bolt 2X 1 Bolt 2Z 1.5 Nut V5 0.5 CompanyName PartName Cost Company X Bolt 2Z Company X Nut V Company Y Bolt 2X Company Y Nut V Company Y Bolt 2Z Company Z Nut V a) Which companies make Bolt 2Z? NEW := SELECT from MANUFACTURER where PartName = Bolt2Z RESULT := PROJECT CompanyName from NEW

49 Opdracht: PART relation MANUFACTURER relation Bolt 2X 1
PartName Weight Bolt 2X 1 Bolt 2Z 1.5 Nut V5 0.5 CompanyName PartName Cost Company X Bolt 2Z Company X Nut V Company Y Bolt 2X Company Y Nut V Company Y Bolt 2Z Company Z Nut V b) Obtain a list of the parts (+cost) made by Company X? NEW := SELECT from MANU’ER where CompanyName=CompanyX RESULT := PROJECT PartName, Cost from NEW

50 Opdracht: PART relation MANUFACTURER relation Bolt 2X 1
PartName Weight Bolt 2X 1 Bolt 2Z 1.5 Nut V5 0.5 CompanyName PartName Cost Company X Bolt 2Z Company X Nut V Company Y Bolt 2X Company Y Nut V Company Y Bolt 2Z Company Z Nut V c) Which companies make a part with weight 1? NEW1 := JOIN MANUCTURER and PART where MANUFACTURER.PartName = PART.PartName NEW2 := SELECT from NEW1 where PART.Weight = 1 RESULT := PROJECT MANU’ER.CompanyName from NEW2

51 Opdracht: PART relation MANUFACTURER relation Bolt 2X 1
PartName Weight Bolt 2X 1 Bolt 2Z 1.5 Nut V5 0.5 CompanyName PartName Cost Company X Bolt 2Z Company X Nut V Company Y Bolt 2X Company Y Nut V Company Y Bolt 2Z Company Z Nut V c) Which companies make a part with weight 1? NEW1 := SELECT from PART where Weight = 1 NEW2 := JOIN MANUCTURER and NEW1 where MANUFACTURER.PartName = NEW1.PartName RESULT := PROJECT MANU’ER.CompanyName from NEW2

52 Chapter 9 - Database Structures: Conclusions
(large) integrated collections of data that can be accessed quickly Database Management System provides high-level view of actual data storage (database model) Relational Model most often used relational operations: SELECT, PROJECT, JOIN, … high-level language for database access: SQL

53 Overzicht Informatica – Tentamen (1)
Most important sections (editie 8) & keywords: Ch , 3, 4: abstractie / algoritme Ch , 2, 4, 5, 6, 7: bits / data opslag & representatie (ASCII, etc) / Boolse operaties / flipflops / geheugen-vormen en -karakteristieken / getalstelsels (binair, hexadecimaal, etc…) / overflow & truncation errors Ch , 2, 3, 4, 6: cpu architectuur / machine language & instructions / programma executie / machine cycle / alternatieve architecturen Ch , 2, 3, 4: operating systems / batch processing / time-sharing / multitasking / OS componenten / process vs. programma / competition Ch , 2, 3, 4: network topologies / bridges / routers / client-server / the internet / world wide web / network protocols / the grid

54 Overzicht Informatica – Tentamen (2)
Most important sections (editie 8) & keywords: Ch , 2, 4, 5, 6: algoritme (formeel) / primitiven / pseudo-code / syntax / semantiek / iteratie / loop control / recursie / efficientie Ch , 2, 3, 4, 5: generaties: 1e, 2e, 3e / assembly language / compilers / machine independence / paradigma’s / imperatief / object-georienteerd / programming concepts / procedures / parameters / call by value/reference translation/compilation process Ch , 2, 3: software life cycle / ontwikkelings-fase / modulariteit / koppeling / cohesie / documentatie / complexiteits-maat voor software Ch , 2: datastructuren / abstractie / statisch vs. dynamisch / pointers / (arrays, lists, stacks, queues, etc…)

55 Overzicht Informatica – Tentamen (3)
Most important sections (editie 8) & keywords: Ch , 2, 5: databases vs. ‘platte’ files / relaties / tuples / attributen / relationele operaties: SELECT, PROJECT, JOIN / files / sequential / tekst / indexed / hashing Ch. 10 – 1, 3, 4: intelligent agents / Turing-test / production systems / search trees / heuristics / artificial neural networks / training vs test Ch. 11 – 1, 2, 4: computability / Turing Machines / the ‘halting’ problem Veel succes!


Download ppt "Overzicht Informatica"

Similar presentations


Ads by Google