segunda-feira, 22 de abril de 2013

Funções recursivas

O entendimento e a utilização de funções recursivas é uma grande arma para resolver vários tipos de problemas.  Entre os problemas que são mais fáceis serem resolvidos usando métodos recursivos estão os problemas de contagem. Em alguns casos, o próprio processo que precisamos contar é descrito de maneira recursiva.

Em geral, os algoritmos recursivos são mais fáceis de serem entendidos e mais fáceis de provar a corretude dos mesmos. 

Considere o seguinte problema Cola:

A cada três garrafas devolvidas vazias de Choco Cola, ganhe um nova garrafa de Choco Cola.

Se você comprar N garrafas de Choco Cola na loja, quantos refrigerantes você vai conseguir realizando todas as trocas possíveis?

Seja T(n) o número de refrigerante que você pode conseguir realizando todas as trocas possíveis.

Recorrência dada pelo professor Fábio Carlos.

$$T(n) = \begin{cases}n & n < 3 \\ 3 + T(n-3+1) & \text{caso contrário,} \end{cases}$$

Observe que a cada três refrigerantes, ele ganha um novo refrigerante. Teste 

Podemos acelerar a recorrência acima da seguinte maneira:

$$T(n) = \begin{cases}n & n < 3 \\ 3* \lfloor n/3 \rfloor + T(n - 3 \lfloor n/3 \rfloor + \lfloor n/3 \rfloor) & \text{caso contrário,} \end{cases}$$

Esta solução é equivalente a solução dada pelo aluno Alexsandro Oliveira.

$$T(n) = \begin{cases}n & n < 3 \\ n - n \text{ mod } 3 + T(n \text{ mod } 3 + \lfloor n/3 \rfloor ) & \text{caso contrário,} \end{cases}$$

Esta outra recorrência também resolve o mesmo problema:

$$T(n,m) = \begin{cases}n & n+m < 3 \\ n + T( \lfloor (n+m)/3 \rfloor , (n+m) \text{ mod } 3 ) & \text{caso contrário,} \end{cases}$$

11 comentários:

Packers And Movers Mumbai disse...

An excellent information provided thanks for all the information i must say great efforts made by you. thanks a lot for all the information you provided.
Packers And Movers Mumbai


Packers And Movers Bangalore disse...

This is really very nice post you shared, i like the post, thanks for sharing..Packers And Movers Bangalore

khadim hussain disse...

http://www.aiobjectives.com/2019/12/18/what-is-forgery-why-it-is-fraud/

What is forgery crimes and why it is fraud ?. Forgery crimes is fake signature and without
permission making a false documents or every where.
What is duplicate invoices and waht is processed of duplicate invoices and what
is detict of this crimres.

Logicmojo disse...

Data Structures Online Course

We offer the best free online courses to learn and practice Data Structure Questions, Best Data Structures And Algorithms Course, Data Structures Online Course, Best Algorithms Course System Design interview question, data structure and algorithms in JAVA, Best data structure and algorithms online course etc. For more info visit our website today.

https://www.logicmojo.com/

Packers And Movers Bangalore disse...

Packers And Movers Bagalkot
Packers And Movers Belgaum
Packers And Movers Hassan
<a href="https://packe

Best Digital Marketing Services in Lahore disse...

islamic dua fuaktsoft channel is the best channel to promote our children to religon and prompte the attention levelof our children.
In Islam, Invocation (duʿāʾ) (Arabic: دُعَاء‎ IPA: [duˈʕæːʔ], plural: ʾadʿiyah أدْعِيَة [ʔædˈʕijæ]) is a prayer of
supplication or request. ... Muhammad is reported to have said, "Dua is the very essence of worship."

Unknown disse...

Convolutional Neural Network (CNN) is a type of deep neural network which has proven
to perform well in computer vision tasks such as image classification, object detection,
object localization and neural style transfer. In this post, I will explain about the
different layers that make up a convolutional neural network: convolution layer, pooling
A convolution layer transforms the input image in order to extract features from it.
In this transformation, the image is convolved with a kernel (or filter). layer
and fully connected layer.

inamulhaq1122 disse...

one two buckle my shoes


Poetry has so many benefits for kids. It is not only a great medium for rendering information
but children also find poems very delightful. Poetry recitation and memorising is a fun activity that you can
engage your kid in. Let’s take a look at some famous, funny and rhyming poems for kids. Along with that, we shall
discuss how you can select a poem and teach your kid to recite it.

Anônimo disse...

grant road call girls ##
juhu call girls ##
kandivali call girls ##
khar call girls ##
kurla call girls ##
lokhandwala call girls ##
lower parel call girls ##
malad call girls ##

Packers And Movers Bangalore disse...

Packers And Movers Bangalore to Mumbai
Packers And Movers Bangalore to Delhi
Packers And Movers Bangalore to Gurgaon
Packers And Movers Bangalore to Bhubaneswar
Packers And Movers Bangalore to Chandigarh
Packers And Movers Bangalore to Kolkata

Best Digital Marketing Services in Lahore disse...




barbaroslar episode 1 in urdu


Comment for barbaroslar episodes: Go and Watch the Turkish Drama Series of Engin Altan's "Barbarosslar" in Urdu only on our youtube channel "My Kids Tube".
Please subscribe and Stay Tuned!


https://www.youtube.com/watch?v=qmJQOLaK2IM