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
***C++ CODING*** Write a program for sorting a list of integers in ascending order using the...
***C++ CODING*** Write a program for sorting a list of integers in ascending order using the bubble sort algorithm. Requirements Implement the following functions: Implement a function called readData int *readData( )   The function returns a pointer that points to the locations with integers reading from the file data.txt. arr is a pointer for storing the integers. The function returns the number of integers. The function readData reads the list of integers from a file call data.txt into the array...
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...
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...
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...
Write an append function void append(const arrayListType<elemType>& otherList) that will take an array list as a...
Write an append function void append(const arrayListType<elemType>& otherList) that will take an array list as a parameter and append it to the current list. Write an operator+ function that will create a new list containing the contents of the two lists added. arrayListType<elemType> operator+(const arrayListType<elemType> & rhs) const so that you can write code like a = b + c where a b and c are all arrayListTypes. Add your functions to the template and write a main program to...