common data structures

M

max(01)*

hi!

i am reading "how to think like a computer scientist - learning with
python"... it semms like a good tutorial, but it shows a different
language heritage... in particular, in the chapter about linked lists.

the question is: why bothering building a linked list class when you
have a native list type in the first place? the same applies about
trees, which can naturally be encoded like lists, e.g.:


1
/ \
2 3 ---> [1, [2, [4, 5]], 3] maybe...
/ \
4 5

is it a teaching contrived example, a matter of performance or what else?

bye

max
 
M

Marc 'BlackJack' Rintsch

the question is: why bothering building a linked list class when you
have a native list type in the first place?

To show how the native list type may be implemented. It's not BTW. And
of course it's a book to learn to think like a computer scientist in
general and not like a python programmer.
the same applies about
trees, which can naturally be encoded like lists, e.g.:


1
/ \
2 3 ---> [1, [2, [4, 5]], 3] maybe...
/ \
4 5

is it a teaching contrived example, a matter of performance or what else?

That's a quite simple example and usually you want not only the data
representation but operations on that tree like in-order tree walk and
similar things.

Ciao,
Marc 'BlackJack' Rintsch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,665
Latest member
salkete

Latest Threads

Top