Link¨opings universitet Institutionen f¨or datavetenskap / Matematiska institutionen

advertisement
Linköpings universitet
Institutionen för datavetenskap / Matematiska institutionen
Christoph Kessler / Kaj Holmberg
Tentamen
TDDB56 DALGOPT-D Algoritmer och Optimering
9 april 2002, kl 8-13
Lokal: Kårallen
Examinator: Christoph Kessler
Jourhavande lärare:
Christoph Kessler (070-3666687, 013-282406), visiting at 09:30 and 11:30,
Kaj Holmberg ( 013-282867), visiting at 09:30 and 11:30
Visning: date/time to be announced on the course homepage
Hjälpmedel / Admitted material:
Miniräknare / pocket calculator
Engelsk-Svensk ordbok / Swedish-English dictionary
Kursböckerna DALG:
Lewis, Denenberg: Data Structures and Their Algorithms. Addison-Wesley, 1991.
Goodrich, Tamassia: Data Structures and Algorithms in Java. Wiley, 2001.
Årets kurslitteratur OPT:
Kombinatorisk optimering 2001.
Papadimitriou, Steiglitz: Combinatorial Optimization,
Kurslitteratur för TAOP13 (2001):
Linjär och ickelinjär optimering, Lundgren, Rönnqvist och Värbrand.
Flöden i nätverk och kombinatorisk optimering, Holmberg.
Kombinatorisk optimering II, Holmberg.
Utdrag ur Kombinatorisk Optimering, problem och algoritmer, Migdalas and Göthe-Lundgren.
Kurslitteratur för TAOP13 (2000):
Kombinatorisk Optimering, problem och algoritmer, Migdalas och Göthe-Lundgren.
1
General instructions
This exam has 7 assignments and 4 pages in total. Read all assignments carefully and completely
before you begin.
Use a separate sheet for each assignment. Mark each sheet on top with your name, personnummer,
and the course code (TDDB56).
You may answer in either English or Swedish.
Write clearly. Unreadable text will be ignored.
Be precise in your statements. Unprecise formulations may lead to a reduction of points.
Motivate clearly all statements and reasoning.
Explain calculations and solution procedures.
The assignments are not ordered according to difficulty.
If you use some result from the admitted literature that has not been part of the lectures, give a
reference (book title, page) or give an explanation.
One copy of each of the admitted course books Lewis/Denenberg and Goodrich/Tamassia is available
for inspection at the central tentavakt desk. Please don’t remove them from there.
1. (7p) You are given a skip list with elements, linked in increasing order of keys, and maximum node
.
height . We assume for simplicity that
In order to implement the ADT PriorityQueue with a skip list, you must (among others) provide an
implementation of the operation DeleteMin that removes a skip list item containing the minimum key
value from the list and returns a pointer to it.
(a) (2p) Give an implementation of SkipListDeleteMin
for a skip list in pseudocode that uses
as few comparisons and (next) pointer updates as possible.
Hint: You may assume that Header(L) gives a pointer to the (artificial) header node of a skip
list , and that height(i) gives the height of a skip list item .
(b) (1p) What is the worst-case complexity of your implementation (using asymptotic notation)?
(c) (0.5p) Assume that the minimum element being removed from the list has height . Give the
(exact) number of pointer updates of your implementation as an explicit term in (no asymptotic
notation).
(d) (2p) What is the expected number of pointer updates in your implementation, assuming that the
skiplist items had been inserted with heights chosen by the random coin throwing mechanism
as described in the lecture and both course books? (Give a calculation that results in an exact
number). Hence, what is the average case complexity (using asymptotic notation)?
Hint: You may find the series sum
, for
, useful.
! #"%$& (& ' *) & ,& + (e) (1.5p) Extend the skip list data structure so that it supports an implementation of findMax (finding the maximum key element without removing it) in constant time (no pseudocode required,
but be precise in your answer: which of the dictionary operations must be modified?).
2
1032 är tudelad om 54 5 4768 , 94;:< >= , samt ? 94 och @8? för alla
0 @A? .- 2 ./(Bågarna
54
går alltså från
till
.) Låt oss anta att det går en båge från varje nod i
till varje nod i .
94 är radindex
En fördel med tudelade grafer är att bågarna kan representeras med en matris, där 7?
är kolumnindex. Bågflöden
ges alltså av en matris C . Låt oss för enkelhets skull anta att
och @B?
9
4
denna matris är kvadratisk, dvs att D
DED DFHG . (Då är alltså D DIJKG .)
2. (17p)
En graf
L
(2p) a) Betrakta problemet att finna ett billigaste uppspännande träd, MST, i en oriktad tudelad graf med
bågkostnadsmatrisen . Beskriv hur Prims metod kan modifieras så att den tudelade strukturen
utnyttjas, dvs så att beräkningarna görs i matrisen. Ge metoden i algoritmform. Indata är endast
och matrisen .
G
L
(3p) b) Lös MST-problemet med metoden som beskrivs i uppgift a, för nedanstående kostnadsmatris.
(Problemet kan alternativt lösas med Prims eller Kruskals metod i standardutförande, men ger
då högst 2 poäng.) Åskådliggör tydligt stegen i metoden.
NOO Q R
U S
LM P JV TQ
S T YW XX
U Q
S VZ
R V
(3p) c) Betrakta
det
valensbegränsade
billigaste
uppspännande
träd-problemet,
VMST, som är det vanliga billigaste uppspännande träd-problemet MST, plus kravet att ingen nod får ha högre valens än . Tillhör igenkänningsversionen av problemet P? Är det NPfullständigt?
VMST kan lösas med en trädsökningsmetod som är mycket lik den som kan användas för handelsresandeproblemet. Beskriv likheter och skillnader. Lös exemplet med nedanstående kostnadsmatris och
med denna metod.
$
V$ M W J
UZ
S
(1p) d) Vad kan sägas om existensen av en Eulercykel resp Hamiltoncykel i en oriktad tudelad graf (för
olika värden på G )?
54 till ) med båg- och nodkapaciteter, dvs
(1p) e) Betrakta nu en riktad tudelad graf (riktning från
övre gränser för hur mycket flöde som får passera igenom varje båge samt igenom varje nod.
54 till nodmängden kan
Problemet att skicka så mycket flöde som möjligt från nodmängden
omformuleras till en vanligt maxflödesproblem. Visa hur.
4
(3p) f) Lös problemet beskrivet i uppgift e, för nedanstående kapacitetsdata. Nodkapaciteter: \
0 R R 0 Q , \ > R 0 R 0 S . Bågkapaciteter:
N Q _^ W
\] P V RQ JV Z .
J
94 nod 1 i
Börja med att skicka så mycket som möjligt tvärs över grafen, dvs från nod 1 i
, från nod 2 i 94 till nod 2 i , osv. (Detta första steg behöver ej motiveras.) Övergåtilldärefter
till en mer noggrant utförd maxflödesmetod. Ange minsnitt.
54 är källor och noderna i är
(1p) g) Minkostnadsflödesproblemet i en tudelad graf, där noderna i
N Q R
LM P [ TS
J
sänkor, kallas transportproblem. Detta problem kan lösas med en specialvariant av simplexmetoden för nätverk, anpassad till matrisformen. Ett transportproblem där varje källstyrka och
3
sänkstyrka är lika med 1 kallas tillordningsproblem. Uppenbarligen kan även detta problem
lösas med ovan nämnda variant av simplexmetoden. Ange en nackdel med att använda simplexmetoden för att lösa tillordningsproblemet.
(3p) h) Kappsäcksproblemet kan lösas med Dynamisk Programmering, vilket kan illustreras som ett
grafproblem. Beskriv den därvid uppkomna grafen samt ange om grafen är tudelad. Motivera.
(Här krävs ej att “alla” bågarna mellan de två nodmängderna finns, ej heller att de är lika stora.)
Har grafen för övrigt någon speciell struktur som bör/kan utnyttjas då problemet löses?
3. (3p) Let the set
`,bacJ 0 Q 0 V 0 S 0de0d Q 0d S 0d [gf
be given.
`
(a) (1p) Construct a heap storing the elements of (such that the minimum element appears at the
root): Draw the tree and the array representation.
(b) (1p) Show the corresponding picture after performing a DeleteMin operation.
(c) (1p) Show the corresponding picture after performing an Insert(1) in the original heap.
h $ 7 $
4. (2p) Insert the numbers 1, 12, 7, 11, 20, 14, 22, 9, 29 (in this order) in a hash table of size 10, using
open addressing with linear probing and the hash function
mod 10. (1.5p) How many probe
operations are now required for Lookup(29)? (0.5p)
5. (5p)
k i Ghl
G j) i G
G
m5Gn
items are sorted but nothing is known
(a) (3p) Given a table of length in which the first
items, how would you sort the entire table in
time in the worst case?
about the last
(no pseudocode is required, but justify your answer (calculation)).
i Gq?srto% and such that a table of length G can be
G ) opGn entries are known to be in order.
opGn
(b) (2p) Find a larger function
such that
sorted in linear time in the worst case when the first
How big can be?
o
6. (3p)
(1p) a) Varför förflyttar man sig enbart mellan närliggande baslösningar i simplexmetoden?
(1p) b) Hur ser man att komplementaritetsvillkoren är uppfyllda när man löser billigaste väg-problem?
(1p) a) På vilket sätt kan komplexiteten för att finna den väg mellan två givna noder som har lägst
kostnad bero på bågkostnaderna?
34
7. (3p) Given the following binary search tree:
22
(a) (0.5p) Is this tree a full binary tree? (justify your answer)
56
(b) (0.5p) Is this tree a complete binary tree? (justify your answer)
15
32
47
66
(c) (0.5p) Is this tree an AVL tree? (justify your answer)
(d) (1.5p) Give the sequences of keys resulting from a preorder, inorder 17
and postorder traversal of the tree.
43 51
52
4
Download