Sunday, November 13, 2022

tap 10 Array interview question

top 10 Array interview question,Array question


 Q.1 Which of following is a disadvantage of array?

        a. Stack and Queue data structures can be implemented through an array.

        b. Index of the first element in an array can be negative.

        c. Wastage of memory if the element inserted in array are lesser than the allocated size.

        d. Element can be accessed sequentially.


Q.2 Assuming int is of 4 bytes, what is the size of int arr[15]?

        a. 15

        b. 19

        c. 11

        d. 60


Q.3 Let the base address of the first element of the array is 250 and each element of the array occupies 3 bytes in the memory, then address of the fifth element of a one-dimensional array a[10] ?

        a. 250

        b. 262

        c. 270

        d. 150


Q.4 A program P reads in 500 integers in the range [0 ....100] experimenting the scores of 500 students. It then prints the frequency of each score above 50. What would be the best way for P to store the frequencies?

        a. An array of 50 numbers

        b. An array of 100 numbers.

        c. An array of 500 numbers.

        d. A dynamically allocated array of 550 numbers


Q.5 If row-major order is used, how is the following matrix stored in memory ?

            a b c

            d e f

            g h i

        a. ihgfedcba

        b. abcdefghi

        c. cfibehadg

        d. adgbehcfi


Q.6 Consider a two dimensional array A[20] [10]. Assume 4 words per memory cell , the base address of array A is 100, element are stored in row-major order and first element is A[0] [0]. What is address of A[11] [5] ?

        a. 560

        b. 460

        c. 570

        d. 575


Q.7 Let a be a two dimensional array declared as follows:

    A: array [1....... 100] [1 ....... 15] of integer;

Assuming that each integer takes one memory location , the array is stored in row-major order and the first element of the array is stored at location 100, what is the address of the element a[i] [j]?

        A. 15i + j +84

        B. 15j + i + 84

        C. 10i + j + 89

        D. 10j + i + 89


Q.8 What is the output of the following C code? Assume that the address of x is 2000 ( in decimal ) interger requires for bytes of memory.

            #include<stdio.h>

            int main()

            {

             insigned int x[4] [3] = {{1,2,3}, {4,5,6}, {7,8,9}, {10,11,12}};

               printf("%u, %u, %u",*(x+3), *(x+2)+3);

               }

        A. 2036,2036,2036

        B. 2012,4,2204

        C. 2036,10,10

        D. 2012,4,6


Q.9 Given an array arr[] of size N. The task is to find the first repeating element in the array of integers , i.e., an element that occurs more than once and whose index of first occurence is smallest.
            Constraints:
            1 <= N <= 10 ^6
            0 <= Ai <= 10^6

Q.10

No comments: