简体   繁体   中英

Which data structure is best for this problem

There are n activities and m students. Each student can do as many activities as possible. I want to figure out the shortest path is between two students. I need to focus on inserting time of the activities: students and the time to find the shortest path between two students. Example: Activity1: Bob,Carl, Anthony, Suzy, David Activity2: Bob, Manny, carl Bethany brad Activity3: Carl, Craig, Candy

Given this if I wanted to find shortest path between Anthony to craig would be Anthony-> Activity1-> Bob -> Activity2-> Carl-> Activity3-> Craig What would be the best data-structure to first insert this and then do the queries for shortest path? I believe its a graph but what type and how would I format it?

Bipartite graph is your solution. one part goes for students and one part for tasks. insertion of task is O(1) as long as you don't need any index, just contiune increasing index of task part. and insertion of student-task relation also O(1). finding the min path is applicable with BFS or dijikstra

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM