<?xml version="1.0" encoding="utf-8"?>
<!-- generator="FeedCreator 1.7.2-ppt DokuWiki" -->
<?xml-stylesheet href="http://massimo30.net/wiki/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel>
        <title>Massimo 30 - Wiki</title>
        <description></description>
        <link>http://massimo30.net/wiki/</link>
        <lastBuildDate>Thu, 09 Sep 2010 16:30:50 +0200</lastBuildDate>
        <generator>FeedCreator 1.7.2-ppt DokuWiki</generator>
        <image>
            <url>http://massimo30.net/wiki/lib/images/favicon.ico</url>
            <title>Massimo 30 - Wiki</title>
            <link>http://massimo30.net/wiki/</link>
        </image>
        <item>
            <title>indice - versione precedente ripristinata</title>
            <link>http://massimo30.net/wiki/indice?rev=1278311864&amp;do=diff</link>
            <description>
&lt;p&gt;
Questa è la pagina principale della wiki di &lt;a href=&quot;http://massimo30.net/&quot; class=&quot;urlextern&quot; title=&quot;http://massimo30.net/&quot;&gt;Massimo 30&lt;/a&gt;, una struttura di incubazione per alcuni contenuti la cui produzione richiede la partecipazione simultanea di più utenti o per i quali siano richiesti strumenti di non facile gestione per l&amp;#039;utente medio (ad esempio, è possibile scrivere formule matematiche con la sintassi di &lt;span class=&quot;math&quot;&gt;\TeX&lt;/span&gt; senza che l&amp;#039;autore debba averlo installato sul proprio computer).
&lt;/p&gt;

&lt;p&gt;
Tutti i contenuti possono essere visualizzati liberamente online, ma non possono essere modificati se non da un gruppo di utenti molto ristretto, scelto dagli amministratori volta per volta; data la natura estremamente volatile degli stessi, è altamente probabile che, nel momento in cui vengono visualizzati, siano contenuti degli errori che verranno corretti dopo pochissimo tempo. Gli esiti del lavoro collaborativo saranno resi disponibili, in futuro, a tutti gli utenti della community, tramite apposite entry della sezione &lt;a href=&quot;http://download.massimo30.net&quot; class=&quot;urlextern&quot; title=&quot;http://download.massimo30.net&quot;&gt;Download&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
Al momento ospitiamo progetti collaborativi per:

&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;http://massimo30.net/wiki/programmazione_2/indice&quot; class=&quot;wikilink1&quot; title=&quot;programmazione_2:indice&quot;&gt;Programmazione 2&lt;/a&gt; (corso tenuto dall&amp;#039;Ing. &lt;a href=&quot;http://www.csai.unipa.it/dip/&quot; class=&quot;urlextern&quot; title=&quot;http://www.csai.unipa.it/dip/&quot;&gt;Daniele Peri&lt;/a&gt; presso la sede di Palermo della &lt;a href=&quot;http://corsi.dinfo.unipa.it/&quot; class=&quot;urlextern&quot; title=&quot;http://corsi.dinfo.unipa.it/&quot;&gt;facoltà di Ingegneria Informatica&lt;/a&gt; dell&amp;#039;&lt;a href=&quot;http://www.unipa.it/&quot; class=&quot;urlextern&quot; title=&quot;http://www.unipa.it/&quot;&gt;Università di Palermo&lt;/a&gt;): cerchiamo di mettere insieme gli appunti disponibili onde pervenire ad un testo di studio organico onnicomprensivo. &lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;

    &lt;strong&gt;N.B.&lt;/strong&gt; Il corso è stato tenuto dall&amp;#039;Ing. Peri &lt;strong&gt;fino all&amp;#039;anno accademico 2008/2009&lt;/strong&gt;. Il materiale pubblicato, per quanto comunque utile, &lt;em class=&quot;u&quot;&gt;non è indicativo del contenuto del corso tenuto in anni successivi&lt;/em&gt;. 

&lt;/p&gt;
</description>
            <author>gsdefender</author>
            <pubDate>Mon, 05 Jul 2010 08:37:44 +0200</pubDate>
        </item>
        <item>
            <title>programmazione_2:grafi:indice</title>
            <link>http://massimo30.net/wiki/programmazione_2/grafi/indice?rev=1265223810&amp;do=diff</link>
            <description></description>
            <author>gsdefender</author>
        <category>programmazione_2:grafi</category>
            <pubDate>Wed, 03 Feb 2010 20:03:30 +0200</pubDate>
        </item>
        <item>
            <title>programmazione_2:ordinamento:algoritmi_non_basati_sui_confronti:radixsort</title>
            <link>http://massimo30.net/wiki/programmazione_2/ordinamento/algoritmi_non_basati_sui_confronti/radixsort?rev=1264304736&amp;do=diff</link>
            <description>&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;math.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;stdlib.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;quot;queue.h&amp;quot;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;stdio.h&amp;gt;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; radixsort&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Record&lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; a&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; n&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; k&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; base&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;register&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; t&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; iterations&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;log&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;k&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;/&lt;/span&gt;log&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;base&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;t&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;t&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt;iterations&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;t&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
	bucketsort&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;a&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;t&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;base&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; bucketsort&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Record&lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; records&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; n&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; t&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; base&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
     &lt;span class=&quot;kw4&quot;&gt;register&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; i&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
     Queue&lt;span class=&quot;sy0&quot;&gt;**&lt;/span&gt; queues&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;calloc&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;base&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Queue&lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
     &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt;base&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
     	queues&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;init_queue&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	enqueue_records&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;records&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;queues&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;t&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;base&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	dequeue_records&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;records&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;queues&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;base&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	free&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;queues&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; enqueue_records&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Record&lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; record_array&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;Queue&lt;span class=&quot;sy0&quot;&gt;**&lt;/span&gt; queue_array&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; n&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; t&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; base&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span class=&quot;kw4&quot;&gt;register&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; i&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt;n&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
		&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; digit&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;t_digit&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;record_array&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;key&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;t&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;base&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		queue_array&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;digit&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;enqueue_record&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;queue_array&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;digit&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;record_array&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; dequeue_records&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Record&lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; record_array&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;Queue&lt;span class=&quot;sy0&quot;&gt;**&lt;/span&gt; queue_array&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; base&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;kw4&quot;&gt;register&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; i&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;z&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt;base&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;queue_is_empty&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;queue_array&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt; FALSE&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
		record_array&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;z&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;dequeue&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;queue_array&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
		queue_free&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;queue_array&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; t_digit&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; number&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; t&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; base&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;number&lt;span class=&quot;sy0&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;pow&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;base&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;t&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;%&lt;/span&gt;base&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
Il radix sort è un algoritmo di ordinamento che permette di ordinare un insieme di n record con chiavi intere comprese tra 1 e k con un costo computazionale pari a 
&lt;span class=&quot;math&quot;&gt;O(n(1+\frac{\log k}{\log n})).&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;
L’algoritmo utilizza un altro algoritmo di ordinamento per chiavi intere, chiamato Bucketsort; in particolare, il Radix sort effettua un numero di chiamata di Bucketsort pari al numero di cifre in cui si può esprimere la chiave più grande della collezione in una data base. Il radix ordina le chiavi a partire dalla loro cifra meno significativa.
Quest&amp;#039;approccio bottom-up, è preferibile al classico approccio top-down, in quanto se pensassimo di ordinare ricorsivamente numeri aventi la stessa cifra iniziale, ci troveremmo ad operare su sottoproblemi di dimensione molto diversa l&amp;#039;uno dall&amp;#039;altro.
L&amp;#039;algoritmo eredita la proprietà di stabilità dal Bucketsort essendo quest&amp;#039;ultimo invocato per ogni cifra i-esima.
&lt;/p&gt;

