Computer ScienceChapter 3: Programming Fundamentals
3.4.1 Array & List are Similar
An Abstract Data Type (ADT)
Explanation level
Introduction
An ordered sequence of elements is called a list. A list is an Abstract Data Type (ADT), where an ADT is a data type which acts for defined operations only. In simple words, though JavaScript provides some basic data types to use, it also allows introducing newer data types that are abstract, for which the definition and corresponding operations need to be explicitly mentioned.
Definition
An Abstract Data Type (ADT) is a mathematical model for data types where the data type is defined by its behavior (operations) rather than its implementation. A list is an ADT that represents an ordered collection of elements.
An array is a concrete data structure that stores elements in contiguous memory locations and provides index-based access.
Main Idea
Arrays and lists are JavaScript data structures that can hold and manage collections of data. Lists and arrays may both arrange things in an ordered fashion for a set of elements. Every element is stored and accessed via an index number which starts at 0, which shows its position. Based on this index number, values can be searched for and updated if required.
Core Concept
Both are able to hold all types of data, i.e., an array or list can include words, numbers, or even a combination of the two. Both are able to expand or contract to hold items, since adding or removing items as required is quite easy. In simplest form, a list is implemented using an array.
Detailed Explanation
Similarities Between Arrays and Lists
| Feature | Array | List |
|---|---|---|
| Ordered collection | Yes | Yes |
| Index-based access | Yes (starts at 0) | Yes (starts at 0) |
| Can hold different data types | Yes | Yes |
| Can expand/contract | Yes | Yes |
| Can search and update values | Yes | Yes |
| Can store words, numbers, or both | Yes | Yes |
Key Points
- Both arrays and lists store elements in an ordered fashion.
- Both use index numbers starting at 0 to access elements.
- Both can hold any type of data (words, numbers, or a combination).
- Both can expand or contract as items are added or removed.
- In its simplest form, a list is implemented using an array.
Abstract Data Type (ADT)
A list is an Abstract Data Type (ADT). This means:
- The list is defined by its operations (add, remove, search, etc.).
- The implementation (how it works internally) is hidden.
- JavaScript provides basic data types, but also allows creating newer abstract data types for which the definition and operations need to be explicitly mentioned.
- `add(item)` — add an item to the list.
- `remove(item)` — remove an item from the list.
- `search(item)` — search for an item in the list.
- `get(index)` — get the item at a specific index.
- `size()` — get the number of items in the list.
Intermediate Level
At the intermediate level, you should understand the relationship between arrays and lists.
- A specific implementation.
- Stores elements in contiguous memory.
- Provides index-based access.
- In JavaScript, arrays are a built-in data type.
- A conceptual model.
- Defined by its operations (add, remove, search).
- Can be implemented using an array, linked list, or other structures.
- In JavaScript, a list can be implemented using an array.
Key point: In JavaScript, the terms "array" and "list" are often used interchangeably because JavaScript arrays are flexible and can serve as lists.
Important Points
- - An ordered sequence of elements is called a list.
- - A list is an Abstract Data Type (ADT).
- - An ADT is defined by its operations, not its implementation.
- - Arrays and lists are similar in many ways.
- - Both use index numbers starting at 0.
- - Both can hold different data types.
- - Both can expand or contract.
- - In simplest form, a list is implemented using an array.
Remember
- - List = ordered sequence.
- - List = ADT.
- - ADT = defined by operations.
- - Array = concrete implementation.
- - Both use index starting at 0.
- - Both can hold any data type.
- - Both can grow/shrink.
- - List is implemented using array.
Common Mistakes
- - Thinking that arrays and lists are completely different (they are similar).
- - Forgetting that list is an ADT (defined by operations).
- - Confusing the implementation with the concept.
- - Thinking that arrays are always fixed-size (in JavaScript, they are dynamic).
- - Assuming that lists and arrays have different indexing (both start at 0).
- - Forgetting that both can hold different data types in JavaScript.
Quick Revision
- An ordered sequence of elements is called a list.
- A list is an Abstract Data Type (ADT).
- An ADT is defined by its operations.
- Arrays and lists are similar: ordered, index-based, can hold any data type, can expand/contract.
- In simplest form, a list is implemented using an array.
- In JavaScript, arrays and lists are often used interchangeably.
60-Second Revision
- List = ordered sequence.
- List = ADT (defined by operations).
- Array = concrete implementation.
- Both: ordered, index-based, any data type, expand/contract.
- List implemented using array.
- Warning: Don't confuse the list (abstract concept) with the array (concrete implementation). They are similar but not identical.
Did you understand this topic?
Your answer is saved with your learning record. It does not mark the topic as mastered.
Quick revision
Revision Zone
Review the key facts, formulas and checks before you move on.3.4.1 Array & List are Similar
Sticky Notes · Quick Revision
Key Point 1
- List = ordered sequence.
Key Point 2
- List = ADT.
Key Point 3
- ADT = operations.
Key Point 4
- Array = implementation.
Key Point 5
- Index starts at 0.
Key Point 6
- Both hold any data type.
Key Point 7
- Both grow/shrink.
Key Point 8
- List implemented using array.
Same supplied content as this Notes page (shared canonical source).