Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Arrays PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

ARRAYS

Array and their usage, sorting algorithm –


selection sort and bubble sort, search in
sorted array. The class objects compatible
with all the class.

Q. What do you understand by Arrays?


How you declare an Array?
Ans: An Array is a collection of variables
of the same data type that are referenced
by a common name. Array can be declared
by the following statements: int n[]=new
int[10];
Q. What are the different types of arrays?
(i) Single Dimensional Arrays: A list of
items can be given one variable name
using only one subscript and such a
variable is called a single subscripted
variable or a one or single dimensional
array.
(ii) Multi Dimensional Arrays: This type
of arrays are actually arrays of arrays.
Q. Why we use Arrays? or What are the
Advantages of using Arrays.
Ans: The Advantages or Arrays are: (i)
Easy to Specify. (ii) Free from run-time
overload. (iii) Random access of elements.
(iv) Fast Sequential Access.
Q. How can arrays be initialized?
Ans: Array can be initialized at the time of
declaration by providing the value list at
the same time.
Q. What do you understand by out-of-
bound subscripts?
Ans: The subscripts other than 0 to n-1 for
an array having n elements are called out-
of-bounds subscripts.
Q. What do you mean by Binary Search?
Ans: This search technique searches the
given ITEM in minimum possible
compression. The Binary search requires
the array must be sorted in any order. The
search ITEM is compared with middle
element of the array. If the ITEM is more
then the middle element later part of the
arrays becomes the new array segment.
The same process is repeated until either
the ITEM is found or the array segment is
reduce to single element.
Q. Differentiate between linear search and
binary search techniques?
Ans: In linear search each elements of the
array is compared with the given item to
be searched for one by one while binary
search searches for the given item in a
sorted array. The search segment reduces
to half at every successive stage.
Q. State the conditions under which Binary
Search is applicable?
Ans: For Binary Search The List must be
sorted, lower bound upper bound and the
sort order of the list must be known.
Q. Comment on the efficiency of linear
search and Binary Search in relation to the
number of element in the list being
searched?
Ans: The Linear search compares the
search item with each element of the array,
one by one. If the search item happens to
be in the beginning of the array, the
compressions are low, however if the
element to be searched for is one of the last
elements of the array, this search technique
proves the worst as so many comparisons
take place. The Binary search on the other
hand, tries to locate the search item in
minimum possible comparisons, provided
the array is sorted. This technique proves
efficient in nearly all the cases.
Q. What do you mean by sorting?
Ans: Sorting of an array means arranging
the array elements in a specified order.
Q. What is Selection sort?
Ans: In selection sort the smallest ( or
largest depending upon the desired order)
key from the remaining unsorted array is
searched for and put in the sorted array.
The process repeats until the entire array is
sorted.
Q. What is Bubble sort?
Ans: In bubble sort the adjoining values
are compared and exchanged if they are
not in proper order. This process is
repeated until the entire array is sorted.
Q. Which element is num[9] of the array
num?
Ans: 10th element. Because the first index
number/subscript value of an array is 0. So
9th element is treated as the 10th element
in an array.

You might also like