davecom / ClassicComputerScienceProblemsInPython

Source Code for the Book Classic Computer Science Problems in Python
https://www.manning.com/books/classic-computer-science-problems-in-python?a_aid=oaksnow&a_bid=d326fe0b
Apache License 2.0
1.03k stars 396 forks source link

Confusion: Can't use binary search in the 2.1 DNA Search when the gene are not sorted #18

Closed theonlyNischal closed 1 year ago

theonlyNischal commented 1 year ago

In the code that you provided, the gene sequence is not explicitly sorted, so the binary search algorithm will not work correctly on this gene sequence.

davecom commented 1 year ago

Not sure what you're referring to. It's sorted on line 67 and then searched:

my_sorted_gene: Gene = sorted(my_gene)
print(binary_contains(my_sorted_gene, acg))  # True
print(binary_contains(my_sorted_gene, gat))  # False