&lt;p&gt;
L&amp;#039;algoritmo esegue &lt;span class=&quot;math&quot;&gt;\log_{k}{n}&lt;/span&gt; volte una chiamata a BucketSort di costo n, partendo dall&amp;#039;assunzione &lt;span class=&quot;math&quot;&gt;b=\Theta(n)&lt;/span&gt; (dove b è la base numerica) e usando la proprietà di cambiamento di base dell&amp;#039;algoritmo arriviamo al costo d&amp;#039;esecuzione  &lt;span class=&quot;math&quot;&gt;O(n(\frac{\log(k)}{\log(n)}))&lt;/span&gt;;
ma poichè anche per k«n è almeno eseguita una lettura degli n elementi dell&amp;#039;istanza, aggiungiamo n al costo, che risulta quindi essere:
&lt;span class=&quot;math&quot;&gt;O(n(1+\frac{\log k}{\log n}))&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;
Nell’implementazione in C dell’algoritmo si è fatto uso di una coda disponibile tra le implementazioni della sezione strutture dati.

&lt;/p&gt;
</description>
            <author>ordeal</author>
        <category>programmazione_2:ordinamento:algoritmi_non_basati_sui_confronti</category>
            <pubDate>Sun, 24 Jan 2010 04:45:36 +0200</pubDate>
        </item>
        <item>
            <title>programmazione_2:tavole_hash:concatenazione</title>
            <link>http://massimo30.net/wiki/programmazione_2/tavole_hash/concatenazione?rev=1251327330&amp;do=diff</link>
            <description>
&lt;p&gt;
N.B. Per la concatenazione si utilizzano liste.
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;sc_ht_list.h&lt;/strong&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;#ifndef _SC_HT_LIST_H
#define _SC_HT_LIST_H

#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;

typedef void* void_ptr;

typedef struct sc_ht_node_t {
	void_ptr key, value;	/*chiave e valore*/
	size_t key_size, value_size; /*dimensione della chiave e del valore*/
	struct sc_ht_node_t * prev;    /*puntatore al nodo precedente*/
	struct sc_ht_node_t * next;    /*puntatore al nodo successivo*/
} sc_ht_node;

typedef sc_ht_node* sc_ht_node_ptr;

typedef struct sc_ht_list_t {
	unsigned int items;  /*numero di elementi della lista (&amp;gt;=0) */
	sc_ht_node_ptr first;  /*puntatore al primo elemento della lista */
} sc_ht_list;

typedef sc_ht_list* sc_ht_list_ptr;
typedef enum { CHAR_PTR, INT_PTR, UINT_PTR, LONG_PTR, ULONG_PTR } type_id;

sc_ht_node_ptr sc_ht_node_alloc(size_t, size_t);      /* alloca la memoria necessaria ad un nodo vuoto (usato internamente da sc_ht_list_insert(sc_ht_list_ptr, void_ptr, void_ptr)) */
void sc_ht_node_free(sc_ht_node_ptr);   /* libera la memoria allocata per il nodo passato come argomento */
sc_ht_list_ptr sc_ht_list_alloc();      /* alloca la memoria necessaria ad una lista vuota */
void sc_ht_list_free(sc_ht_list_ptr);   /* libera la memoria allocata per la lista passata come argomento */
sc_ht_list_ptr sc_ht_list_insert(sc_ht_list_ptr, void_ptr, size_t, void_ptr, size_t); /* inserisce una coppia chiave-valore in cima alla lista */
void_ptr sc_ht_list_search(sc_ht_list_ptr, void_ptr);  /*cerca un valore, data una chiave, in una lista */
sc_ht_list_ptr sc_ht_list_delete(sc_ht_list_ptr, void_ptr); /*cancella una coppia chiave-valore da una lista */
void sc_ht_list_print(sc_ht_list_ptr l, type_id t); /* stampa il contenuto di una lista nel formato chiave=valore, seguita da una freccia se c&amp;#039;è un elemento successivo.*/

#endif&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;sc_ht.h&lt;/strong&gt;

&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;#ifndef _SC_HT_H
#define _SC_HT_H

#include &amp;lt;stdio.h&amp;gt;
#include &amp;quot;sc_ht_list.h&amp;quot;

typedef sc_ht_list_ptr* sc_ht_table_ptr; /* Un vettore di liste è una hash table */

typedef struct _sc_ht_t {
	sc_ht_table_ptr table;
	uint items;
} sc_ht;

typedef sc_ht* sc_ht_ptr;

typedef unsigned int uint;

int hash(void_ptr, uint, type_id); /* Calcola l&amp;#039;hash della chiave fornita */
sc_ht_ptr sc_ht_alloc(uint); /* Alloca memoria per una tabella hash */
void sc_ht_free(sc_ht_ptr); /* Libera la memoria allocata per la tabella hash passata come argomento */
void _sc_ht_insert(sc_ht_ptr, void_ptr, size_t, void_ptr, size_t, type_id); /* Inserisce una coppia chiave=valore in una tabella hash */
void sc_ht_delete(sc_ht_ptr, void_ptr, type_id); /* Cancella, data la chiave, anche il corrispondente valore dalla tabella hash */
void_ptr sc_ht_search(sc_ht_ptr, void_ptr, type_id); /* Cerca l&amp;#039;elemento corrispondente alla chiave data nella tabella: restituisce NULL se la chiave non viene trovata */
void sc_ht_print(sc_ht_ptr, type_id); /* Stampa il contenuto della tabella */

/* Lunghezza del vettore */
#define sc_ht_insert_c_string(a, b, c) _sc_ht_insert(a, b, (1+(strlen(b))), c, (1+(strlen(c))), CHAR_PTR)

#endif&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;sc_ht_list.c&lt;/strong&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;#include &amp;quot;sc_ht_list.h&amp;quot;

sc_ht_node_ptr sc_ht_node_alloc(size_t ks, size_t vs)
{
	sc_ht_node_ptr n=(sc_ht_node_ptr)(calloc(1, sizeof(sc_ht_node)));  /*Memoria per l&amp;#039;intera struttura */

	if(n &amp;amp;&amp;amp; (vs&amp;gt;0) &amp;amp;&amp;amp; (ks&amp;gt;0))
	{
		n-&amp;gt;key=calloc(1, vs); /*Memoria per la chiave */
		n-&amp;gt;value=calloc(1, ks); /*Memoria per il valore */
		n-&amp;gt;key_size=ks;
		n-&amp;gt;value_size=vs;
		n-&amp;gt;next=NULL; /* Non c&amp;#039;è alcun elemento successivo o precedente un nodo staccato */
		n-&amp;gt;prev=NULL;
	}

	return n;
}

void sc_ht_node_free(sc_ht_node_ptr n)
{
    if(n)
    {
	if(n-&amp;gt;next) n-&amp;gt;next-&amp;gt;prev=n-&amp;gt;prev; /* Se non ci troviamo alla fine della lista, L&amp;#039;elemento che precede il nodo che segue quello corrente sarà quello che precede il nodo corrente */
	if(n-&amp;gt;prev) n-&amp;gt;prev-&amp;gt;next=n-&amp;gt;next;  /* L&amp;#039;elemento che segue il nodo che precede quello corrente sarà quello che segue il nodo corrente */
 	free(n-&amp;gt;value);
	free(n-&amp;gt;key);
	free((void*)n);
    }
}

