winterthunder: (Default)
[personal profile] winterthunder posting in [community profile] intro_to_cs
Hi everyone!

First, class business... I went poking around the website, and I found a suggested schedule for the problem sets. They actually correspond to the lectures, imagine that! Anyway, armed with this new info, I've made some tweaks to the problem set schedule.

PS2- 1/22
PS3- 2/5
PS4- 2/19
PS5- 3/5
PS6- 3/19
PS7- 3/26
PS8- 4/16
PS9- 4/23
PS10- 4/30
PS11- 5/14
PS12- 6/4

I also discovered that there are three quizzes associated with this course. So I'm putting the question to you all - do you want to do them?

Poll #2096 Quiz? What Quiz?
Open to: Registered Users, detailed results viewable to: All, participants: 7

I would like to include the quizzes in the course.

View Answers

Yeah, sure, extra practice is good.
7 (100.0%)

No way, I've got enough on my hands with the problem sets.
0 (0.0%)

If you would like to do the quizzes, how should we incorporate them?

View Answers

Add them on top of the lecture and reading in the week where they fit in the sylabus.
7 (100.0%)

Push the lectures back a week to make time for the quiz
0 (0.0%)

Some other idea which I'll tell you about in the comments
0 (0.0%)

Okay, that's out of the way, on to the readings.

I gotta say, this week kicked my ass, and these readings were right there with work and family issues, putting their prints on my bum. The wikibook chapters in particular just are not working for me. Is anyone else having that issue? My notes on those chapters are scattered with big red question marks and underlines with "What does this mean??" written off to the side. Part of this, I think, is that I really don't do numbers. I had to go look up the definition of a prime for the problem set...

Anyway, I've got some questions to toss out for discussion.

1- From the Data Structures reading, what are stacks and queues and why do we care about them? The reading just goes, 'This makes it easy to use lists in stacks and queues, whee!' (Or at least, that was my impression...)
2- From the same reading, why is it useful to be able to unpack a tuple?

Anyone else have questions for the class? This set of readings certainly provides fertile ground for questions. All of section 5.8 of the Data Structures had me going, "Bzuh?" And I just gave up on the wikibook...

Poll #2097 Who rocked problem set one?
Open to: Registered Users, detailed results viewable to: All, participants: 1

I have...

View Answers

Knocked it out of the park.
1 (100.0%)

Struck out.
0 (0.0%)

There's still another at bat to go!
0 (0.0%)

I thought problem set one...

View Answers

Was easy peasy
0 (0.0%)

Was a pain, but achievable
1 (100.0%)

Was way too hard... when did we learn how to do this stuff, again?
0 (0.0%)

Now, [personal profile] aranthe has generously posted answers to some of the exercises in the readings. Anyone want to volunteer to do that for PS1?

Date: 2010-01-16 03:23 am (UTC)
jetamors: Yoruichi is really hot (Default)
From: [personal profile] jetamors
IDK about the stack and queues stuff; like, I can understand what they are, but I don't know how they're usually applied. Hopefully we'll get to use them in problems soon.

Tuple unpacking... I don't know if this is the exact application for it in Python, but I know in Matlab, sometimes you get a big undifferentiated table of data, and so you have to go through and say, okay, column 1 is time, column 2 is heart rate, and so on; this seems like one way to do that.

I can post answers to ps1; would you like me to do it in this entry, or make another one?


Date: 2012-01-09 05:34 am (UTC)
From: (Anonymous)
This is exactly what I was looking for. Thanks for wriitng!

Date: 2010-01-17 01:19 am (UTC)
From: [personal profile] aranthe

Re: stacks and queus: This isn't as complicated as the lack of information made it sound. It's just an order concept:

