Assuming students and courses have unique integer ids.

Use an adjacency list kind of data structure. Where the location of the
student/course in the list can be decided by hashing.

Essentially, there will be 3 hash tables,
1. To store student objects. Key - student id, value- student object.
2. To store course objects. Key - course id, value- course object.
3. to store relationships. Key - student-id/course-id. Values corresponding
student-ids/course-ids. Multiple values will belong to a key and they will
be stored as linked list.

queries a and b can be easily answered by just returning all values from
hash table 1 or 2.
hash table 3 will optimize queries c and d.
On Sun, Oct 30, 2011 at 1:17 AM, Aamir Khan <[email protected]> wrote:

> In a university, students can enroll in different courses. A student may
> enroll for more than one course. Both students and courses can be
> identified by IDs given to them. Design a data structure to store
> students, courses, and the student-course relationships. You can use arrays,
> lists, stacks, trees, graphs, etc. or come up with your own data structures.
> Give the running times, in Big O notation, for the following operations
> for your data structure and justify the answers:
>
> a) Return all students in a list.
> b) Return all courses in a list.
> c) Return all courses in a list for a given student.
> d) Return all students in a list for a given course.
>
>
>
>
>
> Aamir Khan | 3rd Year  | Computer Science & Engineering | IIT Roorkee
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>



-- 
Nitin Garg

"Personality can open doors, but only Character can keep them open"

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to