|
459 | 459 | }, |
460 | 460 | { |
461 | 461 | "cell_type": "code", |
462 | | - "execution_count": 9, |
| 462 | + "execution_count": 2, |
463 | 463 | "id": "efe82236-da69-4654-8f26-23f2a5da6419", |
464 | 464 | "metadata": {}, |
465 | 465 | "outputs": [], |
|
803 | 803 | }, |
804 | 804 | { |
805 | 805 | "cell_type": "code", |
806 | | - "execution_count": 15, |
| 806 | + "execution_count": 3, |
807 | 807 | "id": "153b9a8d-c90a-43ad-bb9b-8bd03b062397", |
808 | 808 | "metadata": {}, |
809 | 809 | "outputs": [], |
|
999 | 999 | "source": [ |
1000 | 1000 | "It is clear that the intersection tree implementation is more efficient than the naive approaches. The expected time complexity is $\\bigO(N \\log N)$ for $|Q| = |D| = N$. Likely, the actual time complexity will be worse since the vinary tree is unlikely to be balanced." |
1001 | 1001 | ] |
| 1002 | + }, |
| 1003 | + { |
| 1004 | + "cell_type": "markdown", |
| 1005 | + "id": "eff509fe-8612-4ccf-bd91-d6fb7535f551", |
| 1006 | + "metadata": {}, |
| 1007 | + "source": [ |
| 1008 | + "## Testing" |
| 1009 | + ] |
| 1010 | + }, |
| 1011 | + { |
| 1012 | + "cell_type": "markdown", |
| 1013 | + "id": "6d763a5d-3bc2-47d0-831d-585521e20b63", |
| 1014 | + "metadata": {}, |
| 1015 | + "source": [ |
| 1016 | + "Since the naive appreach is pretty straightforward, and the intersection tree is a bit more sophisticated, it might be wise to compare the results by way of test." |
| 1017 | + ] |
| 1018 | + }, |
| 1019 | + { |
| 1020 | + "cell_type": "code", |
| 1021 | + "execution_count": 9, |
| 1022 | + "id": "88c24d03-83ef-4f3e-9332-846cba39b52c", |
| 1023 | + "metadata": {}, |
| 1024 | + "outputs": [], |
| 1025 | + "source": [ |
| 1026 | + "import intersection_tree\n", |
| 1027 | + "import naive_intersectionic_queries\n", |
| 1028 | + "\n", |
| 1029 | + "random.seed(1234)\n", |
| 1030 | + "max_end = 1_000_000\n", |
| 1031 | + "nr_intervals = 1_000\n", |
| 1032 | + "nr_queries = 1_000\n", |
| 1033 | + "db_intervals = [\n", |
| 1034 | + " intersection_tree.generate_interval(max_end=max_end) for _ in range(nr_intervals)\n", |
| 1035 | + "]\n", |
| 1036 | + "queries = intersection_tree.create_queries(size=nr_queries, max_end=max_end)\n", |
| 1037 | + "\n", |
| 1038 | + "db = intersection_tree.populate_db(None, db_intervals)\n", |
| 1039 | + "db_results = intersection_tree.execute_queries(queries, db)\n", |
| 1040 | + "\n", |
| 1041 | + "naive_db = db_intervals\n", |
| 1042 | + "naive_db_result = naive_intersectionic_queries.execute_queries(queries, naive_db)\n", |
| 1043 | + "\n", |
| 1044 | + "assert len(db_results) == len(naive_db_result)\n", |
| 1045 | + "assert set(db_results) == set(naive_db_result)" |
| 1046 | + ] |
| 1047 | + }, |
| 1048 | + { |
| 1049 | + "cell_type": "markdown", |
| 1050 | + "id": "eb4b24f3-f503-4ecf-9c10-0c371b3119b2", |
| 1051 | + "metadata": {}, |
| 1052 | + "source": [ |
| 1053 | + "Both algorithms yield identical results." |
| 1054 | + ] |
1002 | 1055 | } |
1003 | 1056 | ], |
1004 | 1057 | "metadata": { |
|
0 commit comments