sc_ht_list_ptr sc_ht_list_alloc()
{
	sc_ht_list_ptr l=(sc_ht_list_ptr)(calloc(1, sizeof(sc_ht_list))); /*Memoria per la lista: spazio per numero degli elementi e puntatore al primo */

	if(l)
	{
		l-&amp;gt;items=0;
		l-&amp;gt;first=NULL;
	}

	return l;
}

void sc_ht_list_free(sc_ht_list_ptr l)
{	
    sc_ht_node_ptr _n=l-&amp;gt;first; /* Puntatore alla testa della lista */
	
    if(_n) /* Se il puntatore è valido */
    {
	    while(_n-&amp;gt;next) _n=_n-&amp;gt;next; /* Arriviamo alla fine della lista, */

	    while(_n-&amp;gt;prev)	 /* quindi retrocediamo di un nodo alla volta liberando la memoria. */
	    {			 /* (sarebbe stato più efficiente tenere un puntatore all&amp;#039;ultimo elemento della lista) */
		_n=_n-&amp;gt;prev;
		 sc_ht_node_free(_n-&amp;gt;next);
		 l-&amp;gt;items--;
	    }	
	    free((void*)l);
    }
}

sc_ht_list_ptr sc_ht_list_insert(sc_ht_list_ptr l, void_ptr k, size_t ks, void_ptr v, size_t vs)
{
	sc_ht_node_ptr _n=NULL;

	if(v &amp;amp;&amp;amp; l &amp;amp;&amp;amp; k)
	{
		_n=sc_ht_node_alloc(ks, vs);  /* Alloco memoria per il nodo */
		if(_n) /* Allocazione avvenuta */
		{
			memcpy(_n-&amp;gt;key, k, ks); /* Copio chiave e valore nelle loro locazioni */
			memcpy(_n-&amp;gt;value, v, vs);
			_n-&amp;gt;prev=NULL; /* Inseriamo in testa: un nuovo nodo sarà sempre il primo */
			_n-&amp;gt;next=l-&amp;gt;first; /* Dopo il nuovo nodo ci sarà quello che era il primo fino all&amp;#039;esecuzione dell&amp;#039;operazione di insert */
			if(l-&amp;gt;first) l-&amp;gt;first-&amp;gt;prev=_n;  /* Se il nuovo nodo non è l&amp;#039;unico nodo della lista, va aggiornato anche il puntatore al precedente*/
			l-&amp;gt;first=_n; /* Colleghiamo in testa */
			l-&amp;gt;items++; /* Un nodo in più */
		}
	}

	return l;
}

void_ptr sc_ht_list_search(sc_ht_list_ptr l, void_ptr k)
{
	unsigned int _i = 0;
	sc_ht_node_ptr _n=l-&amp;gt;first; /*Puntatore al puntatore alla testa */

	if(l &amp;amp;&amp;amp; k)
	{
		while(memcmp(_n-&amp;gt;key,k,_n-&amp;gt;key_size)!=0 &amp;amp;&amp;amp; _i&amp;lt;l-&amp;gt;items) /* Finchè le chiavi non corrispondono... */
		{
			if(_n-&amp;gt;next)  /* Se c&amp;#039;è un nodo successivo, andiamoci */
			{
				_n=_n-&amp;gt;next;
				_i++;
			}
			else /* Siamo all&amp;#039;ultimo nodo, l&amp;#039;elemento non c&amp;#039;è */
				return NULL;
		}
		
		return _n-&amp;gt;value; 
	}
	return NULL; /* Per sicurezza */
}

sc_ht_list_ptr sc_ht_list_delete(sc_ht_list_ptr l, void_ptr k)
{
	sc_ht_node_ptr _n=l-&amp;gt;first; /* Puntatore al puntatore alla testa */
	unsigned int _i=0;

	if(k &amp;amp;&amp;amp; l)
	{
		while(memcmp(_n-&amp;gt;key,k,_n-&amp;gt;key_size)!=0 &amp;amp;&amp;amp; _i&amp;lt;l-&amp;gt;items) /* Finchè le chiavi non corrispondono... */
		{
			if(_n-&amp;gt;next)  /* Se c&amp;#039;è un nodo successivo, andiamoci */
			{
				_n=_n-&amp;gt;next;
				_i++;
			}
			else /* Siamo all&amp;#039;ultimo nodo, l&amp;#039;elemento non c&amp;#039;è */
				return l;
		}
		sc_ht_node_free(_n);
		l-&amp;gt;items--; /* C&amp;#039;è un elemento in meno. */
	}	
	return l;
}

void sc_ht_list_print(sc_ht_list_ptr l, type_id t)
{
	unsigned int _i=0;
	sc_ht_node_ptr _n=l-&amp;gt;first;

	if(l)
	{
		for(_i=0; _i&amp;lt;l-&amp;gt;items &amp;amp;&amp;amp; _n!=NULL; _i++)
		{
			switch(t)
			{
				case CHAR_PTR: printf(&amp;quot;%s=%s&amp;quot;, (char*)(_n-&amp;gt;key), (char*)(_n-&amp;gt;value)); break;
				case INT_PTR: printf(&amp;quot;%d=%d&amp;quot;, *(int*)(_n-&amp;gt;key), *(int*)(_n-&amp;gt;value)); break;
				case UINT_PTR: printf(&amp;quot;%u=%u&amp;quot;, *(unsigned int*)(_n-&amp;gt;key), *(unsigned int*)(_n-&amp;gt;value)); break;
	    /* Nota: richiedono compatibilità C99.
	     *			case LONG_PTR: printf(&amp;quot;%l=%l&amp;quot;, *(long*)(_n-&amp;gt;key), *(long*)(_n-&amp;gt;value)); break;
	     *			case ULONG_PTR: printf(&amp;quot;%ul=%ul&amp;quot;, *(unsigned long*)(_n-&amp;gt;key), *(unsigned long*)(_n-&amp;gt;value)); break;				 
	    */
				default: break;
			}
			_n=_n-&amp;gt;next;
			if(_n) printf(&amp;quot; =&amp;gt; &amp;quot;);
			else break;
		}
		printf(&amp;quot;\n&amp;quot;);
	}
}&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;sc_ht.c&lt;/strong&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;#include &amp;quot;sc_ht.h&amp;quot;

/* Avendo adottato una tipologia di progettazione bottom-up, tutte le funzioni di gestione
 * della lista si riducono a poco più che wrapper. Infatti, una hash table sarà un vettore
 * di liste, per il quale.
 *
 * 1) Si individua la posizione utile, richiamando la funzione hash(chiave, tipo_della_chiave)
 * 2) Si verifica che tabella, chiave, valore ed hash siano ammissibili
 * 3) Si richiama la funzione implementata per una singola lista.
 * 4) Si restituisce (se necessario) il risultato all&amp;#039;utente.
 *
 * L&amp;#039;unica funzione su cui occorre dire qualcosa è hash(chiave, tipo_della_chiave). Vedere 
 * più in basso.
*/

void _sc_ht_insert(sc_ht_ptr ht, void_ptr k, size_t ks, void_ptr e, size_t es, type_id t)
{
	int index=0;
	
	if (ht &amp;amp;&amp;amp; e &amp;amp;&amp;amp; (es&amp;gt;0) &amp;amp;&amp;amp; k &amp;amp;&amp;amp; (ks&amp;gt;0))
	{
		index=hash(k, ht-&amp;gt;items, t);
		if(index&amp;gt;=0) ht-&amp;gt;table[index] = sc_ht_list_insert(ht-&amp;gt;table[index], e, es, k, ks);
	}
}

