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
Starting a computer after it has been turned off is term as​
kifflom [539]

Answer:

Booting

Explanation:

7 0
3 years ago
It’s just a multiple choice question about emails
cestrela7 [59]
The Answer is : A, B , C .
7 0
3 years ago
Read 2 more answers
unscramble the letters to identify which step of the scientific method each statement repesents why is the sliced cheese in the
Rudiy27
Sorry the only word I could get from that is problem, is that possibly the answer?
5 0
3 years ago
Which of the following statements is true of intrapreneurs
chubhunter [2.5K]

<u>Answer is:</u>

They take risks, but not with their own investments.

<u>Explanation:</u>

Intrapreneurship is the act of behaving like an entrepreneur while working within a large organization. Intrapreneurship is known as the practice of a corporate management style that integrates risk-taking and innovation approaches, as well as the reward and motivational techniques, that are more traditionally thought of as being the province of entrepreneurship.


<u>Example:</u>

One of the most well-known examples of intrapreneurship is the "Skunk Works" group at Lockheed Martin. The group was originally named after a reference in a cartoon, and was first brought together in 1943 to build the P-80 fighter jet. Because the project was to eventually become a part of the war effort, the project was internally protected and secretive. Kelly Johnson, later famous for Kelly's 14 rules of intrapreneurship, was the director of this group.

4 0
4 years ago
Which term refers to computer programs that provide computer users with a graphical interface to the internet?
bulgar [2K]
Web browser is the term that refers to computer program that provide computer users with graphical interface to the internet.
4 0
3 years ago
Other questions:
  • What is a collection?
    5·1 answer
  • Max Weber's concept of ________ implies that, in conducting research, social scientists must try to understand others' view of r
    14·2 answers
  • A(n) _____ might be written by a programmer or it might be created through a DBMS utility program.
    6·1 answer
  • Network Industries, Inc., wants to monitor its employees’ electronic com-munications. To avoid liability under laws related to e
    12·1 answer
  • A disk drive’s data ____________________ rate is a summary performance number combining the physical aspects of data access with
    10·2 answers
  • Pass only _____ at a time.
    13·2 answers
  • What is the general form of an internet email address<br>​
    5·1 answer
  • Write a program in which you input three numbers they canhave decimals so float values and the program gives you the minvalue ou
    8·1 answer
  • Desirable workplace habits and skills include:
    14·1 answer
  • Internet speed test, why does it take some time to get maximum speed
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!