Search for notes by fellow students, in your own course and all over the country.

Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.

My Basket

You have nothing in your shopping cart yet.

Title: Understanding Memory and Arrays in Programming
Description: An array is a linear data structure that collects elements of the same data type and stores them in contiguous and adjacent memory locations. Arrays work on an index system starting from 0 to (n-1), where n is the size of the array.

Document Preview

Extracts from the notes are below, to see the PDF you'll receive please use the links above


Understanding Memory and Arrays in
Programming
In programming, memory is essentially a long tape of bytes, with each
byte containing 8 bits
...
To understand the need for arrays, we need to examine
how areas can be declared, initialized, and represented in memory
...
For example, the data type int typically takes up 4 bytes
to store an integer
...
In traditional compilers, we generally
take 2 or 4 bytes to be the data type for storing numbers
...

The memory manager would allocate some memory for storing a
variable, and the value stored in memory would be represented in
binary
...

Using Arrays
An array is a collection of more than one element of the same datatype
...
The number of
elements in an array is determined by the size of the array
...
In C
language, for example, we would write:
int n;
to declare an integer variable
...

Initializing Arrays

Arrays can also be initialized with values
...
In a one-dimensional array, the elements are
stored in a single row with multiple columns
...
For example, an array of integers would take up 2-4 bytes of
memory per element
...


Arrays in Memory
In this video, we will discuss how data is stored in arrays in memory
...
The array can be statically initialized at
compile time or dynamically initialized at runtime
...
The elements
are stored in sequential/continuous locations with each element taking
up the same amount of memory
...
The size of the array is the number of elements it can hold
(n), with the index ranging from 0 to n-1
...

The array follows the random access method, and accessing an element
has a time complexity of O(1)
...
We may not know how much
space we need until runtime
...
If we allocate less space than needed, we
will run out of memory
...
The amount of memory allocated is not contiguous, and the
location of the data may not be known
...
2 Array Operations - Traversal, Insertion |
Explanation with C Program | DSA Course
Jenny's Lectures CS IT

Operations on Arrays in Data Structure
In this blog post, we will be discussing the various operations that can
be performed on 1D arrays in data structures
...

Today, we will focus on how to traverse an array, how to insert data into
an array, and the three types of insertion (at the beginning, at the end,
or at a specific position)
...

Traversal and Insertion with Code Examples
We will start by discussing how to traverse an array and insert data into
an array, with the help of code examples
...

Array Size and Memory Allocation

Before we dive into the code, it's important to understand that the size
of an array is fixed at compile time and cannot be changed at runtime
...
For example, if we declare an
array of size 50, 200 bytes of memory would be allocated by the

memory manager
...

Reading and Writing Data

Now, let's discuss how to read and write data in an array
...

When using scanf , we write %d for integers
...

Maximum Array Size and User Input

The maximum size of an array is determined by the limit of the size of
an array
...
For example, if the size of the
array is five, the user can insert five elements only
...

The value to insert starts at 0 and goes up to 4
...
The
maximum number of elements is the total number of items that can be
inserted, not the size of the array
...

The result of the value can be an error or a number
...

Searching for a particular key in an array will also be discussed
...
By following the code examples provided in this blog post,
you should have a better understanding of how to traverse an array,
insert and delete data, and sort an array
...
We will also cover how to modify the code to insert data at the
beginning and end of the array
...
Next, we write a 'for'
loop to create a diary using an array
...

It is important to note that there is no concept of bound checking in an
array
...
To check for an overflow condition, we can insert the
following line of code after inserting the size:
if(size > 50){
printf("Overflow condition");
}

If the array is not full, we can insert a new element at a specific position
using the following code:
if(!full){
for(i=size;i>pos;i--){
a[i]=a[i-1];
}

a[pos]=num;
size++;
}

If the array is full, we cannot insert a new element
...


1
...
We will
use an example array of size 5 to explain the process of deleting data
from a specific position, beginning, and end of the array
...

First, we initialize an array of size 50 but ask the user for the number of
elements they want to insert
...
For
example, if they choose position 2 (index 1), we cannot leave that space
blank
...

We start a loop to shift the elements to the left, starting from the index
before the position chosen by the user until the second last index of the
array
...
If we want to print the
deleted data, we store it in a separate variable before shifting the
elements
...


int size = 5;
item;

int arr[size];

int pos, i;

// ask user for position to delete

printf("Enter position to delete: ");
&pos);

// check if valid position

|| pos > size) {
position %d", pos);
shift elements
arr[i] = arr[i+1];

scanf("%d",
if (pos <= 0

printf("Invalid position");

else if (pos == size) {

of array

int

}

printf("No data at

} else {

// start loop to

for (i = pos-1; i < size-1; i++) {
}

size--; // decrease size

}

When deleting data from an array, shifting the elements is necessary to
maintain the order of the array
...
The array's
size is also decremented by one after shifting
...
If deleting from the beginning, all
values are shifted to the left, and the updated array starts from index 0
...
Therefore, it is
essential to check the boundaries of the array before entering data
...

The time complexity of deleting data from an array depends on the
position of the data being deleted
...
If deleting from the end, the time
complexity is θ(1) because no shifting is necessary
...

If the array is unsorted, the quickest algorithm for deleting data is to
replace the deleted element with the last element of the array
...
However, if the array is sorted, this
method will disturb the order of the elements, and the shifting method
must be used
...
6 Pointers and 2-D Arrays | Two dimensional Array |
Data Structures & Algorithm Tutorials
Jenny's Lectures CS IT

2D Arrays and Pointers
In this article, we will discuss how 2D arrays are related to pointers and
how you can access the elements of a 2D array with the help of
pointers
...

Each 1D array has three integer elements and the 2D array is an array of
3 1D arrays
...

A pointer variable can be declared to contain the address of an integer
variable
...
Instead, the address of [0][0] can be used
...
You can also use the
name of the array or the address of [0][0]
...

When accessing a 1D array, the name of the array will return the
address of the first element, while adding 1 to the pointer will point to
the next element
...
To print the value at a specific
index of the array, use the dereferencing operator
...
To access a value at a
specific index, use the expression a[i][j] or s*(a+i)+j
...



Title: Understanding Memory and Arrays in Programming
Description: An array is a linear data structure that collects elements of the same data type and stores them in contiguous and adjacent memory locations. Arrays work on an index system starting from 0 to (n-1), where n is the size of the array.