GROUP 1
BUILDING WITH BLOCKS: ESSENTIAL
DATA STRUCTURES LISTS & SETS
GROUP 1
QUOTES TODAY
"Programmers are very
important in a company
for system development
and marketing."
- Cia Rodriguez
GROUP 1
LESSON 1: BUILDING WITH BLOCKS
ESSENTIAL DATA STRUCTURES
1. Lists
Ordered collection of items
Can store numbers, text, or both
Elements can be accessed by index (starts at 0)
You can add, remove, or update elements
GROUP 1
OUTPUT ✅ Output:
apple
apple
Mango
GROUP 1
2. SETS
1. 🔑 What is a Set?
A collection that stores unique elements only (no duplicates).
Unordered → does not guarantee insertion order.
Can contain null, but only once.
Common Implementations:
HashSet → fastest (no order).
LinkedHashSet → keeps insertion order.
TreeSet → keeps elements sorted.
2. ✨ Why use a Set?
When you want to avoid duplicates (e.g., student IDs, emails).
When you only care about membership (is an item inside or not?).
Faster search than a list for checking if something exists.
SALFORD & CO.
3. BASIC EXAMPLE
(HASHSET)
IMPORT [Link].*;
PUBLIC CLASS MAIN {
PUBLIC STATIC VOID MAIN(STRING[] ARGS) {
HASHSET<STRING> FRUITS = NEW HASHSET<>();
[Link]("APPLE");
[Link]("BANANA");
[Link]("MANGO");
[Link]("APPLE"); // DUPLICATE IGNORED
[Link](FRUITS);
}
}
GROUP 1
✅ OUTPUT:
[BANANA, APPLE, MANGO] // ORDER IS NOT
GUARANTEED, NO DUPLICATES
GROUP 1 4. 🔍 COMMON OPERATIONS
IMPORT [Link].*;
PUBLIC CLASS OPERATION{
PUBLIC STATIC VOID MAIN(STRING[] ARGS) {
HASHSET<INTEGER> NUMBERS = NEW HASHSET<>();
[Link](10);
[Link](20);
[Link](30);
// MEMBERSHIP
[Link]([Link](20)); // TRUE
[Link]([Link](40)); // FALSE
// REMOVE
[Link](10);
[Link](NUMBERS); // [20, 30]
// SIZE
[Link]("SIZE: " + [Link]()); // 2
// ITERATION
FOR (INT N : NUMBERS) {
[Link](N);
}
}
}
GROUP 1
✅ OUTPUT:
TRUE
FALSE
[20, 30]
SIZE: 2
20
30
GROUP 1
5. ⚡ SET OPERATIONS
✅ OUTPUT:
UNION: [1, 2, 3, 4,
5, 6]
INTERSECTION: [3,
4]
DIFFERENCE: [1, 2]
GROUP 1
6. 📝 SUMMARY
SET = UNIQUE ELEMENTS, NO DUPLICATES.
HASHSET = FASTEST, UNORDERED.
LINKEDHASHSET = KEEPS ORDER.
TREESET = SORTED ORDER.
USEFUL FOR: UNIQUE DATA, SEARCHING, SET
OPERATIONS.
GROUP 1
THANK YOU