Array Notes
Array Notes
Arrays - Notes
1. Dimensional Array:
A dimensional array is a structure created in the memory to represent a number of values of the same
data type with the variables having the same variable name along with different subscripts.
2. Two types of dimensional array:
Single dimensional array and Two dimensional array
3. What is the need of Dimensional Array? Explain
Variables are useful for keeping track of a single piece of information but as we collect more and more
information, keeping the variables organized can be complicated. In such situations, we need arrays to
solve the problems in a much better and efficient way.
4. A dimensional array is also called a subscripted variable.
5. An array with empty [] represents an unfixed number of cells in memory.
6. Index of an array having ‘n’ elements vary from 0 to n-1
7. Syntax for creating a single dimensional array:
<datatype> <variable>[]= new <datatype> <number of elements>;
Eg: int a[]= new int[10];
8. The different methods to store elements in an array are as follows:
a. Assignment statement:
int a[]= {1,2,3,4,5};
b. Using BlueJ system:
public static void main(int a[])
{//body
}
c. Using Scanner method:
The elements are accepted from the user using Scanner functions inside a loop.
for(i=0;i<5;i++)
{ a[i] = in.nextInt();
}
9. Name two basic operations performed on an array: Searching and Sorting
10. Name two types of searching techniques: Linear and Binary search
11. Name two types of sorting techniques: Selection sort and Bubble sort
12. Selection search is also known as Sequential search. It is the simplest technique in which an item is
searched from the starting position - one by one until the number is found or the end of the array.
13. Binary search is a technique used to find an element in the minimum possible time. It divides the
array into two halves and performs the search. The array needs to be sorted.
Algorithm/ Steps:
● Start with the middle element of the array as a current key.
● If the middle element value matches the target element then return the index of the middle
element.
● Else check if the target element is lesser than the middle element, then continue the search in
the left half.
● If the target element is greater than the middle element, then continue the search in the right
half.
● Check from the second point repeatedly until the value is found or the array is empty.
● If still unable to find the target, display search not successful
The linear search starts searching It finds the position of the searched
from the first element and element by finding the middle element
compares each element with a array.
searched element till the element
found.
In a linear search, the elements don't The pre-condition for the binary search is
need to be arranged in sorted order. that the elements must be arranged in a
order.
It is preferrable for the small-sized data It is preferrable for the large-size data sets.
The efficiency of the bubble sort The efficiency of the selection sort is
is less. high.
SDA DDA
The variables with same name The variables with the same name
have single subscript have two subscripts representing row
number and column number.