Understanding Arrays & Vectors: What They Do & Why They Matter

In summary, arrays are a collection of data that is indexed using natural numbers, vectors are a collection of data that is indexed using mathematical operations, and they are mostly used for graphics and gaming.
  • #1
ineedhelpnow
651
0
whats an array for?...whats a vector for? what do they do? what purpose do they serve?
 
Last edited:
Technology news on Phys.org
  • #2
ineedhelpnow said:
whats an array for?...whats a vector for? who do they do? what purpose do they serve?

Arrays are a collection of data. It holds a sequence of information indexed using natural numbers. Vectors are like those in mathematics. They have specialized operations like adding , scalar-multiplication and so on.

Usually we use arrays and vectors to store data that share a certain property. For example , the students in a class , a finite subset of even numbers , list of books on a library. Most of the time , the size of an array is fixed once declared. Arrays , are mostly used in graphics and gaming.
 
  • #3
ZaidAlyafey said:
Arrays are a collection of data. It holds a sequence of information indexed using natural numbers. Vectors are like those in mathematics. They have specialized operations like adding , scalar-multiplication and so on.

Usually we use arrays and vectors to store data that share a certain property. For example , the students in a class , a finite subset of even numbers , list of books on a library. Most of the time , the size of an array is fixed once declared. Arrays , are mostly used in graphics and gaming.

I would say arrays have more uses than outside graphics and gaming. Most nontrivial programs feature arrays in some way. Arrays and key-value stores (dictionaries/maps) are the most basic data structures.

Also, I think NHN is talking about std::vector, not an actual 3D vector (std::vector is just a type-safe dynamic array). I seriously hate that it's called a "vector" and not an array or list, it's really confusing (even more confusingly, there is an std::list, but it's implemented as a linked list, and hence not usually worth using).
 
  • #4
A vector is an ordered list of items of a given data type.
this is what i have as a definition but i still don't really get it.
 
  • #5
i remember he said in class that we don't ACTUALLY use arrays when we code or something like that. and that got me very confused. he didn't explain it. he just mentioned something about not using them when coding and then he cut off.
 

1. What is an array?

An array is a data structure that stores a collection of elements of the same data type in a sequential manner. Each element in the array is assigned a unique index number, allowing for efficient access and manipulation of the data.

2. What is a vector?

A vector is a mathematical object that represents both magnitude and direction. In computer science, a vector is often used to store and manipulate a collection of values, similar to an array. However, unlike arrays, vectors can dynamically resize and can store elements of different data types.

3. What is the difference between an array and a vector?

Arrays and vectors are similar in that they both store collections of data. However, arrays have a fixed size and can only store elements of the same data type, while vectors can dynamically resize and can store elements of different data types.

4. Why are arrays and vectors important in computer science?

Arrays and vectors are important in computer science because they allow for efficient storage, access, and manipulation of data. They are also essential in many algorithms and data structures, making them a fundamental concept in computer science.

5. How do arrays and vectors relate to each other?

Arrays and vectors are related in that they both store collections of data. Vectors can be viewed as a more flexible and dynamic version of arrays, as they can perform similar operations but with added features such as resizing and storing different data types.

Similar threads

  • Programming and Computer Science
Replies
20
Views
1K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
6
Views
979
  • Programming and Computer Science
Replies
6
Views
1K
  • Programming and Computer Science
Replies
17
Views
2K
Replies
3
Views
1K
  • Programming and Computer Science
Replies
13
Views
3K
  • Programming and Computer Science
Replies
13
Views
1K
  • Programming and Computer Science
Replies
20
Views
3K
  • Programming and Computer Science
Replies
2
Views
1K
Back
Top