void sc_ht_delete(sc_ht_ptr ht, void_ptr k, type_id t)
{
	int index=0;
	
	if(ht &amp;amp;&amp;amp; k)
	{	
		index=hash(k, ht-&amp;gt;items, t);
		if(index&amp;gt;=0) ht-&amp;gt;table[index] = sc_ht_list_delete(ht-&amp;gt;table[index], k);
	}
}

void_ptr sc_ht_search(sc_ht_ptr ht, void_ptr k, type_id t)
{
	int index=0;

	if(ht &amp;amp;&amp;amp; k)
	{
		index=hash(k, ht-&amp;gt;items, t);
		if(index&amp;gt;=0) return sc_ht_list_search(ht-&amp;gt;table[index], k);
	}

	return NULL;
}

sc_ht_table_ptr sc_ht_table_alloc(uint m)
{
	unsigned int i=0;
	sc_ht_table_ptr t=NULL;

	if(m&amp;gt;0)
	{
		t=(sc_ht_table_ptr)(calloc(m, sizeof(sc_ht_list)));

		if(t)
		{
			for(i=0;i&amp;lt;m;i++) t[i]=sc_ht_list_alloc();
		}
	}

	return t;
}

sc_ht_ptr sc_ht_alloc(uint m)
{
	sc_ht_ptr ht = NULL;

	if(m&amp;gt;0)
	{
		ht=(sc_ht_ptr)(calloc(1, sizeof(sc_ht)));
		
		if(ht)
		{
			ht-&amp;gt;items=m;
			ht-&amp;gt;table=sc_ht_table_alloc(ht-&amp;gt;items);
			if(!ht-&amp;gt;table) sc_ht_free(ht);
		}
	}

	return ht;
}

void sc_ht_free(sc_ht_ptr ht)
{
    unsigned int i=0;
    
    if(ht)
    {
	for(i=0;i&amp;lt;ht-&amp;gt;items;i++) sc_ht_list_free(ht-&amp;gt;table[i]);
	ht-&amp;gt;items=0;
	free(ht-&amp;gt;table);
	free(ht);
    }
}

int hash(void_ptr k, uint m, type_id t)
{
/* La funzione di hashing adottata è molto semplice (e primitiva): [chiave] modulo M. M è prefissato
 * con una direttiva di preprocessore e deve essere abbastanza lontano da una potenza di 2
 *
 * Quello di cui si occupa questa funzione è essenzialmente di effettuare correttamente il casting
 * della chiave, che è un puntatore a void, rendendo possibile la dereferenziazione e quindi l&amp;#039;operazione
 * di modulo.
*/
	if(k)
	{
		switch(t)
		{
			case INT_PTR: return *((int*)k)%m; break;
			case UINT_PTR: return *((unsigned int*)k)%m; break;
			case LONG_PTR: return *((long*)k)%m;  break;
			case ULONG_PTR: return *((unsigned long*)k)%m; break;
			case CHAR_PTR: return (int)(*(char*)k)%m; break;
			default: break;
		}
	}
	return -1; /* Hash non valido: le posizioni di un array cominciano da 0, per cui si saprà che c&amp;#039;è stato un errore. */
}

void sc_ht_print(sc_ht_ptr ht, type_id t)
{
	unsigned int i = 0;

	if(ht)
	{
		for(i=0;i&amp;lt;ht-&amp;gt;items;i++) 
		{
			printf(&amp;quot;[%d] &amp;quot;, i);
			sc_ht_list_print(ht-&amp;gt;table[i], t);			
		}
	}
}&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;main.c&lt;/strong&gt;

&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;quot;sc_ht.h&amp;quot;

int main()
{
	sc_ht_ptr ht=NULL;
	printf(&amp;quot;Alloco memoria per la tabella:\n&amp;quot;);
	ht=sc_ht_alloc(80);
	printf(&amp;quot;Inserimento nella tabella:\n\nchiave: ABCDEFGHIJKLMNOPQRSTUVWXYZ\nvalore: PRECIPITEVOLISSIMEVOLMENTE\n&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;A&amp;quot;, &amp;quot;P&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;B&amp;quot;, &amp;quot;R&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;C&amp;quot;, &amp;quot;E&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;D&amp;quot;, &amp;quot;C&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;E&amp;quot;, &amp;quot;I&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;F&amp;quot;, &amp;quot;P&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;G&amp;quot;, &amp;quot;I&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;H&amp;quot;, &amp;quot;T&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;I&amp;quot;, &amp;quot;E&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;J&amp;quot;, &amp;quot;V&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;K&amp;quot;, &amp;quot;O&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;L&amp;quot;, &amp;quot;L&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;M&amp;quot;, &amp;quot;I&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;N&amp;quot;, &amp;quot;S&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;O&amp;quot;, &amp;quot;S&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;P&amp;quot;, &amp;quot;I&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;Q&amp;quot;, &amp;quot;M&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;R&amp;quot;, &amp;quot;E&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;S&amp;quot;, &amp;quot;V&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;T&amp;quot;, &amp;quot;O&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;U&amp;quot;, &amp;quot;L&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;V&amp;quot;, &amp;quot;M&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;W&amp;quot;, &amp;quot;E&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;X&amp;quot;, &amp;quot;N&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;Y&amp;quot;, &amp;quot;T&amp;quot;);
	sc_ht_insert_c_string(ht, &amp;quot;Z&amp;quot;, &amp;quot;E&amp;quot;);
	printf(&amp;quot;\nStampa della struttura della tabella\n&amp;quot;);
	sc_ht_print(ht, CHAR_PTR);
	printf(&amp;quot;\nRicerca del valore corrispondente alla chiave O: &amp;quot;);
	printf(&amp;quot;%s\n&amp;quot;, (char*)sc_ht_search(ht, (void_ptr)&amp;quot;O&amp;quot;, CHAR_PTR));
	printf(&amp;quot;\nRimozione del valore corrispondente alla chiave O.&amp;quot;);
	sc_ht_delete(ht,(void_ptr)&amp;quot;O&amp;quot;, CHAR_PTR);
	printf(&amp;quot;\nRicerca del valore corrispondente alla chiave O: &amp;quot;);
	if(sc_ht_search(ht, (void_ptr)&amp;quot;O&amp;quot;, CHAR_PTR))
		printf(&amp;quot;%s\n&amp;quot;, (char*)sc_ht_search(ht, (void_ptr)&amp;quot;O&amp;quot;, CHAR_PTR));
	else
		printf(&amp;quot;NON TROVATO\n&amp;quot;);
	printf(&amp;quot;\nStampa della struttura della tabella\n&amp;quot;);
	sc_ht_print(ht, CHAR_PTR);
	printf(&amp;quot;\nLibero la memoria allocata per la tabella\n&amp;quot;);
	sc_ht_free(ht);
	return 0;
}&lt;/pre&gt;
</description>
            <author>gsdefender</author>
        <category>programmazione_2:tavole_hash</category>
            <pubDate>Thu, 27 Aug 2009 00:55:30 +0200</pubDate>
        </item>
        <item>
            <title>programmazione_2:tavole_hash:indirizzamento_aperto</title>
            <link>http://massimo30.net/wiki/programmazione_2/tavole_hash/indirizzamento_aperto?rev=1251327057&amp;do=diff</link>
            <description>
&lt;p&gt;
&lt;strong&gt;oa_ht.h&lt;/strong&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;#ifndef _OA_HT_H
#define _OA_HT_H

