Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In Big- notation, analyze the running time of the following pieces of code/pseudo-code. Describe the running time as a function of the input size (here,

In Big- notation, analyze the running time of the following pieces of code/pseudo-code. Describe the running time as a function of the input size (here, n). You should always explain your work when solving mathematics problems.

image text in transcribedimage text in transcribedimage text in transcribed

Part (a) void f1(int n) int t = sqrt(n); for(int i = 0; i > f2(int n) std::map > t1; std::vector v1; for(int i=1; i > x; std::map >:: iterator it; it = t1.find( x ); if( it == t1.end()){ int k = 1 + (x % n); while(k >= 1) { t1[k].push_back(x); k /= 2; else { v1.push_back(x); return t1; Part (d) Notice that this code is somewhat similar to what happens if you keep inserting into a vector. int *a = new int [10]; // new is 0(1) int size = 10; for (int i = 0; i > f2(int n) std::map > t1; std::vector v1; for(int i=1; i > x; std::map >:: iterator it; it = t1.find( x ); if( it == t1.end()){ int k = 1 + (x % n); while(k >= 1) { t1[k].push_back(x); k /= 2; else { v1.push_back(x); return t1; Part (d) Notice that this code is somewhat similar to what happens if you keep inserting into a vector. int *a = new int [10]; // new is 0(1) int size = 10; for (int i = 0; i

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil, Elizabeth O'Neil

2nd Edition

1558605800, 978-1558605800

More Books

Students also viewed these Databases questions

Question

5. Understand how cultural values influence conflict behavior.

Answered: 1 week ago

Question

e. What do you know about your ethnic background?

Answered: 1 week ago