An ordered list (or array, if you're coming from other languages) where items are added and deleted in Last-In-First-Out (LIFO) order. In other words, when you add an element to a stack, you push it into the first position (index 0); when you remove an element, you pop it from the last position (index length-1).
An ordered list (or array, if you're coming from other languages) where items are added and deleted in First-In-First-Out (FIFO) order. When you add an element to a queue, you append it. It becomes the last index. When you remove an element, you leftpop it; this removes the item at index 0.

Stacks and queues are ways of adding and removing items from a list rather than objects in and of themselves.

Re: unpacking tuples. [personal profile] jetamors gave one example. I can see where it would be especially helpful in a configuration case. Once set, configuration data should generally be immutable. This way, you don't have to worry about the data stored in the tuple being changed, but you can assign each piece of it its own meaningful name.

A trivial example: Suppose you had a tuple that stored a person's last name, first name and birth date:

person = 'Smith', 'John', '01.16.80'

If you don't unpack it, you have to refer to each of those things by index: person[0], person[1], person[2]. Most people find the typing of brackets rather awkward because of their location. It's a lot simpler to do this:

last, first, birth = person

That way, you can use meaningful names to refer to each piece of data and they're simpler and quicker to type.

From a programming standpoint, since the tuple data can't be changed, if you want to change the data and use it several times in its changed form in the app, the only way to do that is to assign it to a variable that can accept the changes you want to make.

Date: 2010-01-17 10:46 pm (UTC)
From: [personal profile] aranthe

Wait... when you unpack a tuple, you're assigning names to the data rather than pulling the data from the tuple?

If I'm understanding your question correctly, yes: When you unpack a tuple, the tuple itself remains intact. Unpacking merely assigns the value of each element of the tuple to a name. This does not change the tuple in any way. If you do this...

# Create a tuple.
person = 'Doe', 'Jane', '01.17.80'

# Print the tuple.
print person

# Now, unpack it.
last, first, birth = person

# Print the unpacked variables
print last, first, birth

# Okay, let's make a change to the last name.
last = 'Mrs. John ' + last

# Now, print those variables again
print last, first, birth

# Now print the tuple again.
print person's what the output looks like:

('Doe', 'Jane', '01.17.80')
Doe Jane 01.17.80
Mrs. John Doe Jane 01.17.80
('Doe', 'Jane', '01.17.80')

Line 1 is the tuple. Line 2 shows the three variables after they are unpacked. Line 3 shows the three variables with the change to last. Line 4 shows that the tuple remains unchanged.

So for a stack and a queue... are these types of lists? If you add something to a list with a stack, does that limit you to only adding other items via stack?

Let's see if I can find a better way to put it: A list is just a sequence or collection of data. Without context, it isn't a stack or a queue.

"Stack" and "queue" are (unnecessarily confusing) terms programmers use to tell other programmers what order they are using to add/remove elements to and from the list. If I'm treating the list as a stack, I remove the last item first. If I'm treating it as a queue, I remove the first item first.

It would make a lot more sense if people used the words in their verb form: "I'm stacking this list" or "I'm queuing this list" because it has to do with the way you treat a list, not with anything that is inherent in the list itself. Does this make more sense?

To answer your second question, no, there are no technical constraints to prevent you switching back and forth between the two behaviors. There may be good logical reasons to treat the data in one way or the other, but that's the sort of thing you have to determine when you're planning a program.

BTW, here's a way to keep the terms straight in your head: For stack, picture a stack of books. Unless you want a real mess, it's best you remove the last (topmost) item and work your way down, right? For a queue, think about a customers in a checkout queue: The first one to arrive at the cashier gets checked out first (unless you want a riot).

Date: 2010-01-18 07:49 pm (UTC)
From: [personal profile] aranthe

I get the visualization thing. I do it myself. :-) About the shark and remora analogy, just remember that the remora isn't attached to the shark at all. Here's another way to visualize the concept which works for any type of change, not just for appending:

Suppose you create a bouquet which contains a white carnation, a red rose, a yellow tulip and an orange lily. (Not very likely, but...) You tie a tag around the bouquet and label it bouquet (the tuple). Also, each flower has its own tag: bouquet[0], bouquet[1], etc. These are the elements of the tuple.

When you unpack the tuple, you add a second tag to each of those flowers. Maybe you name them by variety carnation, rose, etc.

Now, suppose you'd prefer a purple carnation and decide to use the old food coloring trick to change the color of the carnation. Whoops! Python says that you can't change the tuple (bouquet) or any of its parts. Instead, you have to get another white carnation and dye it. When you do that, Python moves the carnation tag from the white carnation in the tuple bouquet and gives it to the purple carnation. The white carnation is still bouquet[0], but the carnation tag is now around the purple carnation.

In other words, the tuple and its elements are "frozen." Using the unpacked names, you can make changes, but when you do, the changed data is completely independent of the original.


Date: 2012-01-06 04:53 pm (UTC)
From: (Anonymous)
This is the prfceet way to break down this information.


Date: 2012-01-09 05:34 am (UTC)
From: (Anonymous)
That's really tihnknig out of the box. Thanks!


Date: 2012-01-07 06:49 am (UTC)
From: (Anonymous)
This arctile went ahead and made my day.


Date: 2012-05-03 01:50 pm (UTC)
From: (Anonymous)
Ooops, you are right. I agree with you. Yes, if he cared about Victoria's welfare he would stop pesneritg her. And yes, it is all about his need to be successful at getting people to smile. I don't think that stalking is romantic or that women should smile for men on command.When I posted this, I'd forgotten about the bit in the clip between him and Victoria. The bit that stood out for me is our shared need for validation. I just love the idea of people queuing up to be validated. It makes me laugh and makes me feel stupid. So, it was lazy on my part! A lazy feminist with no attention to detail, that's me. Thanks for watching it properly and commenting much appreciated.


Date: 2012-01-09 04:01 am (UTC)
From: (Anonymous)
Shoot, so that's that one spuposes.


Date: 2012-01-07 07:27 am (UTC)
From: (Anonymous)
Haha. I woke up down today. You've chreeed me up!


Date: 2012-01-07 11:36 am (UTC)
From: (Anonymous)
Well I guess I don't have to spend the weekend fiuginrg this one out!


Introduction to Computer Science

July 2010

2526272829 3031

Page Summary

Style Credit

Expand Cut Tags

No cut tags
Page generated Sep. 25th, 2017 06:03 am
Powered by Dreamwidth Studios