Accounting method (computer science)

In the field of analysis of algorithms in computer science, the accounting method is a method of amortized analysis based on accounting. The accounting method often gives a more intuitive account of the amortized cost of an operation than either aggregate analysis or the potential method. Note, however, that this does not guarantee such analysis will be immediately obvious; often, choosing the correct parameters for the accounting method requires as much knowledge of the problem and the complexity bounds one is attempting to prove as the other two methods.

The accounting method is most naturally suited for proving an O(1) bound on time. The method as explained here is for proving such a bound.

The method

A set of elementary operations which will be used in the algorithm is chosen and their costs are arbitrarily set to 1. The fact that the costs of these operations may differ in reality presents no difficulty in principle. What is important is that each elementary operation has a constant cost.

Each aggregate operation is assigned a "payment". The payment is intended to cover the cost of elementary operations needed to complete this particular operation, with some of the payment left over, placed in a pool to be used later.

The difficulty with problems that require amortized analysis is that, in general, some of the operations will require greater than constant cost. This means that no constant payment will be enough to cover the worst case cost of an operation, in and of itself. With proper selection of payment, however, this is no longer a difficulty; the expensive operations will only occur when there is sufficient payment in the pool to cover their costs.

Examples

A few examples will help to illustrate the use of the accounting method.

Table expansion

It is often necessary to create a table before it is known how much space is needed. One possible strategy is to double the size of the table when it is full. Here we will use the accounting method to show that the amortized cost of an insertion operation in such a table is O(1).

Before looking at the procedure in detail, we need some definitions. Let T be a table, E an element to insert, num(T) the number of elements in T, and size(T) the allocated size of T. We assume the existence of operations create_table(n), which creates an empty table of size n, for now assumed to be free, and elementary_insert(T,E), which inserts element E into a table T that already has space allocated, with a cost of 1.

The following pseudocode illustrates the table insertion procedure:

function table_insert(T, E)
    if num(T) = size(T)
        U := create_table(2 × size(T))
        for each F in T
            elementary_insert(U, F)
        T := U
    elementary_insert(T, E)

Without amortized analysis, the best bound we can show for n insert operations is O(n) — this is due to the loop at line 4 that performs num(T) elementary insertions.

For analysis using the accounting method, we assign a payment of 3 to each table insertion. Although the reason for this is not clear now, it will become clear during the course of the analysis.

Assume that initially the table is empty with size(T) = m. The first m insertions therefore do not require reallocation and only have cost 1 (for the elementary insert). Therefore, when num(T) = m, the pool has (3 - 1)×m = 2m.

Inserting element m + 1 requires reallocation of the table. Creating the new table on line 3 is free (for now). The loop on line 4 requires m elementary insertions, for a cost of m. Including the insertion on the last line, the total cost for this operation is m + 1. After this operation, the pool therefore has 2m + 3 - (m + 1) = m + 2.

Next, we add another m - 1 elements to the table. At this point the pool has m + 2 + 2×(m - 1) = 3m. Inserting an additional element (that is, element 2m + 1) can be seen to have cost 2m + 1 and a payment of 3. After this operation, the pool has 3m + 3 - (2m + 1) = m + 2. Note that this is the same amount as after inserting element m + 1. In fact, we can show that this will be the case for any number of reallocations.

It can now be made clear why the payment for an insertion is 3. 1 pays for the first insertion of the element, 1 pays for moving the element the next time the table is expanded, and 1 pays for moving an older element the next time the table is expanded. Intuitively, this explains why an element's contribution never "runs out" regardless of how many times the table is expanded: since the table is always doubled, the newest half always covers the cost of moving the oldest half.

We initially assumed that creating a table was free. In reality, creating a table of size n may be as expensive as O(n). Let us say that the cost of creating a table of size n is n. Does this new cost present a difficulty? Not really; it turns out we use the same method to show the amortized O(1) bounds. All we have to do is change the payment.

