0% found this document useful (0 votes)
7 views9 pages

Array Concepts and Programming Questions

The document is a question paper on arrays worth 100 marks, divided into multiple choice questions, fill in the blanks, program snippets, differences, and programming tasks. It includes a variety of questions covering array concepts, operations, and programming techniques. The paper assesses knowledge on single and double dimensional arrays, searching algorithms, and requires practical programming skills to solve specific problems.

Uploaded by

maistudies101
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views9 pages

Array Concepts and Programming Questions

The document is a question paper on arrays worth 100 marks, divided into multiple choice questions, fill in the blanks, program snippets, differences, and programming tasks. It includes a variety of questions covering array concepts, operations, and programming techniques. The paper assesses knowledge on single and double dimensional arrays, searching algorithms, and requires practical programming skills to solve specific problems.

Uploaded by

maistudies101
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Question paper on Array - 100 marks

A Multiple Choice Questions 20Marks

Question 1

Which of the following is the correct usage?

1. a[-40]
2. a[40*0]
3. a[0 - 40]
4. None

Question 2

Which element is represented by a[11]?

1. 10th
2. 9th
3. 11th
4. None

Question 3

Cell numbers of a dimensional array are also known as:

1. packets
2. blocks
3. subscripts
4. compartments

Question 4

A dimensional array is also known as:

1. subscripted variable
2. actual variable
3. compound variable
4. none
Question 5

An array element can be accessed through:

1. dots
2. element name
3. index number
4. none

Question 6

Indicate the error message which displays, if the following statement is executed :
int a[5] = {28,32,45,68,12};

1. Insufficient cells
2. Array index out of bounds
3. Elements exceeding cells
4. None

Question 7

The following statement :


int code[ ]= {25,40,38,47};

1. assigns 47 to code[1]
2. assigns 25 to code[0]
3. assigns 38 to code[3]
4. assigns 47 to code[4]

Question 8

The elements of array[25] are numbered:

1. from 1 to 25
2. from 0 to 24
3. from 1 to 26
4. none

Question 9

Which of the following function finds the size of array


char m[] = {'R', 'A', 'J', 'E', 'N', 'D', 'R', 'A' };?

1. [Link] (a)
2. [Link] (m)
3. [Link]
4. None

Question 10

A Single Dimensional array contains N elements. What will be the last subscript?

1. N-1
2. N
3. N+1
4. None

Question 11

The size of an array that signifies the number of elements it can store is given using ...........
brackets.

1. {}
2. []
3. ()
4. All of these

Question 12

Given array int x[] = {11, 22, 33, 44}; the value of x[1] is ........... .

1. 11
2. 22
3. 33
4. Invalid value

Question 13

Given array int x[] = {11, 22, 33, 44}; the value of x[1+2] is ........... .

1. 11
2. 22
3. 33
4. 44

Question 14

If int arr[] = {3, 5, 7, 9}; what is the value of [Link]?

1. 3
2. 5
3. 4
4. Cannot be determined

Question 5

Given array int z[] = {15, 16, 17}; It will occupy ........... bytes in memory.

1. 3
2. 12
3. 24
4. 64

Question 16

A linear search ...........

1. can be used with sorted arrays only


2. can be used with unsorted arrays only
3. can be used with both sorted and unsorted arrays
4. cannot be used with arrays

Question 17

A binary search

1. can be used with sorted arrays only


2. can be used with unsorted arrays only
3. can be used with both sorted and unsorted arrays
4. cannot be used with arrays

Question 18

Which of the following statements is true?

1. Binary search is less efficient than the sequential search.


2. Binary search is less efficient than the linear search.
3. Binary search is more efficient than the sequential search.
4. Binary search is as efficient as the sequential search.

Question 19

In ........... search, the algorithm uses the middle value of the array for the search operation.

1. Binary
2. Linear
3. Bubble
4. Selection

Question 20

Which element is num[9] of the array num?

1. 8th
2. 9th
3. 10th
4. 11th

B Fill in the blanks 5 Marks

Question 1

Each element of a single dimensional array is accessed using variable along


with ________________ enclosed within square bracket.

Question 2

A double dimensional array uses ____________ types of indices.

Question 3

To access the elements in reverse order, the single dimensional array is traversed starting
with _____________ index.

Question 4

Declare integer array A of 50 elements

Question 5

The last index of a single dimensional array will be ___, if it is declared to store 8 elements.

C Give the output of the following program snippets 20


Marks

Question 1 2 Marks

int m[] = {2,4,6,8};


[Link](m[1] + " " + m[2]);
Question 2 2 Marks

int a[] = {2,4,6,8,10};


a[0] = 23;
a[3] = a[1];
int c = a[0] + a[1];
[Link]("Sum = "+c);

Question 3 2 Marks

int a[] = new int [5];


a[0] = 4; a[1] = 8; a[2] = 7; a[3] = 12; a[4] = 3;
[Link](a[2+1]);

Question 4 2 Marks

int a[4] = {2,4,6,8};


for(i = 0; i <= 1; i++)
{
s = a[i] + a[3-i];
[Link](s);
}

Question 5 2 Marks

int n[] ={1,2,3,5,7,9,13,16};


