Implement function update (a, b) (meaning element a is updated to b) as a new fu
ID: 3590451 • Letter: I
Question
Implement function update (a, b) (meaning element a is updated to b) as a new function of skip lists, and give
its time complexity. Implement the function update(a, b) in pseudocode.
The answer given previously was not accepted. Please don't post the same copy pasted code given here
# include <iostreams>
Int main ()
{
Int a,b ;
Cout << ” Enter any two integers to perform update operation “ <<ends;
Cin >> a >> b;
Cout << “ Elements before performing update operation “ << ends;
Cout << a << b;
Update (a,b);
Cout << “ elements after performing update operation “ << ends;
Cout << a << b;
Return 0;
}
Void update ( int rx.ry)
Int update_value;
Update_value=x;
X=y;
Y=update_value;
}
The time complexity for update (x,y)function is 0(1)
Since the function does not contain any loop or recursion
Explanation / Answer
You swapped elements instead of updating one element. Let me rewrite same code with some corrections.
C++ Code:
#include <iostream>
using namespace std;
void update(int* x,int* y){
*x=*y; //just assigning value of b to a
}
int main()
{
int a,b;
cout<<"Enter any two integers to perform update operation"<<endl;
cin>>a>>b;
cout<<"Elements before performing update operation"<<endl;
cout<<a <<b<<endl;
update(&a,&b);
cout<<"Elements after performing update operation"<<endl;
cout<<a <<b<<endl;
return 0;
}
Time Complexity: O(1)
As you explained no loop or recursion.
Pseudo Code:
update(a,b)
{
a=b;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.