#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;

typedef unsigned int uint;
typedef void* void_ptr;
typedef enum { true=0, false=1 } boolean;
typedef enum { CHAR_PTR, INT_PTR, UINT_PTR, LONG_PTR, ULONG_PTR } type_id;

typedef struct _oa_ht_item_t {
	void_ptr key, value;
	size_t key_size, value_size;
} oa_ht_item_t;

typedef oa_ht_item_t* oa_ht_item_ptr;
typedef oa_ht_item_ptr* oa_ht_table_ptr;

typedef struct _oa_ht_t {
	uint items;
	oa_ht_table_ptr table;
} oa_ht;

typedef oa_ht* oa_ht_ptr;

int hash(void_ptr, uint, uint, type_id);
int _oa_ht_insert(oa_ht_ptr, void_ptr, size_t, void_ptr, size_t, type_id);
int _oa_ht_delete(oa_ht_ptr ht, void_ptr k, type_id t);
oa_ht_ptr oa_ht_alloc(uint);
void_ptr _oa_ht_search(oa_ht_ptr, void_ptr, type_id);
void oa_ht_print(oa_ht_ptr ht, type_id);
void oa_ht_free(oa_ht_ptr);
boolean oa_ht_is_cell_free(oa_ht_item_ptr);
boolean oa_ht_was_cell_emptied(oa_ht_item_ptr);

#define CANC ((char*)&amp;quot;[[CANCELLATO]]&amp;quot;)
#define CANC_SIZE (1+strlen(CANC))

#define oa_ht_insert_c_string(a, b, c) _oa_ht_insert(a, (char*)b, (1+strlen(b)), (char*)c, (1+strlen(c)), CHAR_PTR)
#define oa_ht_search_c_string(a, b) (char*)_oa_ht_search(a, b, CHAR_PTR)
#define oa_ht_delete_c_string(a, b) _oa_ht_delete(a, (char*)b, CHAR_PTR)

#endif&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;oa_ht.c&lt;/strong&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;#include &amp;quot;oa_ht.h&amp;quot;

/* Alloca memoria per un elemento del vettore */

oa_ht_item_ptr oa_ht_item_alloc()
{
	oa_ht_item_ptr i=(oa_ht_item_ptr)(calloc(1, sizeof(oa_ht_item_t)));

	if(i)
	{
		i-&amp;gt;key=i-&amp;gt;value=NULL;	
		i-&amp;gt;key_size=i-&amp;gt;value_size=0;
	}

	return i;
}

/* Libera la memoria occupata da un elemento del vettore */

void oa_ht_item_free(oa_ht_item_ptr i)
{
	if(i)
	{
		if(i-&amp;gt;key) free(i-&amp;gt;key);
		if(i-&amp;gt;value) free(i-&amp;gt;value);
		i-&amp;gt;key_size=i-&amp;gt;value_size=0;
		free(i);
	}
}

void oa_ht_table_free(oa_ht_table_ptr t, uint i)
{
	uint j=0;

	if(t &amp;amp;&amp;amp; (i&amp;gt;0))
	{
		for(j=0;j&amp;lt;i;j++) oa_ht_item_free(t[j]);
		free(t);
	}
}

oa_ht_table_ptr oa_ht_table_alloc(uint i)
{
	oa_ht_table_ptr t=NULL;
	uint j=0;

	if(i&amp;gt;0) 
	{
		t=(oa_ht_table_ptr)(calloc(i, sizeof(oa_ht_item_t)));
		if(t) {	for(j=0;j&amp;lt;i;j++) t[j]=oa_ht_item_alloc(); }
	}

	return t;
}

oa_ht_ptr oa_ht_alloc(uint i)
{
	oa_ht_ptr ht=(oa_ht_ptr)(calloc(1, sizeof(oa_ht)));

	if(ht)
	{
		ht-&amp;gt;items=i;
		ht-&amp;gt;table=oa_ht_table_alloc(ht-&amp;gt;items);
		if(!ht-&amp;gt;table) oa_ht_free(ht);
	}

	return ht;
}

void oa_ht_free(oa_ht_ptr ht)
{
	if(ht)
	{
		oa_ht_table_free(ht-&amp;gt;table, ht-&amp;gt;items);
		ht-&amp;gt;items=0;
		free(ht);
	}
}

int hash(void_ptr k, uint i, uint m, type_id t)
{
/* La funzione di hashing adottata è molto semplice (e primitiva): [chiave] modulo M. M è prefissato
 * con una direttiva di preprocessore e deve essere abbastanza lontano da una potenza di 2
 *
 * Quello di cui si occupa questa funzione è essenzialmente di effettuare correttamente il casting
 * della chiave, che è un puntatore a void, rendendo possibile la dereferenziazione e quindi l&amp;#039;operazione
 * di modulo.
*/
	if(k &amp;amp;&amp;amp; (i&amp;gt;=0))
	{
		switch(t)
		{
			case INT_PTR: return *(((int*)k)+i)%m; break;
			case UINT_PTR: return *(((uint*)k)+i)%m; break;
			case LONG_PTR: return *(((long*)k)+i)%m;  break;
			case ULONG_PTR: return *(((unsigned long*)k)+i)%m; break;
			case CHAR_PTR: return (int)((*(char*)k)+i)%m; break;
			default: break;
		}
	}
	return -1; /* Hash non valido: le posizioni di un array cominciano da 0, per cui si saprà che c&amp;#039;è stato un errore. */
}

boolean oa_ht_is_cell_free(oa_ht_item_ptr i)
{
	if(i &amp;amp;&amp;amp; !i-&amp;gt;value) return true;
	
	return false;
}

boolean oa_ht_was_cell_emptied(oa_ht_item_ptr i)
{
	if (i &amp;amp;&amp;amp; (memcmp(i, CANC, CANC_SIZE)==0)) return true;

	return false;
}

int _oa_ht_insert(oa_ht_ptr ht, void_ptr k, size_t ks, void_ptr e, size_t es, type_id t)
{
	int h_k, i;

	h_k=i=0;

	if(ht &amp;amp;&amp;amp; k &amp;amp;&amp;amp; (ks&amp;gt;0) &amp;amp;&amp;amp; e &amp;amp;&amp;amp; (es&amp;gt;0))
	{
		for(i=0;i&amp;lt;ht-&amp;gt;items;i++)
		{
			h_k=hash(k, i, ht-&amp;gt;items, t);
			if((h_k&amp;gt;=0) &amp;amp;&amp;amp; (oa_ht_is_cell_free(ht-&amp;gt;table[h_k])==true || oa_ht_was_cell_emptied(ht-&amp;gt;table[h_k])==true) )
			{
				ht-&amp;gt;table[h_k]-&amp;gt;key=calloc(1, ks);		
				ht-&amp;gt;table[h_k]-&amp;gt;value=calloc(1, es);
					
				if(ht-&amp;gt;table[h_k]-&amp;gt;key &amp;amp;&amp;amp; ht-&amp;gt;table[h_k]-&amp;gt;value)
				{
					ht-&amp;gt;table[h_k]-&amp;gt;key_size=ks;
					ht-&amp;gt;table[h_k]-&amp;gt;value_size=es;
					memcpy(ht-&amp;gt;table[h_k]-&amp;gt;key, k, ks);
					memcpy(ht-&amp;gt;table[h_k]-&amp;gt;value, e, es);
					ht-&amp;gt;items++;
					return 0;
				}				
			}
		}
	} 
	return -1;
}

