Re: [algogeeks] What Data Structure to use ?

2011-10-30 Thread Aamir Khan


 On Sun, Oct 30, 2011 at 1:17 AM, Aamir Khan ak4u2...@gmail.com 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.


 Lets bring a little bit complication,

What if a students wants to know list of all people who share maximum
number of courses with him/her ?

Naive approach : First getting all the courses from the hash tables and
then for each course traversing its list of students, for each student
encountered in this way we can just increase the count. Then all the people
having maximum count and print them.

Any better approach ?




 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.





-- 
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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] What Data Structure to use ?

2011-10-29 Thread Aamir Khan
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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] What Data Structure to use ?

2011-10-29 Thread Nitin Garg
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 ak4u2...@gmail.com 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] What Data Structure to use ?

2011-10-29 Thread Sahil Garg
Create a hash table for students and another hash table for course..
For each record in the student table create a linklist that stores the list
of all the course in which the particular student in enrolled.
For each record in the course table create a linklist that stores the list
of all the students enrolled in this course..

Space will be O(m n)
m is the number of students and n is the number of courses

Time will be..

a) Return all students in a list.   O(m)
 b) Return all courses in a list.O(n)
c) Return all courses in a list for a given student.  O(n)
d) Return all students in a list for a given course. O(m)

let me know if it sounds good..




Sahil Garg
Computer Engineering
Delhi College of Engineering


On Sun, Oct 30, 2011 at 1:17 AM, Aamir Khan ak4u2...@gmail.com 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.


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