How to Organize Data Using Data Structures: Files, Arrays, Lists and Others

An error occurred trying to load this video.

Try refreshing the page, or contact customer support.

Coming up next: How to Write a Program: Coding, Testing & Debugging

You're on a roll. Keep up the good work!

Take Quiz Watch Next Lesson
Your next lesson will play in 10 seconds
  • 0:32 Files
  • 1:22 Lists
  • 2:14 Array
  • 3:27 Stacks
  • 4:26 Queue
  • 6:05 Trees
Save Save Save

Want to watch this again later?

Log in or sign up to add this lesson to a Custom Course.

Log in or Sign up

Speed Speed Audio mode

Recommended Lessons and Courses for You

Lesson Transcript
Instructor: Paul Zandbergen

Paul is a GIS professor at Vancouver Island U, has a PhD from U of British Columbia, and has taught stats and programming for 15 years.

A data structure is a collection of data elements that are organized in some way. Learn about the different types of data structures in programming, such as files, lists, arrays, stacks, queues and trees.

Data Structure

Data structures provide a way of storing and organizing data in a computer. Programming uses a number of different data structures. Within a program, a data structure is a collection of data elements that are organized in some way. For example, a collection of elements could be organized and numbered in sequence. Common data structures are files, lists, arrays, stacks, queues and trees.


A computer file is used for storing information. Computer programs can use files to read the information that needs to be processed and to write the results of the processing. The data inside a file is typically organized in smaller packets of information, which are often referred to as 'records' or 'lines.'

For example, a file can contain the payroll information for each employee, with each employee represented by a line. A computer program can read this information line by line and perform some type of payroll-related operation, such as calculating benefits for a certain pay period. The results could be added to the existing file or written to a new file. Files make it possible for different programs to share information, as one file can be passed onto the next.


A list contains elements of one particular data type. For example, a list could contain strings. An example would be the names of all the players on a soccer team. Each name is a string, but when you organize all the names together, they form a list. A list is the simplest data structure.

For example, a list of strings could look like this:

('John,' 'Paul,' 'George,' 'Ringo')

A list of numbers could look like this:

(67, 84, 92, 52, 81, 75)

Each element in a list is identified by a specific index. All elements in a list are ordered in one particular sequence, and the index for an element tells you at what position in the sequence that element is located. Typically, the index value of the first position is zero (0).


An array is a data structure where the elements are identified by one or more indices. An array is similar to a list, but an array can have multiple dimensions. A one-dimensional array is the same as a list: a linear sequence of elements that are all of the same type.

In a two-dimensional array, the elements are organized in two dimensions, which you can think of as the rows and columns of a table. This type of array uses two indices: one for rows and one for columns. The unique combination of two index values represents a unique cell in the table. Each cell corresponds to an element, which can be a string, a number or some other type of data.

A two-dimensional array is also called a matrix. A three-dimensional array can be represented by a cube and uses three indices. Arrays can have more dimensions, but they are more difficult to visualize.

Arrays make it possible to organize data in an efficient manner because the indices make it possible to retrieve any element. They are relatively easy to implement. However, all the elements have to be of the same type, and searching through a large array can be time consuming if it is not sorted.


A stack is a data structure where elements are only inserted or deleted at the top. A stack is similar to a list, but it can contain any type of element. Contrary to a list, the order of the elements is fixed and cannot be changed. This limits the operations that can be performed on it. There are basically only two operations: push and pop. Push adds an item to the top of the stack, and pop removes an item from the top of the stack.

A stack is a last in, first out (LIFO) data structure. Elements are removed in the reverse order of their addition. The easiest way to visualize a stack is as a pile of books, and the only thing you can do is to add a book to the top or remove a book from the top. This is not a very sophisticated data structure, but it is very efficient. Stacks can be very large, and yet you can work with a stack very quickly since you are only concerned with the item at the top.


A queue is a data structure where the elements are kept in order and where elements are inserted at one end and deleted at the other. A queue is a first in, first out (FIFO) data structure. The first element in a queue will be the first one to be removed. You can also keep adding elements or keep removing elements, and the queue can get longer or shorter.

To unlock this lesson you must be a Member.
Create your account

Register to view this lesson

Are you a student or a teacher?

Unlock Your Education

See for yourself why 30 million people use

Become a member and start learning now.
Become a Member  Back
What teachers are saying about
Try it risk-free for 30 days

Earning College Credit

Did you know… We have over 200 college courses that prepare you to earn credit by exam that is accepted by over 1,500 colleges and universities. You can test out of the first two years of college and save thousands off your degree. Anyone can earn credit-by-exam regardless of age or education level.

To learn more, visit our Earning Credit Page

Transferring credit to the school of your choice

Not sure what college you want to attend yet? has thousands of articles about every imaginable degree, area of study and career path that can help you find the school that's right for you.

Create an account to start this course today
Try it risk-free for 30 days!
Create an account