The Gateway to Computer Science Excellence
+1 vote
127 views

An array of unknown size is filled with special symbols let's say '#'. Time required to find the size of array is

1) O(1)

2) O(logn)

3) O(n)

4) O((logn)2)

in Algorithms by Active (3.9k points) | 127 views
0
is it 2)  ?
0

I think...

it is O(1)...

0
how ?
0

@Diksha Aswal @ hs_yadav  Approach?

0
I think it would take O(logn)

Traverse it exponentially, i.e traverse with modification in Binary search
0
yes... same approach as Ashwin's
0

let 

S is an array...then...let starting address is 100 and having 5 element of 1 byte...then

&S+1 will return  100+5*1=105....now conside.. S=100

calculate....105-100=   5/size of an element  .....

and for given question this ia character...therefro we will assume size is 1 byte..

0
1 -> 2 -> 4 -> 8 -> 16 ->32 ...... -> 1024

Now, If the last element is 513 (OR 1023 OR 768 whichever is the worst case), then how to proceed?
0
yes, it will take O(logn) time.
0

joshi_nitish how?

0
0
(d) option...?? @srivivek
0
No. Answer given is O(logn)

But I am not getting it
0
apply binary search and move towards right ..you will reach to the end i.e. to 'n' in O(logn) time.
0

Diksha Aswal

1 -> 2 -> 4 -> 8 -> 16 ->32 ...... -> 1024

Now, If the last element(#) is at 513 (OR 1023 OR 768 whichever is the worst case), then how to proceed?

Please log in or register to answer this question.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,314 answers
198,358 comments
105,085 users