When a new table is created, there is an old table with m entries. The new table will be of size 2m. As long as the entries currently in the table have added enough to the pool to pay for creating the new table, we will be all right.

We cannot expect the first entries to help pay for the new table. Those entries already paid for the current table. We must then rely on the last entries to pay the cost . This means we must add to the payment for each entry, for a total payment of 3 + 4 = 7.

References

  • Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. Introduction to Algorithms, Second Edition. MIT Press and McGraw-Hill, 2001. ISBN 0-262-03293-7. Section 17.2: The accounting method, pp. 410–412.

Read other articles:

هذه المقالة يتيمة إذ تصل إليها مقالات أخرى قليلة جدًا. فضلًا، ساعد بإضافة وصلة إليها في مقالات متعلقة بها. (يونيو 2019) جانوس ناغي بالوف   معلومات شخصية الميلاد 2 أغسطس 1874[1][2]  الوفاة 18 نوفمبر 1919 (45 سنة)   بودابست  مواطنة المجر  الحياة العملية المهنة رسام  ...

 

Sinagoga Asquenazí de Estambulİstanbul Aşkenaz Sinagogu Vista de la sinagogaLocalizaciónPaís TurquíaDivisión Provincia de EstambulDirección Estambul TurquíaCoordenadas 41°01′31″N 28°58′30″E / 41.02521, 28.97509Información religiosaCulto JudaísmoHistoria del edificioInauguración 23 de septiembre de 1900Arquitecto G. J. CornaroDatos arquitectónicosTipo SinagogaEstilo Orientalista[editar datos en Wikidata] La Sinagoga Asquenazí de Estambul (...

 

موتور يحيي بلوردي موتوريحيي بلوردي  - قرية -  تقسيم إداري البلد  إيران المحافظة كرمان المقاطعة أرزوئیة الناحية الناحية المركزية القسم الريفي Arzuiyeh السكان معلومات أخرى التوقيت توقيت إيران (+3:30 غرينيتش) توقيت صيفي توقيت إيران (+4:30) تعديل مصدري - تعديل   موتور یحیی

Not to be confused with 2022 United States Senate elections in California. 2022 California State Senate election ← 2020 November 8, 2022 (2022-11-08) 2024 → 20 seats from even-numbered districts in the California State Senate21 seats needed for a majority   Majority party Minority party   Leader Toni Atkins Scott Wilk Party Democratic Republican Leader since March 21, 2018 January 20, 2021 Leader's seat 39th–San Diego 21st–Santa Cla...

 

زياد شعبو زياد شعبو   معلومات شخصية الاسم الكامل زياد بركات شعبو الميلاد 1 يناير 1979 (العمر 44 سنة)اللاذقية الطول 1.79 م (5 قدم 10 1⁄2 بوصة) مركز اللعب مهاجم الجنسية سوريا  الرقم 20 مسيرة الشباب سنوات فريق حطين المسيرة الاحترافية1 سنوات فريق م. (هـ.) 1994–2001 نادي حطين 20...

 

Steam cargo ship History United States NameKiowa NamesakeKiowa OwnerClyde Steamship Co. BuilderWilliam Cramp & Sons, Philadelphia Yard number321 Launched9 May 1903 Sponsored byMiss Elizabeth Milne Commissioned12 June 1903 Maiden voyage17 June 1903 HomeportNew York Identification US Official Number 161229 Call sign KSMN FateSank, 26 December 1903 General characteristics TypeCargo ship Tonnage 2,953 GRT[1] 2,256 NRT[1] Length291 ft 2 in (88.75 m) Bea...

Surah ke-39az-Zumar Rombongan-RombonganTeks ArabTerjemahan KemenagKlasifikasiMakkiyahNama lainal-Guraf (Kamar-Kamar)JuzJuz 23 (ayat 1-31) Juz 24 (ayat 32-75)Jumlah ruku8 rukuJumlah ayat75 ayatSurah Az-Zumar (Arab: الزمر, Rombongan-Rombongan) adalah surah ke-39 dalam al-Qur'an. Surah ini tergolong surah Makkiyah, terdiri atas 75 ayat. Dinamakan Az-Zumar yang berarti Rombongan-Rombongan karena kata Az-Zumar yang terdapat pada ayat 71 dan 73 pada surah ini. Dalam ayat-ayat tersebut diterang...

 

UK and US officer ranks compared Rank group General / flag officers Senior officers Junior officers Officer cadet NATO code OF-10 OF-9 OF-8 OF-7 OF-6 OF-5 OF-4 OF-3 OF-2 OF-1 OF(D) Student officer  British Army[1]vte Field marshal General Lieutenant-general Major-general Brigadier Colonel Lieutenant colonel Major Captain Lieutenant Second lieutenant Officer cadet  United States Army[2]vte Various General of the Army General Lieutenant general Major general Briga...

 

  لمعانٍ أخرى، طالع شارع محمد الخامس (توضيح). شارع محمد الخامسBoulevard Mohammed Vمعلومات عامةالموقع وسط المدينة - الدار البيضاءالبلد  المغرب الطول 3 كمالعرض 12 مأقرب محطة مترو محطات الأمم المتحدة، السوق المركزي، محمد الديوري، المقاومة، ساحة اليسير، الدار البيضاء المسافرينا...

Pour les autres articles nationaux ou selon les autres juridictions, voir Code de la route. Panneau de limitations de vitesse à l'entrée en Allemagne (vitesse sur autoroute conseillée) La réglementation de la circulation routière en Allemagne y est connue sous le nom de Straßenverkehrs-Ordnung (StVO)[1],[2]. Équivalent du Code de la route en France, Partie réglementaire, Livre 4: L'usage des voies. Selon les accords internationaux, les véhicules allemands qui se rendent à l'étrange...

 

Santa Ana, Westfassade Innenraum Gewölbe Die Kathedrale Santa Ana steht inmitten der Vegueta, dem ältesten Teil der Stadt Las Palmas de Gran Canaria. Der zweitürmige Bau ist die älteste und größte Kirche der Insel und Bischofskirche des Bistums Kanarische Inseln. Zur Kathedrale gehört das bedeutendste Archiv der Kanaren.[1] Inhaltsverzeichnis 1 Geschichte 2 Baustile 3 Innenraum 4 Ausstattung 5 Quellen 6 Einzelnachweise 7 Weblinks Geschichte 1497, kurz nach der Eroberung Gran Ca...

 

Christian military order Part of a series on theKnights TemplarTemplar Cross Poor Fellow-Soldiers ofChrist and of the Temple of Solomon Overview History Latin Rule Seal Grand Masters Members Trials and dissolution Councils Council of Troyes (1129) Council of Pisa (1135) Council of Vienne Papal bulls Omne datum optimum (1139) Milites Templi (1144) Militia Dei (1145) Pastoralis praeeminentiae (1307) Faciens misericordiam (1308) Vox in excelso (1312) Ad providam (1312) Locations Brittany England...

American politician Chargé d'AffairesCondy Raguet1st United States Ambassador to BrazilIn officeOctober 29, 1825 – April 16, 1827PresidentJohn Quincy AdamsPreceded byOffice establishedSucceeded byWilliam TudorMember of the Pennsylvania Senatefrom the 1st districtIn office1818–1821Preceded byMichael LeibSucceeded byRobert McMullin Personal detailsBornJanuary 28, 1784Philadelphia, Pennsylvania, United StatesDiedMarch 22, 1842 (aged 58)Philadelphia, Pennsylvania, United StatesPolit...

 

Berikut adalah garis waktu sejarah kota Jakarta, Indonesia Sebelum abad ke-19 Bagian dari seri mengenai Sejarah Indonesia Prasejarah Manusia Jawa 1.000.000 BP Manusia Flores 94.000–12.000 BP Bencana alam Toba 75.000 BP Kebudayaan Buni 400 SM Kerajaan Hindu-Buddha Kerajaan Kutai 400–1635 Kerajaan Tarumanagara 450–900 Kerajaan Kalingga 594–782 Kerajaan Melayu 671–1347 Kerajaan Sriwijaya 671–1028 Kerajaan Sunda 662–1579 Kerajaan Galuh 669–1482 Kerajaan...

 

2013 filmArmisticeTheatrical posterDirected byLuke MasseyWritten byLuke MasseyBenjamin ReadProduced byBilly BuddLeon DaviesStarringJoseph MorganMatt RyanAl WeaverWilliam TroughtonMusic byJonathan FletcherDistributed byDouble Dutch MediaRelease dates October 29, 2013 (2013-10-29) (Razor Reel) January 7, 2014 (2014-01-07) (United States) Armistice is a 2013 supernatural psychological thriller film about one man's fight to preserve his humanity and sanity ov...

Milan metro station GioiaGeneral informationLocationVia Melchiorre Gioia, MilanCoordinates45°29′05″N 9°11′43″E / 45.48472°N 9.19528°E / 45.48472; 9.19528Owned byAzienda Trasporti MilanesiPlatforms1Tracks2ConstructionStructure typeUndergroundAccessibleYesOther informationFare zoneSTIBM: Mi1[1]HistoryOpened12 July 1971; 52 years ago (1971-07-12)Services Preceding station Milan Metro Following station Garibaldi FStowards Assago or Abb...

 

Canadian television series This article is about the animated TV series. For the book series, see Grossology (books). GrossologyGenreActionAdventureComedyScience fantasyCreated bySylvia BranzeiDeveloped bySimon Racioppa & Richard ElliottVoices ofKrystal MeadowsMichael CohenM. Christian HeywoodPaul O'SullivanComposerPaul IntsonCountry of originCanadaNo. of seasons2No. of episodes52ProductionExecutive producersScott DyerDoug MurphyMichael YanoverSandra ItkoffProducerMicheal DecsiRunning tim...

 

International sporting eventAthletics at the1983 Pan American GamesTrack events100 mmenwomen200 mmenwomen400 mmenwomen800 mmenwomen1500 mmenwomen3000 mwomen5000 mmen10,000 mmen100 m hurdleswomen110 m hurdlesmen400 m hurdlesmenwomen3000 msteeplechasemen4×100 m relaymenwomen4×400 m relaymenwomenRoad eventsMarathonmen20 km walkmen50 km walkmenField eventsHigh jumpmenwomenPole vaultmenLong jumpmenwomenTriple jumpmenShot putmenwomenDiscus throwmenwomenHammer throwmenJavelin throwmenwomenCombined...

Association football match Football match2021 UEFA Champions League FinalMatch programme coverEvent2020–21 UEFA Champions League Manchester City Chelsea 0 1 Date29 May 2021 (2021-05-29)VenueEstádio do Dragão, PortoMan of the MatchN'Golo Kanté (Chelsea)[1]RefereeAntonio Mateu Lahoz (Spain)[2]Attendance14,110[3]WeatherClear night19 °C (66 °F)72% humidity[4]← 2020 2022 → The 2021 UEFA Champions League final was the final...

 

Duane è un nome proprio di persona inglese e irlandese maschile[1]. Indice 1 Varianti 2 Origine e diffusione 3 Onomastico 4 Persone 4.1 Variante Dwayne 4.2 Altre varianti 5 Il nome nelle arti 6 Note 7 Altri progetti Varianti Inglesi Maschili: Dewayne[1], Dwain[1], Dwayne[1], Dwaine, Dwane Femminili: Duana[1] Origine e diffusione Riprende l'omonimo cognome irlandese, forma anglicizzata del cognome gaelico Ó Dubhán, che significa discendente di...

 

Strategi Solo vs Squad di Free Fire: Cara Menang Mudah!