0% found this document useful (0 votes)
44 views

Chapter 3

1) Arrays are containers that can hold a fixed number of items of the same type. Most data structures use arrays to implement algorithms. Each array element has a numerical index. 2) Basic array operations include traversing elements, inserting, deleting, searching by index or value, and updating elements. 3) Insertion examples covered are at the beginning, given index, after given index, and before given index. Deletion removes an element and reorganizes the array. Search can be by value or index. Update changes an element at a given index.

Uploaded by

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

Chapter 3

1) Arrays are containers that can hold a fixed number of items of the same type. Most data structures use arrays to implement algorithms. Each array element has a numerical index. 2) Basic array operations include traversing elements, inserting, deleting, searching by index or value, and updating elements. 3) Insertion examples covered are at the beginning, given index, after given index, and before given index. Deletion removes an element and reorganizes the array. Search can be by value or index. Update changes an element at a given index.

Uploaded by

Jenber
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Chapter 3

Arrays
Introduction

• Array is a container which can hold a fixed number of items and these items
should be of the same type.

• Most of the data structures make use of arrays to implement their algorithms.

• Each item stored in an array is called an element.


 
• Each location of an element in an array has a numerical index, which is used
to identify the element.

Prepared By: Eyob S. 2


Basic Operations Supported by an Array
• Traverse − Prints all the array elements one by one.

• Insertion − Adds an element at the given index.

• Deletion − Deletes an element at the given index.

• Search − Searches an element using the given index or by the value.

• Update − Updates an element at the given index.

Prepared By: Eyob S. 3


Insertion at the Beginning of an Array

• When the insertion happens at the beginning, it causes all the


existing data items to shift one step downward.

• Exercise 3.1

Prepared By: Eyob S. 4


Insertion at the Given Index of an Array

• In this scenario, we are given the exact location (index) of an array where a
new data element (value) needs to be inserted.

• Starting from the exact location where the value will be inserted shift each
element one step downward.

• Exercise 3.2

Prepared By: Eyob S. 5


Insertion After the Given Index of an Array

• In this scenario we are given a location (index) of an array after


which a new data element (value) has to be inserted.

• Exercise 3.3

Prepared By: Eyob S. 6


Insertion Before the Given Index of an Array

• In this scenario we are given a location (index) of an array before


which a new data element (value) has to be inserted.
 
• This time we seek till index-1, i.e., one location ahead of the given
index.

• Exercise 3.4

Prepared By: Eyob S. 7


Deletion Operation

• Deletion refers to removing an existing element from the array and


re-organizing all elements of an array.

• Exercise 3.5

Prepared By: Eyob S. 8


Search Operation

• You can perform a search for an array element based on its value
or its index.

• Exercise 3.6

Prepared By: Eyob S. 9


Update Operation

• Update operation refers to updating an existing element from the


array at a given index.

• Exercise 3.7

Prepared By: Eyob S. 10


…End…
Prepared By: Eyob S. 11

You might also like