void_ptr _oa_ht_search(oa_ht_ptr ht, void_ptr k, type_id t)
{
	int h_k, i;

	h_k=i=0;

	if(ht)
	{
		for(i=0;i&amp;lt;ht-&amp;gt;items;i++)
		{
			h_k=hash(k, i, ht-&amp;gt;items, t);
			if(h_k&amp;gt;=0)
			{
				if(ht-&amp;gt;table[h_k] &amp;amp;&amp;amp; !ht-&amp;gt;table[h_k]-&amp;gt;value) return NULL;
				if(ht-&amp;gt;table[h_k] &amp;amp;&amp;amp; ht-&amp;gt;table[h_k]-&amp;gt;key &amp;amp;&amp;amp; ht-&amp;gt;table[h_k]-&amp;gt;value &amp;amp;&amp;amp; (memcmp(ht-&amp;gt;table[h_k]-&amp;gt;key, k, ht-&amp;gt;table[h_k]-&amp;gt;key_size)==0) &amp;amp;&amp;amp; (memcmp(ht-&amp;gt;table[h_k]-&amp;gt;value, CANC, CANC_SIZE)!=0))	return ht-&amp;gt;table[h_k]-&amp;gt;value;
			}
		}
	}
	return NULL;
}

int _oa_ht_delete(oa_ht_ptr ht, void_ptr k, type_id t)
{
	int h_k, i;

	h_k=i=0;

	if(ht &amp;amp;&amp;amp; k)
	{
		for(i=0;i&amp;lt;ht-&amp;gt;items;i++)
		{
			h_k=hash(k, i, ht-&amp;gt;items, t);
			if((h_k&amp;gt;=0) &amp;amp;&amp;amp; (memcmp(ht-&amp;gt;table[h_k]-&amp;gt;key, k, ht-&amp;gt;table[h_k]-&amp;gt;key_size)==0))
			{
				free(ht-&amp;gt;table[h_k]-&amp;gt;value);
				ht-&amp;gt;table[h_k]-&amp;gt;value_size=0;
				ht-&amp;gt;table[h_k]-&amp;gt;value=calloc(1, CANC_SIZE);
				if(ht-&amp;gt;table[h_k]-&amp;gt;value)
				{
 				        memcpy(ht-&amp;gt;table[h_k]-&amp;gt;value, CANC, CANC_SIZE);
					ht-&amp;gt;table[h_k]-&amp;gt;value_size=CANC_SIZE;
					return 0;
				}
			}
		}
	}
	return -1;
}

void oa_ht_print(oa_ht_ptr ht, type_id t)
{
	uint i=0;

	if(ht)
	{
		
		printf(&amp;quot;\n&amp;quot;);
		for(i=0;i&amp;lt;ht-&amp;gt;items;i++)
		{
			if(ht-&amp;gt;table[i] &amp;amp;&amp;amp; ht-&amp;gt;table[i]-&amp;gt;key) 
			{
				printf(&amp;quot;[%d] &amp;quot;, i);			
				switch(t)
				{
					case CHAR_PTR: printf(&amp;quot;%s=%s&amp;quot;, (char*)(ht-&amp;gt;table[i]-&amp;gt;key), (char*)(ht-&amp;gt;table[i]-&amp;gt;value)); break;
					case INT_PTR: printf(&amp;quot;%d=%d&amp;quot;, *(int*)(ht-&amp;gt;table[i]-&amp;gt;key), *(int*)(ht-&amp;gt;table[i]-&amp;gt;value)); break;
					case UINT_PTR: printf(&amp;quot;%u=%u&amp;quot;, *(uint*)(ht-&amp;gt;table[i]-&amp;gt;key), *(uint*)(ht-&amp;gt;table[i]-&amp;gt;value)); break;
	    /* Nota: richiedono compatibilità C99.
	     *			case LONG_PTR: printf(&amp;quot;%l=%l&amp;quot;, *(long*)(ht-&amp;gt;table[i]-&amp;gt;key), *(long*)(ht-&amp;gt;table[i]-&amp;gt;value)); break;
	     *	case ULONG_PTR: printf(&amp;quot;%ul=%ul&amp;quot;, *(unsigned long*)(ht-&amp;gt;table[i]-&amp;gt;key), *(unsigned long*)(ht-&amp;gt;table[i]-&amp;gt;value)); break;				 
	    */
					default: break;
				} 
				printf(&amp;quot;\n&amp;quot;);
			}
		}
	}
}&lt;/pre&gt;

&lt;p&gt;
&lt;strong&gt;main.c&lt;/strong&gt;
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;#include &amp;lt;stdio.h&amp;gt;
#include &amp;quot;oa_ht.h&amp;quot;

int main()
{
	oa_ht_ptr ht=NULL;
	printf(&amp;quot;Alloco memoria per la tabella:\n&amp;quot;);
	ht=oa_ht_alloc(256);
	int retval=0;
	printf(&amp;quot;Inserimento nella tabella:\n\nchiave: ABCDEFGHIJKLMNOPQRSTUVWXYZ\nvalore: PRECIPITEVOLISSIMEVOLMENTE\n&amp;quot;);
	if(ht)
	{
		oa_ht_insert_c_string(ht, &amp;quot;A&amp;quot;, &amp;quot;P&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;B&amp;quot;, &amp;quot;R&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;C&amp;quot;, &amp;quot;E&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;D&amp;quot;, &amp;quot;C&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;E&amp;quot;, &amp;quot;I&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;F&amp;quot;, &amp;quot;P&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;G&amp;quot;, &amp;quot;I&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;H&amp;quot;, &amp;quot;T&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;I&amp;quot;, &amp;quot;E&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;J&amp;quot;, &amp;quot;V&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;K&amp;quot;, &amp;quot;O&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;L&amp;quot;, &amp;quot;L&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;M&amp;quot;, &amp;quot;I&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;N&amp;quot;, &amp;quot;S&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;O&amp;quot;, &amp;quot;S&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;P&amp;quot;, &amp;quot;I&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;Q&amp;quot;, &amp;quot;M&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;R&amp;quot;, &amp;quot;E&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;S&amp;quot;, &amp;quot;V&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;T&amp;quot;, &amp;quot;O&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;U&amp;quot;, &amp;quot;L&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;V&amp;quot;, &amp;quot;M&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;W&amp;quot;, &amp;quot;E&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;X&amp;quot;, &amp;quot;N&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;Y&amp;quot;, &amp;quot;T&amp;quot;);
		oa_ht_insert_c_string(ht, &amp;quot;Z&amp;quot;, &amp;quot;E&amp;quot;);
		printf(&amp;quot;\nStampa della struttura della tabella\n&amp;quot;);
		oa_ht_print(ht, CHAR_PTR);
		printf(&amp;quot;\nRicerca del valore corrispondente alla chiave O: &amp;quot;);
		printf(&amp;quot;%s\n&amp;quot;, oa_ht_search_c_string(ht, &amp;quot;O&amp;quot;));
		printf(&amp;quot;\nRimozione del valore corrispondente alla chiave E.\n&amp;quot;);
		retval=oa_ht_delete_c_string(ht, &amp;quot;E&amp;quot;);
		if(oa_ht_search_c_string(ht, &amp;quot;E&amp;quot;))
			printf(&amp;quot;%s\n&amp;quot;, oa_ht_search_c_string(ht, &amp;quot;E&amp;quot;));
		else if(retval==0)
			printf(&amp;quot;VALORE RIMOSSO CON SUCCESSO\n&amp;quot;);
		printf(&amp;quot;\nRicerca del valore corrispondente alla chiave Z: &amp;quot;);
		if(oa_ht_search_c_string(ht, &amp;quot;Z&amp;quot;))
			printf(&amp;quot;%s\n&amp;quot;, oa_ht_search_c_string(ht, &amp;quot;Z&amp;quot;));
		else
			printf(&amp;quot;NON TROVATO\n&amp;quot;);
		printf(&amp;quot;Libero la memoria allocata per la tabella\n&amp;quot;);
		oa_ht_free(ht);
	}
	return 0;
}&lt;/pre&gt;
</description>
            <author>gsdefender</author>
        <category>programmazione_2:tavole_hash</category>
            <pubDate>Thu, 27 Aug 2009 00:50:57 +0200</pubDate>
        </item>
        <item>
            <title>programmazione_2:modelli_di_calcolo_e_analisi_degli_algoritmi:teorema_fondamentale_delle_ricorrenze</title>
            <link>http://massimo30.net/wiki/programmazione_2/modelli_di_calcolo_e_analisi_degli_algoritmi/teorema_fondamentale_delle_ricorrenze?rev=1247780410&amp;do=diff</link>
            <description>
