Original Post
🔒 Locked
Linked Lists Problem
Advertisement
That sounds like graduation homework. hehe
You should make an method that check if two list are equal.
Then make an sub list with the serie.
Then traverse by one(you should keep a variable to know what position in the list you are), copy a sub list with the same lenght of the serie and compare. increment the counter if its equal.
Now let''s analyze the complexity in the worst case of of the algorithm in an unordered list:
there is the lenght of the serie -> LS
there is the lenght of the list -> LL
you make (LL-LS) list comparasion, with is based on LS comparasion.
The creation and copy of list involves (LS+LS) comparasions (serie and sublist).
Being the worst case, presence of 1 serie at the end with (LL-1) lenght.
F=O((2LL-1)*(2LL-2)*(LL-1))
complexity O(n^3).
Now its easy..,(NOT)! You make an grafh with all the possibilities of series in L1. Traverser..er.. travel all over the grafh doing the check above, and keep track of the occurence of series in an balanced tree. Then you do a search on the tree, and it will tell you the result and graph with indicates the serie.
Actually there are easier ways, but this is the funniest and will make you learn a lot about data structures and search algorithms.
You should make an method that check if two list are equal.
Then make an sub list with the serie.
Then traverse by one(you should keep a variable to know what position in the list you are), copy a sub list with the same lenght of the serie and compare. increment the counter if its equal.
Now let''s analyze the complexity in the worst case of of the algorithm in an unordered list:
there is the lenght of the serie -> LS
there is the lenght of the list -> LL
you make (LL-LS) list comparasion, with is based on LS comparasion.
The creation and copy of list involves (LS+LS) comparasions (serie and sublist).
Being the worst case, presence of 1 serie at the end with (LL-1) lenght.
F=O((2LL-1)*(2LL-2)*(LL-1))
complexity O(n^3).
Now its easy..,(NOT)! You make an grafh with all the possibilities of series in L1. Traverser..er.. travel all over the grafh doing the check above, and keep track of the occurence of series in an balanced tree. Then you do a search on the tree, and it will tell you the result and graph with indicates the serie.
Actually there are easier ways, but this is the funniest and will make you learn a lot about data structures and search algorithms.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement