Difference Between Array & Tuple for Large App

In summary: The set {a,b} has cardinality 2 because there are two elements in that set that are not members of any other set. The set {a,b,c} has cardinality 3 because there are three elements in that set: a,b, and c. Thanks Hurkyl. I will use "cardinality" throughout my program.
  • #1
mikestampone
14
0
I am wondering if anyone can describe to me the correct use of a couple words. I am programming a very large application, and I like to name my variables so that they are very descriptive. Before I begin, I would like to know what is the difference between an array and a tuple? Are they the same? If I have a list of symbols, such as <B,0,1>, is it more descriptive to say "symbol array", or "symbol tuple"? Also, as all C programmers know, I will need to be naming the array size in a separate variable. Should I say "symbol tuple size", "symbol array size", or something else? What about for sets? "symbol set" and "symbol set size"? Or is there something better? Normally I would just name them whatever, but this application is gigantic, and I want to make sure I get the naming right the first time. Thanks all.
 
Physics news on Phys.org
  • #2
A tuple, also called a sequence, is an ordered list of items, such as (0,1,1), which is a different tuple from (1,1,0) and (0,1).

A set is a collection of distinct items with no specified order, so {0,1} represents the same set as {1,0} and {0,1,1}.

An array is a collection of items ordered in any number of dimensions. For example, a tuple is a 1-dimensional array (it takes one index to locate an item), and a matrix is a 2-dimensional array (it takes two indices to locate an item).
 
  • #3
Thank you Rasalhague :) That clears up a lot. What about the number of items in a tuple or set. Do I say count, size, cardinality, or something else. I am not sure on how to say "the number of elements" in a single word. Is it different for sets and tuples?
 
  • #4
The Wikipedia entry Tuple talks about the elements and length of a tuple. The Wikipedia entry Sequence talks about the members, elements or terms of a sequence, and about its length. (The tuple article says that a tuple is a sequence; and the sequence article says that a sequence is also called a tuple.) So length looks promising - but maybe someone can give us a more definitive answer. Wolfram Mathworld doesn't go into that much detail.

I've seen several ways of defining tuples in terms of sets. For example, some sources define the tuples recursively using nested sets like this:

(a,b) = {a,{a,b}}
(a,b,c) = ((a,b),c) = {{a,{a,b}},{(a,b),c}} = {{a,{a,b}},{{a,{a,b}},c}}

or if the possibility of a 0-tuple is included:

(a,b) = {{Ø{Ø,a}},{{Ø,{Ø,a}},b}}

and then define a function as a tuple (D,C,r), where D and C are sets, the domain and codomain of the function, and r is the rule relating them. But an alternative approach defines a sequence as a function from the set {1,2,...,n} to a set S, and I don't know how a function is defined in this latter view.

This makes me hesitate to talk about the "elements" of a tuple, in case a tuple is really a set whose elements are other sets. So instead, I've been calling them "terms" or "entries" or more vaguely "items". Maybe I'm being pernickity there, and I don't suppose there's really any ambiguity, but I'm just learning about these things, and I want to get it right... Obviously the Wikipedia writer didn't see any contradiction with calling them elements or members.
 
  • #5
Thanks again Rasalhague. I will use "length" throughout my program :)
 
  • #6
You're welcome.

MATLAB calls it length too:

>> a=[1 1 1];
>> length(a)

ans =

3

A possible source of ambiguity, in some contexts, is that the magnitude or norm of a vector is often referred to, informally, as its length. In the case of the vector space of real coordinate vectors with the usual rules:

[tex]\text{norm}(\mathbf{a})=\sqrt{\mathbf{a} \cdot \mathbf{a}}=\sqrt{\sum_{i=1}^{n}(a_i)^2}[/tex]

>> a=[1 1 1];
>> norm(a)

ans =

1.7321

i.e.

[tex]\sqrt{3}[/tex]
 
  • #7
Luckily, my program is not going to be using vectors, so ambiguity in this case will not be a problem. Although it will be good to consider this ambiguity in the creation of future programs which may involve vectors. Thank you for taking the time to answer my question so in-depth. I really appreciate your guidance.
 
  • #8
Size is a common term for the number of elements in a collection. It's enouraged by the language too -- C++ containers use size() to get the number of elements they contain, and C has the type size_t. (Though I suppose in a few contexts, there could be an ambiguity about size referring to number of bytes -- e.g. that's what sizeof returns)

Of course, length is also common. Java uses that for its arrays, and python uses the abbreviation len for all of its container types.
 
  • #9
Thanks Hurkyl. I will be using length. If I am coding with a vector data type I will default to size. It is interesting that you noted the ambiguity of size referring to a number of bytes. That is actually why I started this thread :) I was looking for something different than size, because I knew size could mean the number of bytes, in C language.
 

FAQ: Difference Between Array & Tuple for Large App

What is an array in a large application?

An array in a large application is a data structure that stores a collection of elements of the same type. It is used to store and manipulate data in an organized manner, making it easier and more efficient to access and modify the data.

What is a tuple in a large application?

A tuple in a large application is also a data structure that stores a collection of elements, but unlike an array, it can store elements of different types. Tuples are often used when the data being stored is not homogenous and needs to be accessed as a whole.

What is the main difference between an array and a tuple in a large application?

The main difference between an array and a tuple in a large application is the type of data they can store. Arrays can only store elements of the same type, while tuples can store elements of different types. Additionally, arrays are mutable, meaning they can be modified, while tuples are immutable and cannot be changed once created.

When should I use an array in a large application?

Arrays are often used in large applications when the data being stored is homogenous and needs to be accessed and manipulated frequently. They are also useful for storing large amounts of data in a structured manner, making it easier to search and process the data.

When should I use a tuple in a large application?

Tuples are useful in large applications when the data being stored is not homogenous and needs to be accessed as a whole. They are also commonly used when the data needs to be passed between different parts of the application, as tuples are immutable and ensure that the data remains unchanged throughout the process.

Similar threads

Replies
3
Views
2K
Replies
2
Views
2K
Replies
4
Views
5K
Replies
31
Views
2K
Replies
11
Views
4K
Replies
1
Views
2K
Back
Top