The Algorithm Design Manual Second Edition



Download 5,51 Mb.
Pdf ko'rish
bet87/488
Sana31.12.2021
Hajmi5,51 Mb.
#273936
1   ...   83   84   85   86   87   88   89   90   ...   488
Bog'liq
2008 Book TheAlgorithmDesignManual

be the length of the walk possible from an average vertex. Using the simplest

possible implementation, we could walk from each of the vertices to find the

largest remaining strip to report in O(kn) time. Repeating this for each of the

roughly n/k strips we extract yields an O(n

2

)-time implementation, which would



be hopelessly slow on a typical model of 20,000 triangles.

How could we speed this up? It seems wasteful to rewalk from each triangle

after deleting a single strip. We could maintain the lengths of all the possible

future strips in a data structure. However, whenever we peel off a strip, we must

update the lengths of all affected strips. These strips will be shortened because

they walked through a triangle that now no longer exists. There are two aspects of

such a data structure:

• Priority Queue – Since we were repeatedly identifying the longest remaining

strip, we needed a priority queue to store the strips ordered according to

length. The next strip to peel always sat at the top of the queue. Our priority

queue had to permit reducing the priority of arbitrary elements of the queue

whenever we updated the strip lengths to reflect what triangles were peeled



88

3 .


D A T A S T R U C T U R E S

Model name

Triangle count

Naive cost

Greedy cost

Greedy time

Diver

3,798


8,460

4,650


6.4 sec

Heads


4,157

10,588


4,749

9.9 sec


Framework

5,602


9,274

7,210


9.7 sec

Bart Simpson

9,654

24,934


11,676

20.5 sec


Enterprise

12,710


29,016

13,738


26.2 sec

Torus


20,000

40,000


20,200

272.7 sec

Jaw

75,842


104,203

95,020


136.2 sec

Figure 3.8: A comparison of the naive versus greedy heuristics for several triangular meshes

away. Because all of the strip lengths were bounded by a fairly small integer

(hardware constraints prevent any strip from having more than 256 vertices),

we used a bounded-height priority queue (an array of buckets shown in Figure

3.7


and described in Section

12.2


(page

373


)). An ordinary heap would also

have worked just fine.

To update the queue entry associated with each triangle, we needed to quickly

find where it was. This meant that we also needed a . . .



• Dictionary – For each triangle in the mesh, we needed to find where it was in

the queue. This meant storing a pointer to each triangle in a dictionary. By

integrating this dictionary with the priority queue, we built a data structure

capable of a wide range of operations.

Although there were various other complications, such as quickly recalculating

the length of the strips affected by the peeling, the key idea needed to obtain better

performance was to use the priority queue. Run time improved by several orders

of magnitude after employing this data structure.

How much better did the greedy heuristic do than the naive heuristic? Consider

the table in Figure

3.8

. In all cases, the greedy heuristic led to a set of strips that



cost less, as measured by the total size of the strips. The savings ranged from about

10% to 50%, which is quite remarkable since the greatest possible improvement

(going from three vertices per triangle down to one) yields a savings of only 66.6%.

After implementing the greedy heuristic with our priority queue data structure,

the program ran in O(n

· k) time, where is the number of triangles and is the

length of the average strip. Thus the torus, which consisted of a small number of

very long strips, took longer than the jaw, even though the latter contained over

three times as many triangles.

There are several lessons to be gleaned from this story. First, when working with

a large enough data set, only linear or near linear algorithms (say O(log n)) are

likely to be fast enough. Second, choosing the right data structure is often the key

to getting the time complexity down to this point. Finally, using smart heuristic




3 . 7

H A S H I N G A N D S T R I N G S



89

like greedy is likely to significantly improve quality over the naive approach. How

much the improvement will be can only be determined by experimentation.


Download 5,51 Mb.

Do'stlaringiz bilan baham:
1   ...   83   84   85   86   87   88   89   90   ...   488




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish