Sunday, 1 May 2016

Insert at the End of an array

According to the heading itself, it says that we are having an array and we have to insert at the end of array

Now to write an algorithm we may have input,output and logic to perform the task

Input: An array named as  "Array" and "Pos" describing the position till where the elements are filled, maximum size "size" and "value" the element to be inserted.

Output: Resultant Array with element inserted.






The figure describes an array named as Array it contains 2 data elements already stored as 1 and 2. The G  here is used to represent the garbage values in an array. Below we are having the index  of array element. From the figure we can get the size as 5 and pos as 2.
Now to insert at end we will follow following steps.

  1. Check the overflow condition that is pos+1==size  i.e. 4+1 =5 and we can’t store the next element.
  2. Set the value at the particular position and terminate. 
  3. Terminate the algorithm


Introduction to Data structure:Arrays

Data Structure :
According to me the data structure can be defined as the way of representing the data in such a manner that it can optimize both the memory requires to perform a particular task or execution time required to execute a particular task.

So to study various algorithms we will space and time complexity as a tool.

The most simple data structure is an array.

So we begin our discussion with an array.

Definition 1: An array can be described as the collection of element of similar type stored at the contiguous location.

The various operations that we can perform on array can be described as

1. Insertion:
The insertion in an array can be at any of the 3 locations
  1. Beginning of an array
  2. End of an array 
  3. Mid of an array
2. Deletion:
  1. Beginning of an array
  2. End of an array 
  3. Mid of an array
 3. Traversing
  1. Inorder
  2. Reverse Order
4. Searching