@Mohit:

No, it's just the hierarchical occurent of conditions that makes the
switch faster. I really doubt that a compiler build a binary search
tree for switches. Also, it a binary tree works for switches why it
can't optimize the if-else-condition? Did you make some testing?


On Nov 21, 3:28 pm, "MOHIT ...." <[email protected]> wrote:
> its depend on compiler how it optimize it . he can make binary search tree
> for this comparison
> or perform cascading comparison as in if else case .. so worst case
> complexity will be as of
> if- else .
>
> but for this case
>
> switch(i)
>
> {
>
> case 4: //some operation
>
> case 5:// some operation
> case 6 : //
> some operation
>
> }
>
> optimization can be done by compiler which need no comparison
> just need to calculate index which need to comparison...
>
> so in above case switch is better than if else.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to