Algorithms using Python?
Wayne Werner
wayne at waynewerner.com
Wed Sep 26 11:55:47 EDT 2012
On Fri, 21 Sep 2012, Dennis Lee Bieber wrote:
> On Fri, 21 Sep 2012 14:26:04 +0530, Mayuresh Kathe <mayuresh at kathe.in>
> declaimed the following in gmane.comp.python.general:
>
>> Is there a good book on foundational as well as advanced algorithms
>> using Python?
>>
> Depends on what you mean by "foundational"...
>
> Since Python has dynamic lists and dictionaries, I suspect you won't
> find any textbook focusing on linked-list or hashed lookup algorithms
> using Python.
>
> You can probably implement them, but they're not going to be very
> efficient. (And never "remove" an element from the linked-list
> implementation because Python would shift all the other elements, hence
> your "links" become invalid).
It's quite inefficient, but it would be fairly trivial to create a LL
implementation like this:
class Link:
def __init__(self):
self.next = None
self.value = None
class LinkedList:
def __init__(self):
self.head = None
def add(self, value):
node = Link()
node.value = value
self.append(node)
def append(self, node):
# Write some code
It's fairly easy to use reference types as one would use pointers in
<language>.
But it might actually require understanding pointers and such in the first
place...
I'm not really aware of any algorithm that's impossible/harder to
implement in Python - Python just makes most things a lot easier so you
never have to deal with the lower level algorithms. Which makes *me* happy
:)
-Wayne
More information about the Python-list
mailing list