Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Following are two functions to find the largest of the 4 given numbers. Which of these has better time complexity? Justify your answer. (5 Marks)
Following are two functions to find the largest of the 4 given numbers. Which of these has better time complexity? Justify your answer. (5 Marks) int findLargest1(in a, int b, int c, int d) { int lrg = a; if(b>lrg) lrg=b; else if(c>lrg) lrg=c; else if(d>lrg) lrg=d; return lrg; } int findLargest2(in a, int b, int c, int d) { if(a>b) if(a>c) if(a>d) retrun a; else return d; else if(c>d) return c; else return d; else if(b>c) if(b>d) return b; else return d; else if(c>d) return c; else return d; }
int findLargesti(in a, int b, int c, int d) { int lrg = a; if (b>lrg) lrg=b; else if (c>lrg) lrg=c; else if (d>lrg) lrg=d; return lrg; } int findLargest2 (in a, int b, int c, int d) { if(a>b) if(a>c) if (a>d) retrun a; else return d; else if(c>d) return c; else return d; else if(b>c) if (b>d) return b; else return d; else if (c>d) return c; else return d; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started