Ask your own question, for FREE!
Computer Science 12 Online
OpenStudy (anonymous):

What is the computational complexity of the following Python code? http://ideone.com/mGBQu

OpenStudy (anonymous):

what it does

OpenStudy (anonymous):

it's a puzzle, find out :-D

OpenStudy (anonymous):

I'm sure ffm would know right away.

OpenStudy (anonymous):

idk whats lambda

OpenStudy (anonymous):

lambda <parameters> = expression is just syntactic sugar for def identifier(parameters): return expression only difference is that there does not need to be an identifier.

OpenStudy (anonymous):

so lambda expressions in Python are simply anonymous functions

OpenStudy (anonymous):

and I think they're coming to Java :-D

OpenStudy (anonymous):

so you can write messy code just like I did :-D

OpenStudy (anonymous):

oops it's lambda <parameters>: expression and if you want to use an identifier, then you write identifier = lambda <parameters>: expression and call it just like you would call a normal function

OpenStudy (anonymous):

they can be used in conjunction with the higher order functions like map, reduce, filter etc. for example, reduce(lambda x,y: x+y, map(lambda x: x*x, range(1, 1001))) returns the sum of the squares of every number in the range [1, 1000]

OpenStudy (anonymous):

Here's a hint: http://rosettacode.org/wiki/Python

OpenStudy (anonymous):

Another hint: http://ideone.com/7vIFn

OpenStudy (anonymous):

I will guess that the running time is in O(n^2), and maybe \[\Omega(1)\]where n is the size of the list passed to ss, and the best-case is when n = 1.

OpenStudy (anonymous):

(assuming lambda calls take constant time)

OpenStudy (anonymous):

right @ bmp

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!