double a=[Link](n[4], n[1]);
double b=[Link](n[5]+n[7]);
[Link]("a=" + a);
[Link]("b=" + b);

Question 6 2 Marks
int x[] = {4, 3, 7, 8, 9, 10};
int p = [Link];
int q = x[2] + x[5] * x[1];
[Link]("p=" + p);
[Link]("q=" + q);
Question 7 2 Marks

int arr [ ] = { 1 2 , 1 0 , 5 , 8 , 7 } ;

[Link] ( [Link] + arr [ [Link] - 1 ] ) ;

[Link](arr[0]+++--arr[2]*arr[4]);

for(inti=0;i<[Link];i++)

[Link](arr[i]+"");

[Link]("\n is theoutput");

Question 8 2 Marks

char x[]={65,66,67,68,32}; //Note:32 is the ASCII of space char

[Link](x[0]+""+x[3]);

[Link](++x[1]);

[Link](x[1]);

for(inti=0;i<[Link];i++)

[Link](x[i]);

Question 9 4 Marks

Write Java statements for the following:

i. Create an array to hold 15 double values.

ii. Assign the value 10.5 to the last element in the array.

iii. Display the sum of the first and the last element.

iv. Write a loop that computes the sum of all odd elements in the array.
D Difference between 2 Marks each (10 marks)
1. Searching and Sorting
2. Single Dimensional Array and Double Dimensional Array
3. Linear search and Binary search
4. Subscript and subscripted variable
5. Bubble Sort and Selection Sort

E Write a program include description table


Solve any 3 45 marks

Question 1

Declare a single dimensional array of size 28 to store daily


temperatures for the month of February. Using this structure,
write a program to find:

1. The hottest day of the month


2. The coldest day of the month
3. The average temperature of the month

Question 2

Write a program to accept the year of graduation from school as


an integer value from the user. Using the binary search technique
on the sorted array of integers given below, output the message
"Record exists" if the value input is located in the array. If not,
output the message "Record does not exist".

Question 3

Write a program that reads ten integers and displays them in the
reverse order in which they were read.

Question 4

Write a program that reads a long number, counts and displays


the occurrences of each digit in it.

Question 5

Write a program to input 10 integer elements in an array and sort


them in descending order using bubble sort technique.

Question 6

Write a program to input A[4][4] in an array and calculate &


display the following

Product of Left Diagonal

Product of Right diagonal

Sum of prime numbers

Common questions

Powered by AI

In implementing binary search, maintain two pointers, left and right, pointing to the beginning and end of the array. While left is less than or equal to right, calculate the middle index. Compare the middle element with the target. If they are equal, target is found. If the target is less, adjust the right pointer to mid - 1; if more, adjust the left pointer to mid + 1. If the loop ends and the target is not found, it does not exist in the array .

A single-dimensional array stores elements in a linear form, accessed by a single index. In contrast, a double-dimensional array, or matrix, consists of rows and columns, requiring two indices for access. This structure is more suitable for complex data representations like grids or tables. Memory-wise, two-dimensional arrays consume more space given their added complexity but offer more flexibility in data manipulation .

The time complexity of linear search is O(n) because it potentially checks each element of the array until the target is found or all elements have been checked. Binary search is more efficient as it keeps halving the array's size and operates in O(log n) time complexity, leveraging the power of a sorted array to skip half the elements at each step .

To declare a single-dimensional array in Java, you specify the data type followed by square brackets and the variable name, such as "int[] arrayName". It is essential to know the array's size, which can be determined by the number of elements it can hold, specified within square brackets .

Linear search can be used on both sorted and unsorted arrays, while binary search requires the array to be sorted. In terms of efficiency, binary search is more efficient than linear search as it reduces the problem size by half with each step, operating in O(log n) time complexity compared to O(n) for linear search .

Subscript refers to the index or position used to access an element within an array, which provides the location within the array structure. A subscripted variable is the array element itself, accessed and manipulated using its subscript. Subscripts are essential in determining which element of the array is being referred to at any given time .

Memory allocation for a two-dimensional array involves creating arrays of arrays, consuming more memory space as each row is an independent array. Access is done using row and column indices, making data retrieval operations slightly more complex than the linear access of single-dimensional arrays. Although conceptually similar, double-dimension adds overhead in managing more sophisticated data structures .

A binary search algorithm relies on a sorted array as it checks the middle value and discards half the dataset, knowing that all preceding or subsequent elements are less or greater. If the array is unsorted, the algorithm might eliminate crucial parts of the array, leading to incorrect results or failure to find the target value .

Bubble sort is a simple sorting algorithm that repeatedly steps through the array, compares adjacent elements, and swaps them if they are in the wrong order. This process is repeated until the entire array is sorted. It is named "bubble sort" because smaller elements "bubble" to the top of the array, like bubbles in water. Despite its simplicity, it is inefficient on large datasets with an average and worst-case time complexity of O(n^2).

Indices in an array are critical for accessing specific elements. In a single-dimensional array, each element can be accessed using an index which starts at 0 and goes up to n-1, where n is the size of the array. Incorrect use of indices can lead to errors such as 'array index out of bounds', either causing data corruption or runtime errors .

You might also like