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: Arrays in data structures
Description: 1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation 1.2 Array Operations - Traversal, Insertion | Explanation with C Program | DSA Course 1.3 Array Operations | Deletion from Array | Explanation with Code | Data Structure

Document Preview

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


Arrays in Data Structure Notes

1
...
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
...
I have
paraphrased and corrected the text to make it more readable
...

1
...
We have already covered the fundamentals of arrays, including why
they are needed, how to declare them, and their memory representation in a previous post
...
The most important
operations we will cover are array traversal, insertion, deletion, sorting, and searching for a
particular key
...
We will also provide code for array deletion
...
Additionally, arrays do not have any bounds
checking property at runtime, so it is the programmer's responsibility to check the boundaries of
the array in the program
...
The base address is 100, so 100 to 299 bytes
should be allocated to this array
...
The scanf function is used to take
input from the user, and the printf function is used to print something on the output screen
...
We use a for loop to iterate over the array, and the
value starts from 0 till the size minus one (i++)
...
The user can
insert data into the array, and the number of data they want to insert is the size of the array
...

Inserting Data and Indexing
The user can insert data into an array by using the scanf function
...
The length of a single element is the same as the number of bytes that will be
inserted
...

The index for a value is a single number, and the number is not an error
...

Deletion and Sorting
In addition to insertion, we will also cover array deletion and sorting
...

Overall, arrays are an important data structure in computer science, and understanding how to
perform operations on arrays is essential for any programmer
...

Inserting Data at Specific Positions
In this tutorial, we will discuss how to insert data at specific positions in an array
...

First, we declare a variable 'i' and the header files
...
The code will look like this:
    int i;
    int a[50];
    for(i=0;i<5;i++){
      a[i]=i+1;
      printf("Index: %d, Value: %d\n",i,a[i]);
    }   
This code will create an array of size 50 and print the values of the array
...
It is the
programmer's responsibility to check the upper bound limit of the array
...
The programmer can choose to either not
insert any elements or overwrite an existing element
...
3 Array Operations | Deletion from Array | Explanation with Code | Data Structure
The deletion operation in arrays
...
We will also write the
code and analyze the time complexity of the operation
...
We then populate the array with the user's input and ask them which position they want

to delete data from
...
Instead, we shift the elements to fill the empty space and decrease the size of the
array by 1
...
We shift the element at index i+1 to
index i and continue until the end of the loop, overwriting the deleted element
...

We provide the code for the deletion operation, where we ask the user for the position to delete,
check if it's a valid position, and then start the loop to shift the elements
...
To delete data from a specific position, the value at that position is shifted to the left to fill
the gap
...
If deleting from the end of
the array, no shifting is necessary
...

When declaring an array, the size cannot be changed
...
If the size entered is greater than the maximum
size allocated for the array, an "out of bounds" message should be displayed
...
If deleting from a specific position, the time complexity is θ(n) because all elements
after the deleted element must be shifted to the left
...
If deleting from the beginning, the time complexity is
θ(n-1) because all elements must be shifted to the left
...
This method takes constant time (θ(1))
...



Title: Arrays in data structures
Description: 1.1 Arrays in Data Structure | Declaration, Initialization, Memory representation 1.2 Array Operations - Traversal, Insertion | Explanation with C Program | DSA Course 1.3 Array Operations | Deletion from Array | Explanation with Code | Data Structure