For (I Pos I 1 I - ) (A (I) A (I+1) ) For (I N I Pos I - ) (A (I) A (I+1) ) For (I Pos I

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

While inserting an item in an array of integers which loop is

right, where pos is the pos at which insertion is to be


made(assume array starts from 1 and N is the max no. of items
in the array.)
 For(i=pos;i>=1;i--) { A[i] = A[i+1]; }
 For(i=N; i>=pos;i--) { A[i] = A[i+1]; }
 For(i=N; i>=pos;i--) { A[i+1] = A[i] }
 For(i=pos ; i
To delete an item from an array which loop is correct, where p
is the position of deletion( assume array starts from 1 and N is
the max no. of items in the array.)

 For(i=N;i>=pos;i--) { a[i] = a[i+1]; }


 For(i=pos;i
 For(i=pos-1;i
 None

What is the contents of the array after the execution of the


following program :-
for(i=1;i<=6;i++)
 {
   for(j=i+1 ; j<= 6; j++)
   {
      if(a[i] == a[j])
      {
         a[j] = 0;
      }
}

Same
10,10, 20, 20, 30, 40

10,0 20, 0, 30, 40

10,30, 20, 0, 0, 40

A Stack follows the principle of

LIFO

FIFO

BOTH A and B
NONE
What is the advantage of linear search
Fast
Time consuming
Needs a sorted array
Does not needs a sorted array
ALL

What is the disadvantage of a binary search

Fast
Time consuming
Needs a sorted array
Does not needs a sorted array
ALL
If the search item lies in the upper half in case of binary
search which is the correct set of statements.
Top = mid + 1;
Top = mid - 1;
Bot = mid + 1;
Bot = mid - 1;

Which of the following data structure is non-linear type?


Strings
Stacks
Lists
None of above

An array is a 

Consecutive group of memory locations that share the same type


Non consecutive group of memory locations that have different
types
Non consecutive group of memory locations that share the same
type
Simple data structure containing identical types

The memory address of the first element of an array is called


Foundation address
Base address
First address
Floor address

For a binary search algorithm to work, it is necessary that the


array (list) must be

In a heap
Popped out of stack
Sorted
Unsorted

On average, a sequential search algorithm would make N/2


number of comparisons for a list of size N.
True
False

The following best describes which algorithm? The elements


are compared and swapped if the first is found to be greater
than the second.

Binary search algorithm


Linear search algorithm
Bubble sorting algorithm
 Elements in an array are accessed
a) randomly
b) sequentially
c) exponentially
d) logarithmically

------------------ is a step by step procedure for calculation


Program
Algorithm
Greedy Method
Problem

You might also like