0% found this document useful (0 votes)
2 views12 pages

Array Data Structures - Programming Logic II

The document outlines key concepts of array data structures, including their definition, manipulation, and built-in methods in JavaScript. It explains the organization of data in arrays, how to declare and access them, and the use of loops for efficient data handling. Additionally, it covers dynamic loading and methods for adding or removing elements from arrays.

Uploaded by

lolxdlkmeu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views12 pages

Array Data Structures - Programming Logic II

The document outlines key concepts of array data structures, including their definition, manipulation, and built-in methods in JavaScript. It explains the organization of data in arrays, how to declare and access them, and the use of loops for efficient data handling. Additionally, it covers dynamic loading and methods for adding or removing elements from arrays.

Uploaded by

lolxdlkmeu
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PROGRAMMING LOGIC II

ARRAY DATA
STRUCTURES
José Dario Pintor da Silva
LEARNING OBJECTIVES

1 DATA STRUCTURE CONCEPT


Understand how organized data enables efficient memory
operations.
2 ARRAY DEFINITION
Learn about sequential storage and the power of indexed
access.

3 MANIPULATION
Master creating, initializing, and modifying arrays in
JavaScript.
4 ITERATION
Use for loops and the length property to traverse entire
collections.

5 BUILT IN METHODS
Explore essential tools like push, pop, shift, and unshift.
ATOMS & MOLECULES

01 THE ANALOGY
A Data Structure is an organized way to
store and relate data in memory. It defines Primitive Types are "atoms" (basic
values).
not just values, but how they interact.
Data Structures are "molecules"
built from atoms, enabling higher-
level operations.
THE TOOLBOX

02  ARRAYS VECTORS
Indexed lists of elements stored sequentially.
Just as a carpenter has different tools for  STACKS & QUEUES
different cuts, programmers choose Data LIFO Last In, First Out) and FIFO First In, First Out) logic.

Structures based on the specific problem  TREES & GRAPHS


For hierarchical relations and complex network connections.
they need to solve.
SEQUENTIAL STORAGE

03 ONE NAME, MANY


VALUES
An Array is a sequence of values stored
sequentially in memory under a single
50 variables for
variable name. It acts as an indexed list of
Instead of creating

50 names, you create one array.


elements.
JavaScript is flexible, allowing

different data types in the same

sequence .
INDEX SYSTEM

05 10 20 30 40 50
An array is a set of "boxes" in memory.
Each box is identified by a number called 0 1 2 3 4
an index. The first element is always at index 0.
The last element is at index 4 (length 5 1 .

Range: 0 to (length - 1)
DECLARING ARRAYS

07 Array of numbers
let numbers = [10, 20, 30];
The most common way to create Array of strings
arrays in JavaScript is using brackets let fruits = ["apple", "pear"];
[]. You can start empty or pre-fill
Mixed types (permitted but use with care)
them with values. let mixed = [1, "text", true];

Empty array
let empty = [];
ACCESS & UPDATE

08 let scores = [85, 90, 75];

To access or modify an element, use the Reading a value


[Link](scores[0]); 85
array name followed by the index in

brackets. It works for both reading and


Modifying a value
writing values. scores[2] = 80;
[Link](scores[2]); 80

The array is now: [85, 90, 80]


AUTOMATION
09 let data = [10, 20, 30, 40, 50];

Accessing positions manually is impossible for (let i = 0; i < [Link]; i ) {


[Link](`Pos ${i}: ${data[i]}`);
for large lists. We use loops to traverse }
entire collections efficiently.
[Link] is 5
i goes from 0 to 4
The length Property: Automatically tracks the
number of elements, ensuring the loop stays
within valid bounds.
DYNAMIC LOADING

10 let count = 5;
let numbers = new Array(count);

You can fill arrays with user input via Filling the array
for (let i = 0; i < count; i ) {
terminal or browser Use a loop to
.
let input = prompt(`Enter value ${i+1}:`);
numbers[i] = Number(input); Convert to number
prompt for each value and store it at }

index i
. Displaying results
[Link]("Values entered:", numbers);
END OF ARRAY

11 let list = ["A", "B"];

push() adds one or more elements to the Adding to the end


[Link]("C"); ["A", "B", "C"]
end of the array. pop() removes the last
element and returns it. Removing from the end
let last = [Link]();

[Link](last); "C"
[Link](list); ["A", "B"]
START OF ARRAY

12 let queue = ["Bob", "Charlie"];

Add to start
unshift() adds elements to the [Link]("Alice");
beginning, while shift() removes the ["Alice", "Bob", "Charlie"]
first element. Both methods re-index
Remove from start
the entire array. let first = [Link]();

[Link](first); "Alice"
[Link](queue); ["Bob", "Charlie"]

You might also like