Question

Consider using a vector of vectors to represent the adjacency list instead of a vector of...

Consider using a vector of vectors to represent the adjacency list instead of a vector of lists. For each function from part b, c and ds, note if the runtime would change and justify your answer; i.e. explain why the runtime is the same or different
part b, c, d are functions. The function for part b sorts the list before inserting it into the vector. Part C compares two list and checks for common elements. Lastly, Part D if there are common elements then they merge the two list together.

Edit: This is in c++

Homework Answers

Answer #1

b. For this part, the time complexity would be the same. As earlier, we need to sort list but now we would need to sort vector. But the time complexity of both the operations is O(nlong(n)), if merge sort is used in both the cases.

c. For this too the time complexity would be same, as we have the sorted list and vector, so we would need to traverse the list and vector linear in both the cases to find the common elements if present so for both the cases we will have the time complexity as O(n).

d. For this case, the time complexity would not be same, as in the case of the list we would need to traverse the full list in order to append the common element at the end of the list, whereas in the case of the vector we can do this operation in constant time complexity. Thus in case of vectors of the vector, the time taken would be less in comparison of the vector of lists.

Thanks

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Consider the two vector-functions listed below. Justify your answers for each question. x1(t) = [t, 2t]...
Consider the two vector-functions listed below. Justify your answers for each question. x1(t) = [t, 2t] and x2(t) = [t , t^2] (a) Are the vector-functions x1(t) and x2(t) linearly independent on the interval (−∞,∞)? (b) Does there exist a point t0 such that the constant vectors x1(t0) and x2(t0) are linearly dependent? (c) Can the vector-functions x1(t) and x2(t) be solutions to a first-order homogeneous linear system? DIFF. EQUATIONS
using dr.racket programing language If we write a function that tests whether a list contains only...
using dr.racket programing language If we write a function that tests whether a list contains only strings, odd numbers, or even numbers, you will notice that the code that iterates through the list stays the same, with the only change being the predicate function that checks for the desired list element. If we were to write a new function for each of the tests listed above, it would be more error-prone and an example of bad abstraction. We could write...
Using R and install.packages("MASS"), library(MASS) 1. Generate the following vector using at least two methods. 0,...
Using R and install.packages("MASS"), library(MASS) 1. Generate the following vector using at least two methods. 0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4 2. Generate the following vector. Apple1, Banana2, Orange3, Cranberry4, Watermelon5 3. Generate the following vector using the “rep” function. a, a, b, b, c, c, a, a, b, b, c, c 4. In vector y = (8, 3, 5, 7, 6, 6, 8, 9, 2, 3, 9, 4, 10, 4, 11), which elements of y contains...
Must be written in c++: This problem solely involves your demonstration of the proper usage of...
Must be written in c++: This problem solely involves your demonstration of the proper usage of C++ STL std::list<int> Below you will be given four total functions to develop (two are listed here, two separately after) Put all four of your functions in the same single source code file Submit ONLY your one source code CPP file online Submitting two or three or more separate CPP files will lose points (1) The first function you will need to implement is...
1. Define the following terms: a) macromolecule b) monomer c) polymer 2. For each of the...
1. Define the following terms: a) macromolecule b) monomer c) polymer 2. For each of the biological molecules in the table below, describe its functions and list a specific example of a monomer and a polymer. Be sure to look at the examples of structural formulas shown in your book (e.g., Fig 3.5, 3.6). Macromolecule Functions Monomer Polymer Carbohydrate Protein Protein (we will learn the names of some specific proteins later) Nucleic acid 3. When monomers are joined together to...
Data Structure in C++ I keep getting the same warning, and I cant seem to fix...
Data Structure in C++ I keep getting the same warning, and I cant seem to fix it.. Can you explain to me what I am doing wrong? Warning: dlist.cc: In function 'std::ostream& operator<<(std::ostream&, dlist&)': dlist.cc:66:10: error: invalid initialization of reference of type 'std::ostream& {aka std::basic_ostream&}' from expression of type 'dlist::node*' dlist.cc: In function 'dlist operator+(dlist&, dlist&)': dlist.cc:93:8: error: invalid operands of types 'dlist::node*' and 'dlist::node*' to binary 'operator+' dlist.cc:97:8: error: could not convert 'result' from 'int' to 'dlist' My code:...
My assignment: Triplet Template Class Directions: Define a template class for a generic triplet. The private...
My assignment: Triplet Template Class Directions: Define a template class for a generic triplet. The private data member for the triplet is a generic array with three elements. The triplet ADT has the following functions:  default constructor  explicit constructor: initialize the data member using parameters  three accessors (three get functions) which will return the value of each individual element of the array data member  one mutator (set function) which will assign values to the data member...
Please do the following in python: Write a program (twitter_sort.py) that merges and sorts two twitter...
Please do the following in python: Write a program (twitter_sort.py) that merges and sorts two twitter feeds. At a high level, your program is going to perform the following: Read in two files containing twitter feeds. Merge the twitter feeds in reverse chronological order (most recent first). Write the merged feeds to an output file. Provide some basic summary information about the files. The names of the files will be passed in to your program via command line arguments. Use...
Using the model proposed by Lafley and Charan, analyze how Apigee was able to drive innovation....
Using the model proposed by Lafley and Charan, analyze how Apigee was able to drive innovation. case:    W17400 APIGEE: PEOPLE MANAGEMENT PRACTICES AND THE CHALLENGE OF GROWTH Ranjeet Nambudiri, S. Ramnarayan, and Catherine Xavier wrote this case solely to provide material for class discussion. The authors do not intend to illustrate either effective or ineffective handling of a managerial situation. The authors may have disguised certain names and other identifying information to protect confidentiality. This publication may not be...
Please read the article and answear about questions. Determining the Value of the Business After you...
Please read the article and answear about questions. Determining the Value of the Business After you have completed a thorough and exacting investigation, you need to analyze all the infor- mation you have gathered. This is the time to consult with your business, financial, and legal advis- ers to arrive at an estimate of the value of the business. Outside advisers are impartial and are more likely to see the bad things about the business than are you. You should...