Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

AIM: Write a program for Traversing in Linear Array: Description: It means processing or visiting each element in the array exactly once for one operation.

image text in transcribed

image text in transcribed

AIM: Write a program for Traversing in Linear Array: Description: It means processing or visiting each element in the array exactly once for one operation. Let 'A' is an array stored in the computer's memory and we want to display the contents of A, then it has to be traversed i.e. by accessing and processing each element of 'A' exactly once. Linear array A with lower boundary LB (0 in C++) and upper boundary ( UB = N - 1 in C++) where N is the number of values stored in the array. If the array is empty then N will be equal 0. SIZE is the total locations/positions available in array. This algorithm traverses A applying process to each element of A. SIZE = 10 Lower Bound N = 5 A[O] A[1] A[3] A[6] 1151 A[7] A[8] A[9 A[21 12 5 A[41 15 Algorithm: (Traverse a Linear Array) Here A is an array has N elements stored in it, with lower bound LB=0 and upper bound UB= N - 1. 1. K = LB and UB = N - 1 2. Repeat Steps 3 and 4 while K S UB. 3. Apply PROCESS to A[k]. 4. K = K+1. [End of Step 2 loop.] 5. End. The alternate algorithm using for-loop to traverse A: Algorithm: (Traverse a Linear Array) This algorithm traverse a linear array A with lower bound LB=0 and upper bound UB= N - 1. 1. Repeat for K = LB to UB Apply PROCESS to A[K]. [End of loop]. 2. Fnd. AIM: Write a program to Delete an Item from Linear Array: Description: Deletion refers to the operation of removing one of the element from the array A Deleting an item at the end of the array presents no difficulties. But, deleting an item from beginning or somewhere in the middle of array would require that each subsequent element be moved one location upward in order to fill up the array. The following algorithm deletes the Kth element from a linear array A with N values stored in it. Here A is a Linear Array with SIZE locations, N is the number of total values stored in A and K is a positive integer such that K

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions