I have My goal is to remove overlapping regions and return the map where the key / values are added Below is an example of my current implementation (this class is required): You can use I do not understand Python, but I think that you are doing a cruel force here. There will be another way to sort on a preliminary index; So get your example for you 0 3 4 5 7 10 15 18 19 Go through each start index and check that its indexed index is binary search i.e. 0, get your last index 2 and see where 2 lies. I since 2 lies immediately after 0, but it does not overlap anything, but we say that the end of 0 was index 17, its It would mean that all the starting points for 0, 17 overs Chunk to 15, which is 3,4,5,7,10,15 This complexity is notification. Edit I have realized that you maintain 4,5 4,5 and 5,6 overlap and I think because 4,5 is the integer key 1 The integer of 5,6 is less than the key, which is 2. So I think that you always maintain a lower integer key, though it is overlapping. If this is the case, then complexity o (N ^ 2) because you can not blindly binary search. For example, if the end index of 4 was 10, you would have to go through 5,7 and 10 to see if their integer key is less than 4. If it is 4 and its end index can be filtered, otherwise 4. {integer_key -> The list [Tupal]} as the key / value added Tuples contains the
(start, end) value that represents the string indexed for a substrung operation.
{TUPAL -> Integer_key} .
Order imported from the import command string_length = 20 idx_region_map = ordered (idx_region_map) 0] = [(0,2), (7,10)] idx_region_map [1] = [[4,5], (18,19)] idx_region_map [2] = [(3,3), (5,6) ), (10,13)] idx_region_map [3] = [(15,17), (19, 20)] # can be presented as the following: ## 012345678901234567890 | # 0 | OOO ---- OUO ---------- | # 1 | ---- oo ------------ oo- | # 2 | --- O-OO --- OUO ------- | # 3 | --------------- ooo-oo | | # ... def filter_overlaps (string_length, idx_region_map): region_idx_map = {} occupied = [for idx limit (string_length)] for incorrect, fields in idx_region_map.items (): for fields in fields: start, end = field [0], area [1] + 1 overlap = any (capture [start: end]) does not overlap: for the range I (start, end): captured [i] = True region_idx_map [region] = Idx return region_idx_map # Prints: (3, 3): 2, (4, 5): 1, (18, 19): 1, (7, 10): 0, (0, 2): 0, (15 , 17): 3} It seems to work adequately for my needs, but I know this I am curious to know what the alternative algorithms are to solve this problem. For example, using different data structures or more efficient than the above.
Comments
Post a Comment