Set, Bag and Sequence Exercises

School of Computing, Engineering and Information Sciences
University of Northumbria
Set, Bag and
Sequence
Exercises
School of Computing, Engineering and Information Sciences
University of Northumbria
Part A
Orderable Data
Aim:
Examine the nature of ordering in data.
Outline of Session:
With an example of a card pack, look at various ordering
possibilities.
Pack of Cards
A typical card pack contains four suits: spades, hearts, diamonds
and clubs.
Each suit contains 13 cards: ace, king, queen, jack, one to ten.
Two joker cards are also often added to the pack.
Order of Cards
Take a pack of cards, shuffle them and then sort them into 'order'.
Questions
What order are you choosing?
Are there different orders you could have chosen?
How might a computer program or database recognise such
orders?
A Different Order of Cards
Shuffle the cards again.
Questions
Is it possible for you sort them into the original 'order'? Is it possible
for you shuffle them into a different order? (Do not sort them).
Yet Another Different Order of Cards
Shuffle the cards again.
Questions
Is it possible for you sort them into the previous shuffled order? If
not, why not?
2
School of Computing, Engineering and Information Sciences
University of Northumbria
Part B
Sets, Bags and Sequences
Aim:
To introduce examples of sets, bags and sequences in real-world
data.
Outline of Session:
Examples of data in a tabular format are given for 12 real-world
applications. For each one it is necessary to decide whether the
rows of data are in the form of a set, a bag or a sequence of rows.
Instructions:
Look at each of the following tabular representations of data, and
for each one decide whether it is:
a set of rows,
a bag of rows, i.e. it contains duplicate rows,
a sequence of rows. i.e. it is important that the rows are in
a particular order.
In each case, give the reasons for your choice.
For each case that is not a sequence of tuples, suggest whether
the order of tuples given is a helpful order, whether some other
order might be preferable, or whether the order doesn’t matter.
For some other preferable order, state what (combination of)
sequencing attribute(s), ascending or descending, you would use.
Decide for each case whether the table of data could be stored in a
relation, where a row is put into a tuple and each column
corresponds to an attribute.
If it cannot be stored in a relation, either because tuples
would be duplicated, or because a tuple order is required that
cannot be obtained by sequencing the tuples by some attributevalue order, how would you amend the relation so that it could
represent the bag or sequence?
3
School of Computing, Engineering and Information Sciences
University of Northumbria
1.
Shopping List
Product Name
Quantity
Cornflakes (Large)
2
Packet of lean bacon
1
Tin of beans (Family Size)
12
Loaf of white bread
2
Tea bags (pack of 144)
1
Eggs
12
This is a:
Set
Bag
Sequence
If applicable, the tuple order is:
Helpful ?
Preferred
Sequencing
Yes/No/Doesn’t Matter
Reasons:
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
Can the tabular data be put into a relation ?
Yes/No
If not, how would you amend the relation so as to be able to represent
the tabular data ?
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
4
School of Computing, Engineering and Information Sciences
University of Northumbria
2.
Supermarket Checkout Receipt
Product Name
Price
Alpen Muesli
1.45
Alpen Muesli
1.45
Eggs, large (12 pack)
1.21
Toilet rolls, soft
(6 pack)
1.32
Beans (large tin)
0.28
Beans (large tin)
0.28
Beans (large tin)
0.28
Bacon, lean back
0.99
Bacon, lean back
0.99
This is a:
Set
Bag
Sequence
If applicable, the tuple order is:
Helpful ?
Preferred
Sequencing
Yes/No/Doesn’t Matter
Reasons:
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
Can the tabular data be put into a relation ?
Yes/No
If not, how would you amend the relation so as to be able to represent
the tabular data ?
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
5
School of Computing, Engineering and Information Sciences
University of Northumbria
3.
Company’s Customer List (sample)
Name
Address
Tel No
Fax No
Appledorn PLC
21, Dean Rd., Morpeth.
01670
873441
01670
873442
Ellison’s Sprays
Garden House, Byker.
0191 256
4433
0191 256
5621
Proctor & Gamble
Ltd
St Nicholas Rd., Gosforth
0191 261
8790
0191 261
8722
Tilcon Fixings
Airport Ind. Estate,
Kenton.
0191 235
2376
0191 235
2377
Whitelease Plant
Hire
15, Abbey Square,
Alnwick.
01665
435611
01665
435633
This is a:
Set
Bag
Sequence
If applicable, the tuple order is:
Helpful ?
Preferred
Sequencing
Yes/No/Doesn’t Matter
Reasons:
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
Can the tabular data be put into a relation ?
Yes/No
If not, how would you amend the relation so as to be able to represent
the tabular data ?
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
6
School of Computing, Engineering and Information Sciences
University of Northumbria
4.
Telephone Directory (sample)
Name
Address
Tel No
Fawcett J
Balliol Farm,
01665 266
7650
Goodall, C B
58, Burnham Av,
NE5 7TY
267 8893
Lightfoot ,
ME
96, Dacre St,
NE10 9RT
482 3317
Reynolds W
5, 15, Osborne Rd,
Jesmond
281 3346
Todd, D J
South Tyne View
01670 33417
This is a:
Set
Bag
Sequence
If applicable, the tuple order is:
Helpful ?
Preferred
Sequencing
Yes/No/Doesn’t Matter
Reasons:
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
Can the tabular data be put into a relation ?
Yes/No
If not, how would you amend the relation so as to be able to represent
the tabular data ?
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
7
School of Computing, Engineering and Information Sciences
University of Northumbria
5.
University Squash Ladder (sample)
The initial position in the ladder is random. Each player can
only play the person above/below them. The winner of the
game takes the higher of their two positions, the loser the
lower position. And so on, till the end of the season. The
number of games played by each person is variable.
Name
Department
Ext No
Teal, W
Computing &
Maths
4562
Robinson, G M
Chaplaincy
3581
Brigham, E
Law
1256
Sargent, M
Reprographics
6784
Hutchinson, P
Built Environment
7732
Wheatley, A
Art & Design
4512
This is a:
Set
Bag
Sequence
If applicable, the tuple order is:
Helpful ?
Preferred
Sequencing
Yes/No/Doesn’t Matter
Reasons:
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
Can the tabular data be put into a relation ?
Yes/No
If not, how would you amend the relation so as to be able to represent
the tabular data ?
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
8
School of Computing, Engineering and Information Sciences
University of Northumbria
6.
University Library Book Register (sample)
Title
Author(s)
Publisher
ISBN
Introduction to Database
Systems
C J Date
AddisonWesley
0-201-824582
Introduction to Database
Systems
C J Date
AddisonWesley
0-201-824582
Introduction to Database
Systems
C J Date
AddisonWesley
0-201-824582
Fundamentals of Database
Systems
Elmasri &
Navathe
AddisonWesley
0-8053-01453
Database Systems
Atzeni, Ceri,
Paraboschi,
Torlone
McGraw-Hill
0-07-7095006
Database Systems
Atzeni, Ceri,
Paraboschi,
Torlone
McGraw-Hill
0-07-7095006
This is a:
Set
Bag
Sequence
If applicable, the tuple order is:
Helpful ?
Preferred
Sequencing
Yes/No/Doesn’t Matter
Reasons:
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
Can the tabular data be put into a relation ?
Yes/No
If not, how would you amend the relation so as to be able to represent
the tabular data ?
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
9
School of Computing, Engineering and Information Sciences
University of Northumbria
7.
Football League Table (sample of Premier Division)
Club
Won
Drawn
Lost
Goal
Diff
Points
Newcastle Utd
5
1
0
+13
16
Arsenal
5
0
1
+10
15
Liverpool
3
0
3
+1
9
Manchester Utd
2
3
1
-1
9
Tottenham
Hotspur
1
2
3
-11
5
This is a:
Set
Bag
Sequence
If applicable, the tuple order is:
Helpful ?
Preferred
Sequencing
Yes/No/Doesn’t Matter
Reasons:
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
Can the tabular data be put into a relation ?
Yes/No
If not, how would you amend the relation so as to be able to represent
the tabular data ?
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
10
School of Computing, Engineering and Information Sciences
University of Northumbria
8.
Construction Task List
Task
ManHours
Price
Submit Tender
25
0
Obtain Contract
6
0
Lay Foundations
95
1,000
Build Walls
250
4,900
Fit Roof
110
1,200
Install Fittings
220
5,100
This is a:
Set
Bag
Sequence
If applicable, the tuple order is:
Helpful ?
Preferred
Sequencing
Yes/No/Doesn’t Matter
Reasons:
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
Can the tabular data be put into a relation ?
Yes/No
If not, how would you amend the relation so as to be able to represent
the tabular data ?
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
11
School of Computing, Engineering and Information Sciences
University of Northumbria
9
CAMRA Beer Register
(ABV = Alcohol by Volume, and is an indication of the
strength of the beer).
Name
Price
ABV
Ruddles County
1.80
6.5
Old Ebenezer
2.20
8.0
Bishop’s Finger
1.95
5.4
Black Sheep
1.80
6.2
Summer Ale
1.72
4.2
Snecklifter
1.61
5.4
This is a:
Set
Bag
Sequence
If applicable, the tuple order is:
Helpful ?
Preferred
Sequencing
Yes/No/Doesn’t Matter
Reasons:
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
Can the tabular data be put into a relation ?
Yes/No
If not, how would you amend the relation so as to be able to represent
the tabular data ?
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
12
School of Computing, Engineering and Information Sciences
University of Northumbria
10
New Cars for Sale at Nissan Dealership
Model
Colour
Primera 2.0 SE
White
Primera 1.6 GX
Ice Blue
Micra 1.3 GX
Racing Green
Micra 1.3 GS
Crimson
Almera 1.6 SLX
Racing Green
Primera 2.0 SE
Ice Blue
Primera 2.0 SE
White
Primera 1.6 GX
Silver
Almera 1.6 SLX
White
Micra 1.3 GX
Racing Green
This is a:
Set
Bag
Sequence
If applicable, the tuple order is:
Helpful ?
Preferred
Sequencing
Yes/No/Doesn’t Matter
Reasons:
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
Can the tabular data be put into a relation ?
Yes/No
If not, how would you amend the relation so as to be able to represent
the tabular data ?
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
13
School of Computing, Engineering and Information Sciences
University of Northumbria
11
Car Repairs at ‘Racing Motors’
Customer
Model
(In order of priority)
Registration
Job
G. Smith
Nissan
Primera
M 101 RCV
6,00O Mile Service
P. Wareing
Ford Focus
V 579 GHL
Adjust Gear Change
K. Blofeld
Mercedes
190D
K 233 LMH
Fit New Engine
A. C. Jones
Toyota Corolla
S 998 POP
12,000 Mile Service
M.
Pinkerton
Vauxhall
Vectra
H 285 WSD
MOT + Service
R. Turner
Rover 400
L 445 DDF
Fit New Starter
Motor
T. Smythe
Rover 200
N 378 FHB
Engine Tune
This is a:
Set
Bag
Sequence
If applicable, the tuple order is:
Helpful ?
Preferred
Sequencing
Yes/No/Doesn’t Matter
Reasons:
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
Can the tabular data be put into a relation ?
Yes/No
If not, how would you amend the relation so as to be able to represent
the tabular data ?
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
14
School of Computing, Engineering and Information Sciences
University of Northumbria
12
Train Departures from Newcastle Central Station
Time
Destination
Platform
12.00
Edinburgh
2
12.00
King’s Cross
4
12.07
South Shields
7
12.16
Liverpool
3
12.23
Bristol
4
12.30
Carlisle
8
12.30
King’s Cross
4
This is a:
Set
Bag
Sequence
If applicable, the tuple order is:
Helpful ?
Preferred
Sequencing
Yes/No/Doesn’t Matter
Reasons:
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
Can the tabular data be put into a relation ?
Yes/No
If not, how would you amend the relation so as to be able to represent
the tabular data ?
…………………………………………………………………………………
…………………………………………………………………………………
………………………………………
15