• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 2 out of 5 pages
Other

Arrays: Concepts, Operations, and Applications

Document preview thumbnail
Preview 2 out of 5 pages

This document provides an in-depth look at arrays, covering 1D arrays, 2D arrays, and multi-dimensional arrays. Learn common operations like sorting, searching, and manipulating arrays with practical examples.

Content preview

Arrays
Array Operations
Here are some common operations that can be performed on arrays:

1. Accessing Elements
You can access an element in an array using its index. In most programming
languages, indexing starts at 0.

Example (Python):

arr = [10, 20, 30, 40, 50]
print(arr[0]) # Output: 10 (first element)
print(arr[3]) # Output: 40 (fourth element)

2. Inserting Elements
Inserting elements into an array can be done at a specific index. However, in
languages like C, C++, and Java, arrays have a fixed size, so inserting an element
often requires resizing the array or using other data structures (like a list in
Python or ArrayList in Java).

Example (Python, dynamic array):

arr = [10, 20, 30]
arr.insert(1, 15) # Insert 15 at index 1
print(arr) # Output: [10, 15, 20, 30]

3. Deleting Elements
To delete an element, you can remove it by its value or index.

Example (Python):

arr = [10, 20, 30, 40, 50]
arr.remove(30) # Removes the first occurrence of 30
print(arr) # Output: [10, 20, 40, 50]

, In other languages like C++, you may have to shift elements manually after
deletion.

4. Traversing an Array
To access every element in an array, you need to traverse it using a loop.

Example (Python):

arr = [10, 20, 30, 40, 50]
for num in arr:
print(num)

Output:

10
20
30
40
50

5. Searching for an Element
You can search for an element in an array by iterating through all the elements.

Example (Python):

arr = [10, 20, 30, 40, 50]
if 30 in arr:
print("Found 30!")
else:
print("30 not found.")

6. Sorting
Sorting an array arranges its elements in a specified order (ascending or
descending). Many programming languages provide built-in sorting functions.

Example (Python):

Document information

Uploaded on
January 28, 2025
Number of pages
5
Written in
2024/2025
Type
Other
Person
Unknown
$5.29

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
0
Followers
0
Items
252
Last sold
-




Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions