recategorized by
641 views
0 0 votes

Consider an array size of 10 and insertion of 10 element in it.If first five element are inserted at loc =0 and rest five element are at loc=2

then the total number of shifting of elements is:

  1. 35
  2. 20
  3. 45
  4. 0

1 Answer

3 3 votes
total 35 shifting

First 1 is inserted in a[0]

then 1 shifted to a[1] and 2 get place at a[0]

next, 3 comes a[1] shifts 1 more , and 2 shifts 1 place and a[0] occupied by 3

like that upto 5 insertion there are of shift 4+3+2+1=10

 

Next 6 inserted at a[2]

So, 1 shifts one place , 2 shifts 1 place, 3 shifts 1 place and 6 occupies a[2]

again 7 inserted 1,2,3,6 shifts 1 place

like that here 1,2,3 shifts 5 place each

and 6,7,8,9 shifts 4,3,2,1 place

So, here total shifts 5+5+5+4+3+2+1=25

total 35 shifting
Position:
Show:

Related questions

0 0 votes
1 1 answer
1.2k
1.2k views
Surya Dhanraj asked Oct 24, 2017
1,165 views
An array a of unknown size is filled with special symbol let's say # . Time required to find the size of a is:Please give proper explanation
0 0 votes
1 answers 1 answer
509
509 views
Kamalkant Patel asked Jan 30, 2016
509 views
Number of comparisions in worst case required to merge two sorted arrays of size 40 and 60 are -
7 7 votes
1 1 answer
364
364 views
GO Classes asked Jul 3
364 views
A sequence of $n$ elements is implemented in two ways:As a normal array with contiguous memory and no extra empty slot. As a singly linked list with only a $\texttt{head}...
1 1 vote
1 1 answer
402
402 views
jothee_new asked Sep 8, 2025
402 views
We have an array $A$ of $n$ numbers, where $n$ is a power of $2$.We build a full binary tree on top of the array $A.$ The elements of the array are leaves of the tree, nu...