CPE 110L DATA STRUCTURES AND ALGORITHM ANALYSIS ENGR. ANGELUS VINCENT P.
GUILALAS
St. Paul University Surigao
COLLEGE OF ENGINEERING
Surigao City, Philippines
Data Structures and
Algorithm Analysis
Laboratory Exercises
PREPARED BY:
ENGR. ANGELUS VINCENT P. GUILALAS
Laboratory Exercises Page 1
CPE 110L DATA STRUCTURES AND ALGORITHM ANALYSIS ENGR. ANGELUS VINCENT P. GUILALAS
Student Report
CpE 102 DATA STRUCTURES AND ALGORITHM ANALYSIS (Lab)
2ND Semester, SY 2012-2013
Name: Joseph Bryan J. Sarvida Course and Year: BSCpE-III
Laboratory Exams
Major Exams Perfect Score Score Remarks
Midterm Exam
Final Exam
Laboratory Exercises
Instructor’s
Exercise # Title Date Performed Rating
Signature
ARRAY
1 Dec. 5, 2017
Insertion at the Beginning of an Array
Laboratory Exercises Page 2
CPE 110L DATA STRUCTURES AND ALGORITHM ANALYSIS ENGR. ANGELUS VINCENT P. GUILALAS
Exercise No. 4
Insertion of data anywhere in array
OBJECTIVES
1. Provide practical implementation of insertion of array.
2. Implement insertion of array at the beginning using C++
3. Illustrate the insertion operation in array.
EQUIPMENT
Quantity
1 PC with Microsoft Visual Studio C++ per student
DISCUSSION
Array
Array is a container which can hold a fix 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. Following are the important terms to understand the concept of Array.
Element − each item stored in an array is called an element.
Index − each location of an element in an array has a numerical index, which is used to identify the element.
Array Representation
Arrays can be declared in various ways in different languages. For illustration, let's take C array declaration.
Arrays can be declared in various ways in different languages. For illustration, let's take C array declaration.
As per the above illustration, following are the important points to be considered.
Index starts with 0.
Array length is 8 which means it can store 8 elements.
Each element can be accessed via its index. For example, we can fetch an element at index 6 as 9.
Laboratory Exercises Page 3
CPE 110L DATA STRUCTURES AND ALGORITHM ANALYSIS ENGR. ANGELUS VINCENT P. GUILALAS
Basic Operations
Following are the 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.
Insertion Operation
Insert operation is to insert one or more data elements into an array. Based on the requirement, a new element can be
added at the beginning, end, or any given index of array.
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. Here,
we design and implement an algorithm to insert an element at the beginning of an array.
Algorithm
We assume A is an array with N elements. The maximum numbers of elements it can store is defined by MAX. We
shall first check if an array has any empty space to store any element and then we proceed with the insertion process.
Implementation in C++
Screen Shoots
GENERALIZATION
Laboratory Exercises Page 4