Bifalgorithm post · Brisk · Chapter 1

How are sets different from computer collections in size and type?

How are sets different from computer collections in size and type? (Brisk · Chapter 1) — "Infinite sets. ’Nuff said. I’ve never seen an array with infinitely m…

Ideas in this flowchart

  • Infinite sets can be heterogeneous, unlike common computer collections.
  • Sets may be infinite, although computer arrays are not encountered with infinitely many elements.
  • Most program collections contain elements of a single type.
  • A uniform type allows the program to treat all collection elements in the same way.
  • Mixing incompatible types can cause problems during operations or searches.
  • Sets can be heterogeneous and contain different kinds of things.
  • One example is X = { Jack Nicholson, Kim Kardashian, Universal Studios, 5786, F }.
  • Programming languages generally provide ways to create heterogeneous collections.
  • In Java, a non-generic ArrayList can hold items of class Object.
  • In C, an array of void pointers can point to different kinds of things.
  • In strongly typed languages, heterogeneous collections can feel like an unnatural workaround, unlike in Perl or JavaScript.
  • Sets are often intentionally restricted to one type, so their universe Ω is homogeneous.
Feed/

How are sets different from computer collections in size and type?

Channel

Brisk

1 page

"Infinite sets. ’Nuff said. I’ve never seen an array with infinitely many elements, and neither will you. Untyped. Most of the time, an array or other collection in a computer program contains elements of only a single type: it’s an array of integers, or a linked list of Customer objects, for example. This is important because the program often needs to treat all elements in the collection the same way. Perhaps it needs to loop over the array to add up all the numbers, or iterate through a customer list and search for customers who have not placed an order in the last six months. The program would run into problems if it tried to add a string of text to its cumulative total, or encountered a Product object in the middle of its list of Customers. Sets, though, can be heterogeneous, meaning they can contain different kinds of things. The Davies family example had all human beings, but nothing stops me from creating a set X = { Jack Nicholson, Kim Kardashian, Universal Studios, 5786, F }. I don’t press this point too hard for a couple of reasons. First, most programming languages do allow heterogeneous collections of some sort, even if they’re not the most natural thing to express. In Java, you can define an ArrayList as a non-generic so that it simply holds items of class “Object”. In C, you can have an array of void *’s — pointers to some unspecified type — which allows your array to point to different kinds of things. Unless it’s a loosely-typed language, though, like Perl or JavaScript, it sort of feels like you’re bending over backwards to do this. The other reason I make this distinction lightly is that when we’re dealing with sets, we often do find it useful to deal with things of only one type, and so our Ω ends up being homogeneous anyway."

Flowchart preview
Series cover
👍
0
0 comments0 shares

Sign in to view and post comments.