Questions on Using Python to Teach Data Structures and Algorithms

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Wed Sep 27 20:45:16 EDT 2006


efrat:

>1. What exactly is a Python list?

A dynamic array that can grow geometrically on the right.


>If one writes a[n], then is the complexity Theta(n)? If this is O(1),<

It is O(1).


>then why was the name "list" chosen?

I'd too love to know why the wrong "list" name was chosen for them,
instead of "array". (Maybe because "list" is shorter, or because ABC
called them "lists"...)


>2. Suppose I have some file example.py, and I'd like to incorporate it
**into** part of an HTML page with nice syntax highlighting and all the
shebang. Is there an easy way to do so?<

There are many programs that do this, I use a modified version of
PySourceColor:
http://bellsouthpwp.net/m/e/mefjr75/


Using Python to teach data structures and algorithms to
electrical-engineers students:
The following personal ideas may seem wrong, but if they are wrong,
than I'd like to know why.
I think Python is only partially fit for your purpose. If you want to
teach how complex data structures work in general, and some smart
algorithms on them, like teaching some interesting graph algorithms,
then Python is fit, because implementing such algorithms is often
simple, etc.
But to manage simple data structures Python isn't good, because it's
too much slow compared to the simple operations, and it uses too much
memory. One of the basic data structures is the chained list, you can
easly implement a chained list in Python, but the result is often
useless and without meaning, maybe even for teaching purposes. Python
is too much hi-level, while most of the basic data structures use
pointers and they have a meaning if done closer to the 'metal'. With
Python you can't have pointers (just names of objects) and some times
if you use a "fast" data structure you end doing things slower than
using the built-in data structures like dicts. So to teach some of the
basic data structures to your electrical-engineers students I think
Pascal is the best choice still :-)
(Note: to teach DSA to CS students C can be fit too, and to teach a bit
of DSA to younger people Python can be better.)

Bye,
bearophile




More information about the Python-list mailing list