Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Introduction to Arrays in Programming

Rating
-
Sold
-
Pages
2
Uploaded on
05-03-2023
Written in
2020/2021

The document discusses the basics of arrays - a collection of data types stored in continuous memory locations. It highlights the need for arrays and the different types of arrays - fixed size and dynamic size - and their characteristics. The document also briefly touches upon how to use arrays. Examples are provided to illustrate the concepts discussed.

Show more Read less
Institution
Course

Content preview

Arrays in Data Structure
Data Structures and Algorithms
An array is an essential data structure in computer science and programming. It is a collection of
elements of the same data type that are stored in contiguous memory locations. Using arrays has many
advantages, including faster access to elements and simplified code.

Arrays are particularly useful when dealing with a large amount of data. For example, imagine we need
to store the temperature of every day of the year. We could create a separate variable for each day, but
that would require writing a lot of code and would not be efficient. Instead, we can use an array to store
all 365 temperatures in a single data structure.

There are two main types of arrays: fixed size arrays and dynamic size arrays. Fixed size arrays have a
fixed number of elements, which is specified when the array is declared. Once the array is created, its
size cannot be changed. This means that if we try to add more elements to the array than its capacity,
we will get an error.

Dynamic size arrays, on the other hand, can resize themselves as we add or remove elements. These
arrays are more flexible than fixed size arrays but may require more memory and processing time. In
most programming languages, dynamic size arrays are implemented using a data structure called a
"vector."

Here's an example of creating an array of integers in Python:

my_array = [1, 2, 3, 4, 5]

print(my_array[2])

This would output 3, since the third element of the array (at index 2) is 3.

In summary, arrays are a powerful data structure for storing collections of data. They allow us to access
elements quickly and simplify code by reducing the need for many individual variables. There are two
main types of arrays: fixed size arrays and dynamic size arrays. Fixed size arrays have a fixed number of
elements, while dynamic size arrays can resize themselves as we add or remove elements.

Here are some examples of arrays:

Integer array: an array that stores a sequence of integers.

int numbers[5] = {2, 4, 6, 8, 10};

In this example, we have defined an array of integers named "numbers" that has a fixed size of 5
elements. The elements of the array are initialized to the values 2, 4, 6, 8, and 10.

String array: an array that stores a sequence of characters.

char name[6] = {'J', 'o', 'h', 'n', 'n', 'y'};

Written for

Course

Document information

Uploaded on
March 5, 2023
Number of pages
2
Written in
2020/2021
Type
Class notes
Professor(s)
Prof abdul rehman
Contains
All classes

Subjects

$10.99
Get access to the full document:

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

Get to know the seller
Seller avatar
user111

Get to know the seller

Seller avatar
user111 University of Arizona College of Engineering
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
3 year
Number of followers
0
Documents
8
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

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