&lt;h4&gt;&lt;a name=&quot;teorema_fondamentale_delle_ricorrenze&quot; id=&quot;teorema_fondamentale_delle_ricorrenze&quot;&gt;TEOREMA FONDAMENTALE DELLE RICORRENZE&lt;/a&gt;&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;

&lt;p&gt;

Supponiamo che un problema di dimensione &lt;span class=&quot;math&quot;&gt;n&lt;/span&gt; venga diviso in &lt;span class=&quot;math&quot;&gt;a&lt;/span&gt; sottoproblemi di dimensione &lt;span class=&quot;math&quot;&gt;\frac{n}{b}&lt;/span&gt; ciascuno, e che ad ogni suddivisione sia necessario un tempo &lt;span class=&quot;math&quot;&gt;f(n)&lt;/span&gt; per poter rielaborare i dati parziali.
&lt;/p&gt;

&lt;p&gt;
La relazione di ricorrenza corrispondente a tale algoritmo ricorsivo è: 
&lt;span class=&quot;math&quot;&gt;T(n) = aT(\frac{n}{b}) + f(n)&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;
Il teorema master, supposto che &lt;span class=&quot;math&quot;&gt;n&lt;/span&gt; sia una potenza esatta di &lt;span class=&quot;math&quot;&gt;b&lt;/span&gt;, e che la ricorsione si fermi per n=1, risolve la precedente relazione di ricorrenza con una formula aperta.
&lt;/p&gt;

&lt;p&gt;
Rappresentiamo l&amp;#039;algoritmo ricorsivo che risolve il precedente problema, su un albero di ricorsione, ove ogni nodo rappresenta una generica chiamata ricorsiva, operante su una certa porzione del problema iniziale.
&lt;/p&gt;

&lt;p&gt;
 &lt;a href=&quot;http://massimo30.net/wiki/_detail/programmazione_2/teorema_master/recursion.png?id=programmazione_2%3Amodelli_di_calcolo_e_analisi_degli_algoritmi%3Ateorema_fondamentale_delle_ricorrenze&quot; class=&quot;media&quot; title=&quot;programmazione_2:teorema_master:recursion.png&quot;&gt;&lt;img src=&quot;http://massimo30.net/wiki/_media/programmazione_2/teorema_master/recursion.png&quot; class=&quot;media&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Proprietà 1&lt;/strong&gt;
Il contributo di ogni nodo a livello &lt;span class=&quot;math&quot;&gt;i&lt;/span&gt; al tempo di esecuzione è &lt;span class=&quot;math&quot;&gt;f(\frac{n}{b^i})&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Proprietà 2&lt;/strong&gt;
All&amp;#039; i-esimo livello sono presenti &lt;span class=&quot;math&quot;&gt;a^i&lt;/span&gt; nodi
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;Proprietà 3&lt;/strong&gt;
Poichè la massima profondità si ha quando la dimensione dei dati su cui operare è 1, le foglie contribuiscono con f(1), il livello delle foglie si ha per &lt;span class=&quot;math&quot;&gt;1 = \frac{n}{b^i} \Rightarrow i=log_b{n}&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;

Il costo d&amp;#039;esecuzione, visto come somma dei contributi di ogni nodo, vale pertanto 
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;(&lt;em class=&quot;u&quot;&gt;R&lt;/em&gt;)&lt;/strong&gt;    &lt;span class=&quot;math&quot;&gt;T(n) = \sum_{i=0}^{log_b{n}}{a^i f(\frac{n}{b^i})}&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;

Articoliamo lo sviluppo di tale somma in 3 casi:
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;1)&lt;/strong&gt;
&lt;/p&gt;

&lt;p&gt;
Ip. &lt;span class=&quot;math&quot;&gt;f(n)= O(n^{log_{b}{a} - \epsilon})&lt;/span&gt;   per &lt;span class=&quot;math&quot;&gt;\epsilon&lt;/span&gt; costante e &amp;gt;0 
&lt;/p&gt;

&lt;p&gt;
Th. &lt;span class=&quot;math&quot;&gt;T(n) = \Theta(n^{log_{b}{a}})&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;

&lt;strong&gt;2)&lt;/strong&gt;
&lt;/p&gt;

&lt;p&gt;
Ip. &lt;span class=&quot;math&quot;&gt;f(n) = \Theta(n^{log_{b}{a}})&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;
Th. &lt;span class=&quot;math&quot;&gt;T(n) = \Theta(n^{log_{b}{a}} log_{b}{n})&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;

&lt;strong&gt;3)&lt;/strong&gt;
&lt;/p&gt;

&lt;p&gt;
Ip. &lt;span class=&quot;math&quot;&gt;cf(n) \geq af(\frac{n}{b})&lt;/span&gt;    per &lt;span class=&quot;math&quot;&gt;0 &amp;lt; c &amp;lt; 1&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;
( e quindi &lt;span class=&quot;math&quot;&gt;f(n) = \Omega(n^{log_{b}{a} + \epsilon}&lt;/span&gt;)
&lt;/p&gt;

&lt;p&gt;
Th. &lt;span class=&quot;math&quot;&gt;T(n)=\Omega(f(n))&lt;/span&gt;
&lt;/p&gt;

&lt;/div&gt;

&lt;h3&gt;&lt;a name=&quot;dimostrazione&quot; id=&quot;dimostrazione&quot;&gt;Dimostrazione&lt;/a&gt;&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
&lt;strong&gt;1)&lt;/strong&gt;
&lt;/p&gt;

&lt;p&gt;
Dalla (&lt;em class=&quot;u&quot;&gt;R&lt;/em&gt;) abbiamo:
&lt;/p&gt;

&lt;p&gt;
&lt;span class=&quot;math&quot;&gt;T(n) = \sum_{i=0}^{log_b{n}}{a^i O( (\frac{n}{b^i})^{log_{b}{a} -\epsilon} )}&lt;/span&gt; = 
&lt;/p&gt;

&lt;p&gt;
&lt;span class=&quot;math&quot;&gt;O(\sum_{i=0}^{log_b{n}}{n^{log_b{a - \epsilon}}b^{i\epsilon} })&lt;/span&gt; = 
&lt;/p&gt;

&lt;p&gt;
&lt;span class=&quot;math&quot;&gt;O(n^{log_b{a} - \epsilon}\sum_{i=0}^{log_b{n}}{(b^{\epsilon})^{i} })&lt;/span&gt; = 
&lt;/p&gt;

