It's UWAweek 48

help2200

This forum is provided to promote discussion amongst students enrolled in CITS2200 Data Structures and Algorithms.

Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

How do I ask a good question?
Displaying the 4 articles in this topic
Showing 4 of 176 articles.
Currently 4 other people reading this forum.


 UWA week 16 (1st semester, week 7) ↓
SVG not supported

Login to reply

👍?
helpful
2:23pm Tue 16th Apr, William R.

Is O(1) achievable? The add_child function asks for a target of O(1), a tree data structure wouldn't be able to achieve this, finding from root the parent to link the child would be O(n). A set would meet O(1) but would have trouble with get_primogeniture_order which asks for O(n) and going through the set several times to find the eldest child of the eldest child of the... and so on would be O(n^2) because if it was held in n + n-1 + n-2 ... +1 that solves to O(n^2). So far I have opted for a hashmap, which under most circumstances is O(1) under the very rare occurrence that everything hashes to the same key, then it would have worst case O(n). Am I missing a data structure that could achieve all target time complexities or does target time complexity allow for hashtables that would be just off? Kind Regards Bill


SVG not supported

Login to reply

👍?
helpful
11:04am Wed 17th Apr, William R.

Nevermind, I'm overcomplicating this.


SVG not supported

Login to reply

👍?
helpful
3:58pm Wed 17th Apr, ANONYMOUS

I met the same question, I can't decide use which kind of data structures...


SVG not supported

Login to reply

👍x1
helpful
5:43pm Wed 17th Apr, William R.

I found that only the absolutely simplest structure lets me have O(1) so simple data structures built into python are a good start on finding the right one.

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  8:08AM Aug 25 2024
Privacy policy