1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
satela [25.4K]
3 years ago
10

A pair is a simple struct with two data members, one of type T1 and one of type T2. A set and a map are organized as binary sear

ch trees; anunordered_set and an unordered_map are organized as hash tables that never allow the load factor to exceed some constant, and a loop that visits every item in a hash table of N items is O(N).
Suppose UCLA has C courses each of which has on average S students enrolled. For this problem, courses are represented by strings (e.g. "CS 32"), and students by their int UIDs. We will consider a variety of data structures, and for each determine the big-O time complexity of the appropriate way to use that data structure to determine whether a particular student s is enrolled in course c. For example, if the data structure were vector>>, where each pair in the outer vector represents a course and all the students in that course, with those students being sorted in order, then if the pairs are in no particular order in the outer vector, the answer would be O(C + log S). (The reason is that we'd have to do a linear search through the outer vector to find the course, which is O(C), and then after that do a binary search of the S students in the sorted vector for that course, which is O(log S).) In these problems, we're just looking for the answer; you don't need to write the reason.

e. unordered_map>. What is the big-O complexity to determine whether a particular student s is enrolled in course c?

f. Suppose we have the data structure map> and we wish for a particular course c to write the id numbers of all the students in that course in sorted order. What is the big-O complexity?

g. Suppose we have the data structure unordered_map> and we wish for a particular course c to write the id numbers of all the students in that course in sorted order (perhaps using an additional container to help with that). What is the big-O complexity?

h. Suppose we have the data structure unordered_map> and we wish for a particular student s to write all the courses that student is enrolled in, in no particular order. What is the big-O complexity?
Computers and Technology
1 answer:
madam [21]3 years ago
7 0

Answer:

(e) unordered_map<string, unordered_set<int>>

The outer unordered_map is a hash table, so to search the course c it would take constant time O(1). and once we have the course and its unordered_set , which is again a hash table so to serach the student s it would take constant time O(1).So total time is O(1), constant.

(f) map<string, set<int>>

The outer map is a binary search tree, so to search the course c it would take logC time and once we have the course and its set, which is a binary tree, to list the ids in sorted order we need to do an inorder traversal of the tree that would take O(S) time.So total time is O(logC+S)

(g) unordered_map<string, unordered_set<int>>

The outer unordered_map is a hash table, so to search the course c it would take constant time O(1). and once we have the course and its onordered_set , which is another hash table, to list the ids in sorted order we need to loop through all elements in the hash table which takes O(S) time and sort them using any sorting algorithms or else construct another container set<int> that takes O(SlogS) time. So total time is O(SlogS).

(h) unordered_map<string, set<int>>

The outer unordered_map is a hash table, so we loop through each course in it and do search for the student s in its set<int>, which is a binary search tree, if found we print the course else not. The search takes logS time for each course, so total time is O(ClogS).

You might be interested in
Difference between a lesson plan and scheme of work​
MariettaO [177]

SORRY BUT THERE IS No difference at all

5 0
3 years ago
Read 2 more answers
Bugs bunny personality traits
Dafna1 [17]

Answer:

As a character, Bugs Bunny is king, and he's as close to an animated culture hero as we're going to get. Think about it. He's the person you want to be — the smartest one in the room who's still effortlessly cool. He's quick-witted, funny, and even a little cruel, but only to his tormenters.

Explanation:I hope this helps!!!Plz leave a heart and a rating!!

3 0
4 years ago
What does it mean to “declare a variable”? create a variable use a variable share a variable modify a variable
lara [203]

You are defining the variable

6 0
3 years ago
Read 2 more answers
Suppose Host A wants to send a large file to Host B. The path from Host A to Host B has three links, of rates R1 = 500 kbps, R2
Vlad1618 [11]

Answer:

a) 500 Kbps  b) 64 sec  c) 320 sec

Explanation:

a) We define the throughput of a network, as the actual maximum transmission rate that the network is able to deliver, which in this case is equal to the lowest transmission rate of any of the links that the traffic must go through:

R1 =500 kbps

b) If the file size is given in bytes, and we have the throughput in bps, we need to convert to bits first, as follows:

4*10⁶ bytes * (8 bits/byte) = 32*10⁶ bits.

The time needed to transfer the file, will be given by the quotient between the file size and the throughput, as follows:

t = 32*10⁶ bits / 500*10³ bits/sec = 64 sec

c) If the transmission rate R2 is reduced to 100 kbps, R2 becomes the lowest transmission rate in the network, so it becomes the new throughput.

So, the time needed for the same file to be transferred to host B is as follows:

t=  32*10⁶ bits / 100*10³ bits/sec = 320 sec

6 0
3 years ago
When an important file is saved on two different computers, what is the name of the file that is housed on the second computer?
OleMash [197]
When an important file is saved on two different computers, the name of the file that is housed on the second computer is 'back up'. Back up refers to the process of copying and archiving a particular computer data in order to have an extra copy to fall back on in the event of data loss.  <span />
5 0
3 years ago
Other questions:
  • What could break the circuit between your home and an electric power plant?
    15·2 answers
  • What are the best ways to find data within a spreadsheet or database? Check all that apply. sorting tools the help function scro
    11·2 answers
  • A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in
    13·1 answer
  • Roark has just joined a company and in his role as a lead analyst, he will be responsible for determining which systems developm
    11·1 answer
  • Write a method named printGPA that takes in as a parameter a Scanner to read in user input, and calculates a student's grade poi
    8·1 answer
  • What are the two types of commennts of java​
    12·1 answer
  • Which of these are the two main components of a CPU?
    5·2 answers
  • Задание: Построить иерархию классов в соответствии с вариантом задания. Построить диаграммы классов.
    8·1 answer
  • Yeoo check dis out!!!!!! wait my full vid dont show hol on
    7·2 answers
  • Let A and B be regular languages. Is the set of strings of odd length from A beginning with 0 concatenated with the set of strin
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!