&lt;p&gt;
&lt;span class=&quot;math&quot;&gt;O(n^{log_b{a} -\epsilon} (1+b^{\epsilon} + \ldots n^{\epsilon}))&lt;/span&gt; = 
&lt;/p&gt;

&lt;p&gt;
&lt;span class=&quot;math&quot;&gt;O(n^{log_b{a}-\epsilon}(n^{\epsilon} +O(n^{\epsilon}))) &lt;/span&gt; =
&lt;/p&gt;

&lt;p&gt;
&lt;span class=&quot;math&quot;&gt;O(n^{log_b{a}-\epsilon}n^{\epsilon})&lt;/span&gt; =
&lt;/p&gt;

&lt;p&gt;
&lt;span class=&quot;math&quot;&gt;O(n^{log_b{a}})&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;
Inoltre per le proprietà 2 e 3, il contributo delle sole foglie al costo totale è &lt;span class=&quot;math&quot;&gt;a^{log_b{n}}=n^{log_b{a}}&lt;/span&gt;, quindi &lt;span class=&quot;math&quot;&gt;T(n)=\Omega(n^{log_b{a}})&lt;/span&gt;, pertanto 
&lt;/p&gt;

&lt;p&gt;
&lt;span class=&quot;math&quot;&gt;T(n)=\Theta(n^{log_b{a}})&lt;/span&gt;             C.V.D.
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;2)&lt;/strong&gt;
&lt;/p&gt;

&lt;p&gt;
Dalla (&lt;em class=&quot;u&quot;&gt;R&lt;/em&gt;) abbiamo:
&lt;/p&gt;

&lt;p&gt;
&lt;span class=&quot;math&quot;&gt;T(n)=\sum_{i=0}^{log_b{n}}{a^i \Theta( (\frac{n}{b^i})^{log_b{a}} )}&lt;/span&gt; =
&lt;span class=&quot;math&quot;&gt;\Theta(\sum_{i=0}^{log_b{n}}{n^{log_b{a}}})&lt;/span&gt; = 
&lt;span class=&quot;math&quot;&gt;\Theta(n^{log_b{a}}\sum_{i=0}^{log_b{n}}{1})&lt;/span&gt; =
&lt;span class=&quot;math&quot;&gt;\Theta(n^{log_b{a}}log_b{n})&lt;/span&gt;               C.V.D.
&lt;/p&gt;

&lt;p&gt;
&lt;strong&gt;3)&lt;/strong&gt;
&lt;/p&gt;

&lt;p&gt;
Notiamo che l&amp;#039;equazione f(n)=&lt;span class=&quot;math&quot;&gt;\Omega(n^{log_b{a} + \epsilon})&lt;/span&gt; &lt;em class=&quot;u&quot;&gt;NON&lt;/em&gt; è l&amp;#039;ipotesi, bensì è una condizione &lt;em class=&quot;u&quot;&gt;NECESSARIA&lt;/em&gt; all&amp;#039;ipotesi   &lt;span class=&quot;math&quot;&gt;cf(n) \geq af(\frac{n}{b})&lt;/span&gt;    per &lt;span class=&quot;math&quot;&gt;0 &amp;lt; c &amp;lt; 1&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;
Da quest&amp;#039;ultima ricaviamo iterativamente :
&lt;/p&gt;

&lt;p&gt;
&lt;span class=&quot;math&quot;&gt;af(\frac{n}{b}) \leq cf(n) \Rightarrow f(\frac{n}{b}) \leq \frac{c}{a} f(n)&lt;/span&gt;
&lt;span class=&quot;math&quot;&gt;\Rightarrow f(\frac{n}{b^2}) \leq (\frac{c}{a})^{2}f(n)&lt;/span&gt;
&lt;span class=&quot;math&quot;&gt;\Rightarrow \ldots f(\frac{n}{b^i}) \leq (\frac{c}{a})^i f(n)&lt;/span&gt;
&lt;span class=&quot;math&quot;&gt;\Rightarrow a^i f(\frac{n}{b^i}) \leq c^if(n)&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;

Da quest&amp;#039;ultima e dalla &lt;em class=&quot;u&quot;&gt;R&lt;/em&gt; abbiamo:
&lt;/p&gt;

&lt;p&gt;
&lt;span class=&quot;math&quot;&gt;T(n) \leq \sum_{i=0}^{log_b{n}}{c^i f(n)} \leq f(n)\sum_{i=0}^{\infty}{c^i} = f(n) \frac{1}{1-c} = \Theta(f(n))&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;span class=&quot;math&quot;&gt;\Rightarrow T(n)=O(f(n))&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;
ma f(n) è il contributo del solo nodo radice, quindi &lt;span class=&quot;math&quot;&gt;T(n) = \Omega(f(n))&lt;/span&gt; e quindi &lt;span class=&quot;math&quot;&gt;T(n) = \Theta(f(n))&lt;/span&gt;    C.V.D.
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Dimostriamo infine che &lt;span class=&quot;math&quot;&gt;af(\frac{n}{b}) \leq cf(n) \Rightarrow f(n)=\Omega(n^{log_b{a}+\epsilon})&lt;/span&gt;  con &lt;span class=&quot;math&quot;&gt;c&amp;lt;1&lt;/span&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;

se &lt;span class=&quot;math&quot;&gt;\frac{a}{c}f(\frac{n}{b}) \leq f(n)&lt;/span&gt;   abbiamo iterativamente che:
&lt;/p&gt;

&lt;p&gt;
&lt;span class=&quot;math&quot;&gt;\frac{n^{log_b{a}}}{n^{log_b{c}}} \ldots \frac{a^i}{c^i}f(\frac{n}{b^i}) \leq \ldots \frac{a^2}{c^2}f(\frac{n}{b^2}) \leq \frac{a}{c}f(\frac{n}{b}) \leq f(n)&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;span class=&quot;math&quot;&gt;\Rightarrow  n^{log_b{a}}n^{log_b{\frac{1}{c}}} \leq f(n)&lt;/span&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;span class=&quot;math&quot;&gt;\Rightarrow f(n) = \Omega(n^{log_b{a}}n^{\epsilon})&lt;/span&gt;  con &lt;span class=&quot;math&quot;&gt;\epsilon = log_b{\frac{1}{c}}&lt;/span&gt;  C.V.D.

&lt;/p&gt;

&lt;/div&gt;
&lt;!-- SECTION &quot;Dimostrazione&quot; [1802-] --&gt;</description>
            <author>ordeal</author>
        <category>programmazione_2:modelli_di_calcolo_e_analisi_degli_algoritmi</category>
            <pubDate>Thu, 16 Jul 2009 23:40:10 +0200</pubDate>
        </item>
        <item>
            <title>programmazione_2:selezione_e_statistiche_di_ordine:calcolo_deterministico_del_mediano - creata</title>
            <link>http://massimo30.net/wiki/programmazione_2/selezione_e_statistiche_di_ordine/calcolo_deterministico_del_mediano?rev=1236887873&amp;do=diff</link>
            <description>


&lt;h1&gt;&lt;a name=&quot;mediano_dei_mediani&quot; id=&quot;mediano_dei_mediani&quot;&gt;Mediano dei mediani&lt;/a&gt;&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;/div&gt;
</description>
            <author>gsdefender</author>
        <category>programmazione_2:selezione_e_statistiche_di_ordine</category>
            <pubDate>Thu, 12 Mar 2009 20:57:53 +0200</pubDate>
        </item>
    </channel>
</rss>
