retagged by
491 views
0 votes
0 votes

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

retagged by

1 Answer

0 votes
0 votes
First travel the array exponentially, then once you find anything other than '#', start traversing the array in reverse order exponentially( let's say you are now at loc 'n' then next loc will be n-2 then next n-4, n-8,n-16....) until you again find this symbol '#'. Now again traverse in reverse order(let's say you are at loc. m then next loc will be m+2,m+4...)until you find anything other than '#'. repeat this until you reach a point when there is a difference of 2 in between the loc. of '#' and garbage. Then do a linear access to reach the end element of the array. This whole process would take time $O(log \ n)$

Related questions

0 votes
0 votes
1 answer
2
Kamalkant Patel asked Jan 30, 2016
285 views
Number of comparisions in worst case required to merge two sorted arrays of size 40 and 60 are -
0 votes
0 votes
1 answer
3
ManojK asked May 20, 2016
396 views
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=2then the total number of shi...
3 votes
3 votes
2 answers
4
dhruba asked Jun 5, 2023
1,043 views
In QuickSort algorithm, which of the following statements is NOT true regarding the partition process?a) Partition always divides the array into two non-empty subsets.b) ...