version
stringclasses
1 value
style
stringclasses
2 values
subset
stringclasses
12 values
question_id
stringlengths
9
23
question
stringlengths
27
8.13k
solution
stringlengths
99
5.97k
test
stringlengths
105
4.45k
test_info
listlengths
0
13
gpt_pass_sequence
listlengths
1
10
gpt_pass_trial_num
int64
1
10
gpt_difficulty
stringclasses
3 values
gpt_pass_percentage
float64
0.1
1
trials
dict
chosen_trial
stringclasses
10 values
metadata
dict
benchmark_similarity
float64
0.16
0.93
benchmark_instruction
stringclasses
1 value
benchmark_task_id
stringclasses
1 value
filter_reason
stringclasses
1 value
base_id
stringlengths
7
21
variant
stringclasses
2 values
top_function_names
listlengths
2
13
n_top_functions
int64
2
13
helper_call_edges
listlengths
1
16
n_helper_call_edges
int64
1
16
harness_functions
listlengths
0
3
structural_wrapper
bool
1 class
class_names
listlengths
0
5
has_class
bool
2 classes
test_kind
stringclasses
1 value
test_has_solution_import
bool
2 classes
third_party_imports
listlengths
0
5
stdlib_only
bool
2 classes
question_norm_sha1
stringlengths
40
40
solution_ast_sha1
stringlengths
40
40
v1.0
instruct
Data_Structure
Data_Structure_21796_I
### Scenario You have been hired by a company that needs to efficiently sort large datasets constantly. They use both min heaps and max heaps in different parts of their system depending on the type of data they are dealing with. Your task is to complete the implementation of the heap sort for both max heap and min h...
def max_heapify(arr, n, i, debug): largest = i left = 2 * i + 1 right = 2 * i + 2 if left < n and arr[largest] < arr[left]: largest = left if right < n and arr[largest] < arr[right]: largest = right if largest != i: arr[i], arr[largest] = arr[largest], arr...
from solution import max_heap_sort, min_heap_sort def test_max_heap_sort(): assert max_heap_sort([3, 1, 4, 1, 5, 9, 2], debug=False) == [1, 1, 2, 3, 4, 5, 9] assert max_heap_sort([-5, 3, -1, 0, 2], debug=False) == [-5, -1, 0, 2, 3] assert max_heap_sort([1, 1, 1, 1, 1], debug=False) == [1, 1, 1, 1, 1] a...
[ { "docstring": null, "function_declaration": "def max_heapify(arr, n, i, debug):", "function_name": "max_heapify", "parameter_list": "(arr, n, i, debug)" }, { "docstring": null, "function_declaration": "def max_heap_sort(arr, debug=False):", "function_name": "max_heap_sort", "par...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_heap_sort(arr, debug=False):\n def heapify(arr, n, i):\n largest = i \n left = 2 * i + 1 \n right = 2 * i + 2 \n \n ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00021796", "row_id": 21796, "seed_ids": "[8]" }
0.606939
Data_Structure_21796
I
[ "max_heapify", "max_heap_sort", "min_heapify", "min_heap_sort" ]
4
[ [ "max_heap_sort", "max_heapify" ], [ "min_heap_sort", "min_heapify" ] ]
2
[]
false
[]
false
pytest
true
[]
true
0f9ba5709174d6bc00921df74416c38ba95da6f7
aba161b51e0a9f719877bd6df64cdaab0d0ea79f
v1.0
instruct
Data_Structure
Data_Structure_21799_I
You are tasked with implementing a function `insertion_sort` that sorts an array of integers using the insertion sort algorithm. Given the core logic for binary search (`search_insert`) to find the correct insertion positions, your goal is to integrate this into a full sorting method. ### Function Signature: ```python...
from typing import List def search_insert(arr: List[int], val: int, start: int, end: int) -> int: """ Helper function to perform binary search to find the insertion position for val """ while start < end: mid = (start + end) // 2 if arr[mid] < val: start = mid + 1 el...
from solution import insertion_sort def test_sorted_list(): assert insertion_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_reverse_sorted_list(): assert insertion_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] def test_unsorted_list_general(): assert insertion_sort([4, 2, 7, 1, 3]) == [1, 2, 3, 4, 7] def ...
[ { "docstring": "Helper function to perform binary search to find the insertion position for val", "function_declaration": "def search_insert(arr, val, start, end):", "function_name": "search_insert", "parameter_list": "(arr, val, start, end)" }, { "docstring": "Function to perform insertion ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def search_insert(arr, val, start, end):\n \"\"\"\n Binary search method to find the correct insertion position for val in arr between start and end.\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021799", "row_id": 21799, "seed_ids": "[199]" }
0.601759
Data_Structure_21799
I
[ "search_insert", "insertion_sort" ]
2
[ [ "insertion_sort", "search_insert" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9c8b4cb464085faf30e5463fbd1346e0d94b4130
1f20d8db57bcc131393258159d7cee457dded72a
v1.0
instruct
Data_Structure
Data_Structure_21808_I
### Insertion Sort with Binary Search **Context**: As a programming challenge, you need to implement an efficient sorting algorithm. You've been provided with a helper function `search_insert` that uses binary search to find the correct position to insert an element in a sorted array. Your task is to use this helper...
from typing import List def search_insert(array: List[int], val: int) -> int: """ This function utilizes binary search to find the index at which `val` should be inserted to keep `array` sorted. """ low = 0 high = len(array) - 1 while low <= high: mid = (low + high) // 2 if...
from solution import insertion_sort def test_insertion_sort_empty(): assert insertion_sort([]) == [] def test_insertion_sort_single_element(): assert insertion_sort([1]) == [1] def test_insertion_sort_sorted(): assert insertion_sort([1, 2, 3]) == [1, 2, 3] def test_insertion_sort_reverse_sorted(): a...
[ { "docstring": "This function utilizes binary search to find the index at which \n`val` should be inserted to keep `array` sorted.", "function_declaration": "def search_insert(array, val):", "function_name": "search_insert", "parameter_list": "(array, val)" }, { "docstring": "Sorts an array ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef search_insert(array: List[int], val: int) -> int:\n low = 0\n high = len(array) - 1\n while low <= high:\n mid ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021808", "row_id": 21808, "seed_ids": "[199]" }
0.593523
Data_Structure_21808
I
[ "search_insert", "insertion_sort" ]
2
[ [ "insertion_sort", "search_insert" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2704e443d116618f73908e7f55af45477d2b702e
634fd7ac9e00d13a285d4ae0f5d5358d61d1341f
v1.0
instruct
Data_Structure
Data_Structure_21821_I
#### Scenario You currently work at a tech company that processes large datasets daily. To improve the efficiency of managing tasks, your company wants to sort various datasets using the Heap Sort algorithm. Your task is to implement both the max heap sort and the min heap sort functions. #### Problem Statement Imple...
def max_heapify(arr, n, i, simulation=False, iter_count=[0]): largest = i left = 2 * i + 1 right = 2 * i + 2 if left < n and arr[left] > arr[largest]: largest = left if right < n and arr[right] > arr[largest]: largest = right if largest != i: arr[i], arr[largest] = arr...
from solution import max_heap_sort, min_heap_sort def test_max_heap_sort(): assert max_heap_sort([4, 6, 3, 2, 8, 1, 5]) == [1, 2, 3, 4, 5, 6, 8] assert max_heap_sort([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] assert max_heap_sort([1]) == [1] assert max_heap_sort([]) == [] a...
[ { "docstring": null, "function_declaration": "def max_heapify(arr, n, i, simulation=False, iter_count=[0]):", "function_name": "max_heapify", "parameter_list": "(arr, n, i, simulation=False, iter_count=[0])" }, { "docstring": null, "function_declaration": "def min_heapify(arr, n, i, simu...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_heapify(arr, n, i, simulation=False, iter_count=[0]):\n largest = i\n left = 2 * i + 1\n right = 2 * i + 2\n\n if left < n and arr[left] >...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00021821", "row_id": 21821, "seed_ids": "[8]" }
0.635021
Data_Structure_21821
I
[ "max_heapify", "min_heapify", "max_heap_sort", "min_heap_sort" ]
4
[ [ "max_heap_sort", "max_heapify" ], [ "min_heap_sort", "min_heapify" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a52ea0095b0f7582aa823012a4c5dbbfe81fa39c
b343122c8acf332ee3ce44ccea2492ecb469ef8e
v1.0
instruct
Data_Structure
Data_Structure_21861_I
Given the helper method `search_insert` which performs a binary search to find the insertion position in a sorted array, implement the **insertion sort** algorithm using this method. Your task is to write a function `insertion_sort` that sorts an array of integers using the insertion sort technique. #### Input: * A si...
from typing import List def search_insert(sorted_portion: List[int], value: int) -> int: """ Helper method to perform a binary search and find the correct index to insert the given value into the sorted portion of the list. """ low, high = 0, len(sorted_portion) while low < high: mid = ...
from solution import insertion_sort def test_insertion_sort_empty(): assert insertion_sort([]) == [] def test_insertion_sort_single_element(): assert insertion_sort([5]) == [5] def test_insertion_sort_two_elements(): assert insertion_sort([3, 1]) == [1, 3] assert insertion_sort([1, 3]) == [1, 3] def...
[ { "docstring": "Helper method to perform a binary search and find the correct index\nto insert the given value into the sorted portion of the list.", "function_declaration": "def search_insert(sorted_portion, value):", "function_name": "search_insert", "parameter_list": "(sorted_portion, value)" }...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def search_insert(arr, target):\n \"\"\"\n Helper function to determine the position to insert a target in a sorted array.\n It performs a binary sea...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021861", "row_id": 21861, "seed_ids": "[199]" }
0.621969
Data_Structure_21861
I
[ "search_insert", "insertion_sort" ]
2
[ [ "insertion_sort", "search_insert" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ff3c2f449d30171e50ef392104dae5e7c280fb9a
b2042d50e8b985b36b9f56f27b33659cf0b850e5
v1.0
instruct
Data_Structure
Data_Structure_21912_I
### RSA Encryption Key Generation and Message Encryption/Decryption You have been provided with an RSA key generation algorithm and basic encryption/decryption functions. Your task is to improve the reliability and efficiency of the RSA key generation process. Furthermore, you will implement functions to encrypt and d...
import random from sympy import isprime, mod_inverse def generate_large_prime(bits, rng): """Generate a prime number with specified bits using a RNG.""" while True: number = rng.getrandbits(bits) if isprime(number): return number def generate_key(k, seed=None): """Generate RSA ...
from solution import generate_key, encrypt, decrypt def test_key_generation(): n, e, d = generate_key(512) assert isinstance(n, int) assert isinstance(e, int) assert isinstance(d, int) assert e == 65537 # Checking if public exponent is correctly set def test_encryption_decryption(): n, e, d =...
[ { "docstring": "Generate a prime number with specified bits using a RNG.", "function_declaration": "def generate_large_prime(bits, rng):", "function_name": "generate_large_prime", "parameter_list": "(bits, rng)" }, { "docstring": "Generate RSA key pair. Return (n, e, d).", "function_decl...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom sympy import isprime, mod_inverse\n\ndef generate_large_prime(bits, rng):\n \"\"\"Generate a prime number with specified bits using a R...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00021912", "row_id": 21912, "seed_ids": "[154]" }
0.651196
Data_Structure_21912
I
[ "generate_large_prime", "generate_key", "encrypt", "decrypt" ]
4
[ [ "generate_key", "generate_large_prime" ] ]
1
[]
false
[]
false
pytest
true
[ "sympy" ]
false
3533690c8a40557b5fc93a69671f294dc8ee8a55
94a21bd7ba9041fea034ef1a25f959c2a257cf66
v1.0
instruct
Data_Structure
Data_Structure_21932_I
**Context**: Imagine you are assisting in the development of a software tool aimed at providing insights into the structural properties of strings for various applications like bioinformatics and text analysis. One task is to generate all possible subdivisions of a given string where each subdivision consists entirely ...
def is_palindrome(s): """ Check if the given string s is a palindrome. """ return s == s[::-1] def generate_all_palindromic_partitions(s): """ Generates all possible subdivisions of the string s where each subdivision consists of palindromic substrings. """ def backtrack(start, path): ...
from solution import generate_all_palindromic_partitions def test_single_character(): assert generate_all_palindromic_partitions("a") == [["a"]] def test_two_same_characters(): assert generate_all_palindromic_partitions("aa") == [["a", "a"], ["aa"]] def test_non_palindromic_characters(): assert generate_...
[ { "docstring": "Check if the given string s is a palindrome.", "function_declaration": "def is_palindrome(s):", "function_name": "is_palindrome", "parameter_list": "(s)" }, { "docstring": "Generates all possible subdivisions of the string s where each subdivision consists of palindromic subs...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_palindrome(string):\n \"\"\"\n Helper function to check if a given string is a palindrome.\n \"\"\"\n return string == string[::-1]\n\ndef ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00021932", "row_id": 21932, "seed_ids": "[113]" }
0.750884
Data_Structure_21932
I
[ "is_palindrome", "generate_all_palindromic_partitions" ]
2
[ [ "generate_all_palindromic_partitions", "is_palindrome" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3e488a6a08ba4b4962c387e226fa6460388d4873
5de651f893545c12fdbe6435f7e8be14ff293300
v1.0
instruct
Data_Structure
Data_Structure_21941_I
**Question: Implement and Optimize Radix Sort** ### Problem Statement Given a list of non-negative integers, implement the Radix Sort algorithm to sort the list. Your implementation should follow the outlined principles and aim to optimize space complexity where possible. ### Function Signature ```python def optimize...
from typing import List def optimized_radix_sort(arr: List[int]) -> List[int]: if len(arr) == 0: return arr max_num = max(arr) place = 1 while max_num // place > 0: counting_sort(arr, place) place *= 10 return arr def counting_sort(arr: List[int], place: int): ...
from solution import optimized_radix_sort def test_radix_sort_example_case(): arr = [170, 45, 75, 90, 802, 24, 2, 66] expected = [2, 24, 45, 66, 75, 90, 170, 802] assert optimized_radix_sort(arr) == expected def test_radix_sort_empty_list(): arr = [] expected = [] assert optimized_radix_sort(a...
[ { "docstring": null, "function_declaration": "def optimized_radix_sort(arr):", "function_name": "optimized_radix_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def counting_sort(arr, place):", "function_name": "counting_sort", "parameter_list": ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef counting_sort(arr: List[int], exp: int) -> None:\n n = len(arr)\n output = [0] * n # Output array that will have sorted ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021941", "row_id": 21941, "seed_ids": "[15]" }
0.584978
Data_Structure_21941
I
[ "optimized_radix_sort", "counting_sort" ]
2
[ [ "optimized_radix_sort", "counting_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
db22b3bb77b5fad511c01748f217c14ebf0f352d
c1414ecb527be33d1500c5156bb84aaf35c058db
v1.0
instruct
Data_Structure
Data_Structure_21964_I
You are required to implement the `merge_sort` function given below. This function should sort an array of integers in non-decreasing order using the Merge Sort algorithm. Merge Sort works on the principle of Divide and Conquer. The array is divided into two halves, each of which is recursively sorted and then merged...
from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers in non-decreasing order using the Merge Sort algorithm. Parameters: arr (List[int]): An unsorted list of integers. Returns: List[int]: A list of integers sorted in non-decre...
from solution import merge_sort def test_merge_sort_empty(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_sorted_list(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_sorted_list(): assert merg...
[ { "docstring": "Sorts an array of integers in non-decreasing order using the Merge Sort algorithm.\n\nParameters:\n arr (List[int]): An unsorted list of integers.\n \nReturns:\n List[int]: A list of integers sorted in non-decreasing order.", "function_declaration": "def merge_sort(arr):", "func...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef merge_sort(arr: List[int]) -> List[int]:\n if len(arr) <= 1:\n return arr\n\n mid = len(arr) // 2\n left_half =...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021964", "row_id": 21964, "seed_ids": "[12]" }
0.697506
Data_Structure_21964
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
5f3f9e029b757f2aa54383990585187e4e4c74e5
f7a3bb4ca487b2f42590df591333bdf8d1d17f6e
v1.0
instruct
Data_Structure
Data_Structure_21991_I
#### Context: A research institution needs to process a large amount of sensor data collected in an unsorted format. They seek to sort this data as efficiently as possible to perform further analysis. Implement a function that sorts an array of integers using heap sort. You can choose between max heap sort and min heap...
def heapify(arr, n, i, order='asc', simulation=False): if order == 'asc': largest = i left = 2 * i + 1 right = 2 * i + 2 if left < n and arr[i] < arr[left]: largest = left if right < n and arr[largest] < arr[right]: largest = right if larges...
from solution import heap_sort def test_heap_sort_ascending(): arr = [4, 10, 3, 5, 1] assert heap_sort(arr, 'asc', False) == [1, 3, 4, 5, 10] def test_heap_sort_descending(): arr = [4, 10, 3, 5, 1] assert heap_sort(arr, 'desc', False) == [10, 5, 4, 3, 1] def test_heap_sort_empty(): arr = [] a...
[ { "docstring": null, "function_declaration": "def heapify(arr, n, i, order='asc', simulation=False):", "function_name": "heapify", "parameter_list": "(arr, n, i, order='asc', simulation=False)" }, { "docstring": null, "function_declaration": "def heap_sort(arr, order='asc', simulation=Fa...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def heap_sort(arr, order='asc', simulation=False):\n def heapify(arr, n, i, desc):\n largest = i\n left = 2 * i + 1\n right = 2 * i + ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00021991", "row_id": 21991, "seed_ids": "[8]" }
0.657055
Data_Structure_21991
I
[ "heapify", "heap_sort" ]
2
[ [ "heap_sort", "heapify" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ea184d1eecb06c93552ff98427cf5d422f31c858
0d55d25deda2552a52421a7d5394339c607f0747
v1.0
instruct
Data_Structure
Data_Structure_22026_I
### Scenario You have been hired by a software company to write a function that sorts a list of floating-point numbers, taking advantage of the fact that before rounding, these numbers are uniformly distributed between 0.0 and 1.0. To achieve this, you decide to implement the bucket sort algorithm. ### Objective Write...
def insertion_sort(bucket): for i in range(1, len(bucket)): key = bucket[i] j = i - 1 while j >= 0 and key < bucket[j]: bucket[j + 1] = bucket[j] j -= 1 bucket[j + 1] = key return bucket def improved_bucket_sort(arr): if not arr: return [] ...
from solution import improved_bucket_sort def test_improved_bucket_sort_standard_case(): arr = [0.897, 0.565, 0.656, 0.123, 0.665, 0.343] assert improved_bucket_sort(arr) == [0.123, 0.343, 0.565, 0.656, 0.665, 0.897] def test_improved_bucket_sort_already_sorted(): arr = [0.1, 0.2, 0.3, 0.4, 0.5] asser...
[ { "docstring": null, "function_declaration": "def insertion_sort(bucket):", "function_name": "insertion_sort", "parameter_list": "(bucket)" }, { "docstring": null, "function_declaration": "def improved_bucket_sort(arr):", "function_name": "improved_bucket_sort", "parameter_list":...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def insertion_sort(bucket):\n for i in range(1, len(bucket)):\n key = bucket[i]\n j = i - 1\n while j >= 0 and bucket[j] > key:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022026", "row_id": 22026, "seed_ids": "[26]" }
0.562637
Data_Structure_22026
I
[ "insertion_sort", "improved_bucket_sort" ]
2
[ [ "improved_bucket_sort", "insertion_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
05f7c82981a6f0a16d7f4e300b30385eb5a5d860
5f463e82e966c5d26cceb96b2a4ad30936d058c5
v1.0
instruct
Data_Structure
Data_Structure_22043_I
### Question: Implement and Optimize Bucket Sort #### Context Imagine you are tasked with sorting a large list of floating-point numbers representing sensor readings collected within a specific range. The numbers are uniformly distributed between 0 and 1. #### Problem Statement Implement an optimized bucket sort func...
from typing import List def insertion_sort(arr: List[float]) -> List[float]: for i in range(1, len(arr)): key = arr[i] j = i - 1 while j >= 0 and key < arr[j]: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key return arr def optimized_bucket_sort(arr: List[flo...
from solution import optimized_bucket_sort def test_optimized_bucket_sort_basic(): assert optimized_bucket_sort([0.12, 0.25, 0.9, 0.5, 0.8]) == [0.12, 0.25, 0.5, 0.8, 0.9] def test_optimized_bucket_sort_empty(): assert optimized_bucket_sort([]) == [] def test_optimized_bucket_sort_single_element(): asser...
[ { "docstring": null, "function_declaration": "def insertion_sort(arr):", "function_name": "insertion_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def optimized_bucket_sort(arr):", "function_name": "optimized_bucket_sort", "parameter_list": "(a...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef optimized_bucket_sort(arr: List[float]) -> List[float]:\n if not arr:\n return []\n \n # Determine the number o...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022043", "row_id": 22043, "seed_ids": "[26]" }
0.516557
Data_Structure_22043
I
[ "insertion_sort", "optimized_bucket_sort" ]
2
[ [ "optimized_bucket_sort", "insertion_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
445e8701b399eaf48810d5c5df405efc43750979
088c2630b8a8b31a8b91a14921d2acfb633ba669
v1.0
instruct
Data_Structure
Data_Structure_22064_I
### RSA Encryption Algorithm: Secure Communication You are working on implementing a secure communication system using cryptography. In this challenge, you need to generate RSA keys and use them for encryption and decryption of messages. #### Task Complete the function `rsa_secure_communication(k, message)` that perf...
import random from sympy import isprime, primerange, mod_inverse def generate_large_prime(bits): """ Generate a prime number of given bit length. """ lower_bound = 2 ** (bits - 1) upper_bound = 2 ** bits - 1 while True: candidate = random.randint(lower_bound, upper_bound) i...
from solution import rsa_secure_communication def test_rsa_secure_communication_16bit(): k = 16 message = 123 encrypted_message, decrypted_message = rsa_secure_communication(k, message) assert decrypted_message == message def test_rsa_secure_communication_32bit(): k = 32 message = 45678 en...
[ { "docstring": "Generate a prime number of given bit length.", "function_declaration": "def generate_large_prime(bits):", "function_name": "generate_large_prime", "parameter_list": "(bits)" }, { "docstring": "Generate RSA public and private keys of bit length k.", "function_declaration":...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom sympy import isprime, mod_inverse\n\ndef generate_prime(bit_length):\n while True:\n p = random.getrandbits(bit_length)\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00022064", "row_id": 22064, "seed_ids": "[154]" }
0.671623
Data_Structure_22064
I
[ "generate_large_prime", "rsa_key_generation", "rsa_encrypt", "rsa_decrypt", "rsa_secure_communication" ]
5
[ [ "rsa_key_generation", "generate_large_prime" ], [ "rsa_secure_communication", "rsa_decrypt" ], [ "rsa_secure_communication", "rsa_encrypt" ], [ "rsa_secure_communication", "rsa_key_generation" ] ]
4
[]
false
[]
false
pytest
true
[ "sympy" ]
false
83835911aa81a1f33213130f4f4eadccc246de35
d48d88923a305913dd1bc04b126404c16365dae8
v1.0
instruct
Data_Structure
Data_Structure_22105_I
### Merge Sort Implementation Challenge #### Context: Merge Sort is a powerful and efficient sorting algorithm suitable for sorting large datasets, especially when the data to be sorted can be large and not fit into memory. You are required to implement the Merge Sort algorithm from scratch, focusing on its fundamenta...
from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts an array of integers using the merge sort algorithm. """ if len(arr) <= 1: return arr mid = len(arr) // 2 left_half = merge_sort(arr[:mid]) right_half = merge_sort(arr[mid:]) return merge(le...
from solution import merge_sort def test_merge_sort_empty_array(): assert merge_sort([]) == [] def test_merge_sort_sorted_array(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_sorted_array(): assert merge_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] def test_merge_sort_r...
[ { "docstring": "Sorts an array of integers using the merge sort algorithm.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two sorted lists into one sorted list.", "function_declaration": "def merge(left...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef merge_sort(arr: List[int]) -> List[int]:\n if len(arr) <= 1:\n return arr\n \n def merge(left: List[int], right...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022105", "row_id": 22105, "seed_ids": "[12]" }
0.667476
Data_Structure_22105
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a4f9d504a952be8a29c615c68a7d60e08b3d373b
067a5884705e8f3e20eb3e09630b4a2aaf9cec75
v1.0
instruct
Data_Structure
Data_Structure_22140_I
You are given a rather impractical algorithm called Bogo Sort, which attempts to sort an array by randomly shuffling it until it is sorted. Despite its lack of practical use, Bogo Sort serves as an educational example. Given this, your task is to implement a more efficient sorting algorithm, such as Merge Sort, and pr...
import random # Bogo Sort for comparison (not practical, included just for comparison study) def is_sorted(arr): return all(arr[i] <= arr[i+1] for i in range(len(arr)-1)) def bogo_sort(arr): while not is_sorted(arr): random.shuffle(arr) return arr # Efficient Merge Sort implementation def merge_s...
from solution import merge_sort, bogo_sort, is_sorted import time def test_merge_sort_empty(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_two_elements(): assert merge_sort([2, 1]) == [1, 2] def test_merge_sort_sorted_list(): as...
[ { "docstring": null, "function_declaration": "def is_sorted(arr):", "function_name": "is_sorted", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def bogo_sort(arr):", "function_name": "bogo_sort", "parameter_list": "(arr)" }, { "docstring": "So...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\n# Bogo Sort for comparison (not practical, included just for comparison study)\ndef is_sorted(arr):\n return all(arr[i] <= arr[i+1] for i ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022140", "row_id": 22140, "seed_ids": "[16]" }
0.518873
Data_Structure_22140
I
[ "is_sorted", "bogo_sort", "merge_sort", "merge" ]
4
[ [ "bogo_sort", "is_sorted" ], [ "merge_sort", "merge" ] ]
2
[]
false
[]
false
pytest
true
[]
true
d61a30498852237cb220b08f805148c954ff0281
b573a320da0bd9c6af2d4850306903045da8f9af
v1.0
instruct
Data_Structure
Data_Structure_22167_I
In advanced cryptographic systems, it is crucial to quickly determine if large numbers are prime. Using the Rabin-Miller primality test, you can efficiently check for primality with a high degree of certainty. **Scenario**: You are working for a tech company that needs to generate a list of large prime numbers for cry...
import random from typing import List def is_prime(n: int, k: int) -> bool: """Check if a number is prime using the Rabin-Miller primality test.""" if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False d = n - 1 r = 0 while d % 2 =...
from solution import generate_primes def test_generate_primes_small_range(): assert generate_primes(10, 5) == [2, 3, 5, 7] def test_generate_primes_medium_range(): assert generate_primes(50, 5) == [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47] def test_generate_primes_large_range(): assert gene...
[ { "docstring": "Check if a number is prime using the Rabin-Miller primality test.", "function_declaration": "def is_prime(n, k):", "function_name": "is_prime", "parameter_list": "(n, k)" }, { "docstring": "Generate list of prime numbers up to n using Rabin-Miller primality test.", "funct...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom typing import List\n\ndef is_prime(n: int, k: int) -> bool:\n \"\"\"Check if a number is prime using the Rabin-Miller primality test.\"...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022167", "row_id": 22167, "seed_ids": "[136]" }
0.598616
Data_Structure_22167
I
[ "is_prime", "generate_primes" ]
2
[ [ "generate_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4230af867c48c5ac85588f39cf35aa398df06472
ff000aef279a5719234a17fa37b783b73e05d8dc
v1.0
instruct
Data_Structure
Data_Structure_22170_I
#### Context: In mathematics, certain numbers display unique properties based on operations performed on their individual digits. One such property involves digit powers. For example, the number 89 satisfies the condition: \[ 8^1 + 9^2 = 89 \] Similarly, 135 satisfies: \[ 1^1 + 3^2 + 5^3 = 135 \] Your task is to implem...
def digit_power_sum(n): """ Function to calculate the sum of digits raised to their respective positions. """ return sum(int(digit)**(index + 1) for index, digit in enumerate(str(n))) def sum_digit_powers(low: int, high: int) -> list: """ Function to find all numbers between low and high (inclu...
from solution import sum_digit_powers def test_sum_digit_powers_single_digit_numbers(): assert sum_digit_powers(1, 9) == [1, 2, 3, 4, 5, 6, 7, 8, 9] def test_sum_digit_powers_small_range(): assert sum_digit_powers(1, 100) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 89] def test_sum_digit_powers_large_range(): assert ...
[ { "docstring": "Function to calculate the sum of digits raised to their respective positions.", "function_declaration": "def digit_power_sum(n):", "function_name": "digit_power_sum", "parameter_list": "(n)" }, { "docstring": "Function to find all numbers between low and high (inclusive)\ntha...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_digit_powers(low: int, high: int) -> list:\n \"\"\"\n This function returns a list of integers within the given range [low, high]\n that sati...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00022170", "row_id": 22170, "seed_ids": "[135]" }
0.673713
Data_Structure_22170
I
[ "digit_power_sum", "sum_digit_powers" ]
2
[ [ "sum_digit_powers", "digit_power_sum" ] ]
1
[]
false
[]
false
pytest
true
[]
true
cb38f07aae0f1771f1d94c14dc948ceadb24e4a1
abe5a70ef4fd12ff74ec2edfc4dd6d50b45d6ec5
v1.0
instruct
Data_Structure
Data_Structure_22218_I
### Question: Implement and Enhance Insertion Sort with Binary Search The Insertion Sort algorithm provided is a simple and intuitive way to sort small arrays. However, it has a performance bottleneck due to its O(n^2) time complexity. One way to optimize this algorithm is by using binary search to find the correct po...
from typing import List def binary_search(arr: List[int], val: int, start: int, end: int) -> int: """ This function performs binary search on subarray arr[start:end] to find the position where val fits. """ if start == end: if arr[start] > val: return start else: ...
from solution import enhanced_insertion_sort def test_enhanced_insertion_sort_example1(): assert enhanced_insertion_sort([64, 34, 25, 12, 22, 11, 90]) == [11, 12, 22, 25, 34, 64, 90] def test_enhanced_insertion_sort_example2(): assert enhanced_insertion_sort([-10, -50, 0, 20, 30, 10, -40]) == [-50, -40, -10, ...
[ { "docstring": "This function performs binary search on subarray arr[start:end] to find the position where val fits.", "function_declaration": "def binary_search(arr, val, start, end):", "function_name": "binary_search", "parameter_list": "(arr, val, start, end)" }, { "docstring": null, ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def binary_search(arr, val, start, end):\n \"\"\"\n Helper function to perform binary search and find the index\n where val should be inserted in the...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022218", "row_id": 22218, "seed_ids": "[7]" }
0.60801
Data_Structure_22218
I
[ "binary_search", "enhanced_insertion_sort" ]
2
[ [ "enhanced_insertion_sort", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c54fc5d7103dc655b3778765611244f3825622e2
59c597fdf674e81da1845370d11a0da83e48c3c4
v1.0
instruct
Data_Structure
Data_Structure_22231_I
### BinarySearchTree Deletion: You are required to implement the `delete_node` function in a given Binary Search Tree (BST). Specifically, you need to delete a node from the BST that matches a given key, ensuring that the tree remains a valid BST afterward. **Function Signature:** ```python def delete_node(root, key)...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def delete_node(root, key): if not root: return root if key < root.val: root.left = delete_node(root.left, key) elif key > root.val: ...
from solution import delete_node, build_tree, tree_to_list def test_delete_node_middle_node(): root = build_tree([5,3,6,2,4,None,7]) key = 3 expected_result = [5, 4, 6, 2, None, None, 7] new_root = delete_node(root, key) assert tree_to_list(new_root) == expected_result def test_delete_node_with_no...
[]
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef de...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022231", "row_id": 22231, "seed_ids": "[331]" }
0.592421
Data_Structure_22231
I
[ "delete_node", "get_min", "build_tree", "tree_to_list" ]
4
[ [ "delete_node", "get_min" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
27a9a073e4b72b5a77fd049be35df3c4440c23e3
2d7ddf622019b6155ef6cf9ecd54ee58e73bb271
v1.0
instruct
Data_Structure
Data_Structure_22234_I
### Question: Efficient GCD Calculation You have been provided with two functions that calculate the greatest common divisor (GCD) of two integers using different methods. Your task is to create a comprehensive function that combines the robustness and error handling of the standard Euclid's GCD calculation with the e...
def euclid_gcd(a, b): while b: a, b = b, a % b return a def bitwise_gcd(a, b): if a == 0: return b if b == 0: return a shift = 0 while ((a | b) & 1) == 0: a >>= 1 b >>= 1 shift += 1 while (a & 1) == 0: a >>= 1 while b != 0: ...
import pytest from solution import optimized_gcd def test_gcd_regular_case(): assert optimized_gcd(48, 18) == 6 assert optimized_gcd(100, 10) == 10 def test_gcd_prime_numbers(): assert optimized_gcd(13, 17) == 1 assert optimized_gcd(29, 13) == 1 def test_gcd_one_zero_input(): with pytest.raises(V...
[ { "docstring": null, "function_declaration": "def euclid_gcd(a, b):", "function_name": "euclid_gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def bitwise_gcd(a, b):", "function_name": "bitwise_gcd", "parameter_list": "(a, b)" }, { "docst...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def optimized_gcd(a, b):\n \"\"\"\n Returns the greatest common divisor of a and b using an optimized approach.\n Uses Euclid's method combined with ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022234", "row_id": 22234, "seed_ids": "[166]" }
0.746652
Data_Structure_22234
I
[ "euclid_gcd", "bitwise_gcd", "optimized_gcd" ]
3
[ [ "optimized_gcd", "bitwise_gcd" ], [ "optimized_gcd", "euclid_gcd" ] ]
2
[]
false
[]
false
pytest
true
[]
true
7c346f7ae7e672f4ea6559ad35bd23906064d8f7
10a8926375cacd8311c2d07f4093f7b432e83850
v1.0
instruct
Data_Structure
Data_Structure_22250_I
#### Scenario You work for a software security consulting firm that frequently needs to analyze encryption key strengths. One common task is to check if certain integers are prime, which is fundamental to determining the hardness of factorizing encryption keys. #### Task Implement an optimized function `next_prime(n...
def prime_check(n): """Return True if n is a prime number, else return False.""" if n <= 1: return False if n == 2 or n == 3: return True if n % 2 == 0 or n % 3 == 0: return False j = 5 while j * j <= n: if n % j == 0 or n % (j + 2) == 0: return False...
from solution import next_prime def test_next_prime_after_small_numbers(): assert next_prime(0) == 2 assert next_prime(1) == 2 def test_next_prime_after_prime_numbers(): assert next_prime(2) == 3 assert next_prime(3) == 5 assert next_prime(5) == 7 def test_next_prime_after_composite_numbers(): ...
[ { "docstring": "Return True if n is a prime number, else return False.", "function_declaration": "def prime_check(n):", "function_name": "prime_check", "parameter_list": "(n)" }, { "docstring": "Returns the smallest prime number greater than n.", "function_declaration": "def next_prime(n...
[ 1, 1 ]
2
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def prime_check(n):\n \"\"\"Return True if n is a prime number, else return False.\"\"\"\n\n if n <= 1:\n return False\n if n == 2 or n == 3:\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022250", "row_id": 22250, "seed_ids": "[143]" }
0.731099
Data_Structure_22250
I
[ "prime_check", "next_prime" ]
2
[ [ "next_prime", "prime_check" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3ea2b2f9d817c8e94501cc2616982ff46cee04e3
56e133d01d2701ddb338e9d0d2e80f7119a601f6
v1.0
instruct
Data_Structure
Data_Structure_22251_I
### Merge Sort - Enhanced Implementation #### Problem Statement: You have been hired as a software developer to improve the performance of an existing in-house sorting library. Currently, it uses a basic recursive implementation of the merge sort algorithm, which works well but consumes significant additional memory d...
def iterative_merge_sort(arr): """ Perform an in-place iterative merge sort on the given array. """ width = 1 n = len(arr) while width < n: for i in range(0, n, 2 * width): left = i mid = min(i + width, n) right = min(i + 2 * width, n) merg...
from solution import iterative_merge_sort def test_iterative_merge_sort_empty(): assert iterative_merge_sort([]) == [] def test_iterative_merge_sort_single_element(): assert iterative_merge_sort([1]) == [1] def test_iterative_merge_sort_sorted_array(): assert iterative_merge_sort([1, 2, 3, 4, 5]) == [1, ...
[ { "docstring": "Perform an in-place iterative merge sort on the given array.", "function_declaration": "def iterative_merge_sort(arr):", "function_name": "iterative_merge_sort", "parameter_list": "(arr)" }, { "docstring": "In-place merge function that merges two halves of an array.", "fu...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def merge(arr, l, m, r):\n # Helper function to merge two halves in place.\n n1 = m - l + 1\n n2 = r - m\n \n # Create temporary arrays \n L...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022251", "row_id": 22251, "seed_ids": "[12]" }
0.636578
Data_Structure_22251
I
[ "iterative_merge_sort", "merge" ]
2
[ [ "iterative_merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
e3ef034e2c2702cbd7ee2e066d323e45b49f6b9f
d314a9261ee876b5eabda1924189bb7b2e19b16d
v1.0
instruct
Data_Structure
Data_Structure_22295_I
### Question: Implement an Enhanced Sorting Solution You are tasked with improving upon the Stooge Sort algorithm to create a more efficient sorting method. Use your understanding from the analysis of Stooge Sort and principles from other efficient algorithms to design and implement a new sorting function. **Scenario...
def improved_sort(arr): """ This function sorts an array of integers in ascending order using merge sort algorithm which has O(n log n) time complexity. Parameters: arr (list): List of integers to be sorted Returns: list: Sorted list of integers """ if len(arr) <= 1: ...
from solution import improved_sort def test_improved_sort_sorted_array(): assert improved_sort([1, 2, 3]) == [1, 2, 3] def test_improved_sort_reverse_sorted_array(): assert improved_sort([3, 2, 1]) == [1, 2, 3] def test_improved_sort_unsorted_array(): assert improved_sort([3, 2, 5, 1, 4]) == [1, 2, 3...
[ { "docstring": "This function sorts an array of integers in ascending order using\nmerge sort algorithm which has O(n log n) time complexity.\n\nParameters:\narr (list): List of integers to be sorted\n\nReturns:\nlist: Sorted list of integers", "function_declaration": "def improved_sort(arr):", "functio...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def improved_sort(arr: list) -> list:\n \"\"\"\n Sorts the array in ascending order using Timsort, which is an optimized\n sorting algorithm derived ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022295", "row_id": 22295, "seed_ids": "[10]" }
0.63639
Data_Structure_22295
I
[ "improved_sort", "merge" ]
2
[ [ "improved_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8478075bb9ed6fb4e601219ddd045a6432f6d60c
b8fe1a8f879cbc615505ffaf438688928102d995
v1.0
instruct
Data_Structure
Data_Structure_22336_I
#### Scenario You are developing a sophisticated filtering system for a library's digital archiving tool. Given the massive collection of digitized books, your tool needs an efficient way to search for specific keyword patterns in text documents. #### Task Implement a Python function to check if a given keyword patte...
def compute_lps(pattern): length = 0 lps = [0] * len(pattern) i = 1 while i < len(pattern): if pattern[i] == pattern[length]: length += 1 lps[i] = length i += 1 else: if length != 0: length = lps[length - 1] els...
from solution import is_pattern_in_text def test_pattern_exists(): assert is_pattern_in_text('hello there hero!', 'hero') == True def test_pattern_does_not_exist(): assert is_pattern_in_text('a quick brown fox', 'lazy') == False def test_pattern_exists_with_repeated_substring(): assert is_pattern_in_text...
[ { "docstring": null, "function_declaration": "def compute_lps(pattern):", "function_name": "compute_lps", "parameter_list": "(pattern)" }, { "docstring": null, "function_declaration": "def is_pattern_in_text(text, pattern):", "function_name": "is_pattern_in_text", "parameter_list...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_pattern_in_text(text: str, pattern: str) -> bool:\n \"\"\"\n This function leverages the Knuth-Morris-Pratt (KMP) algorithm to check if the patte...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022336", "row_id": 22336, "seed_ids": "[93]" }
0.540123
Data_Structure_22336
I
[ "compute_lps", "is_pattern_in_text" ]
2
[ [ "is_pattern_in_text", "compute_lps" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4c27f95d1ed4ba7853ef1cfb0b038a7e0ef16ab0
35e38db8582a52c4bd1a80f6b2f8d6abba40ea5f
v1.0
instruct
Data_Structure
Data_Structure_22367_I
### Binary Search Tree Operations As a programming exercise, you will implement insertion, searching, and deletion operations for a Binary Search Tree (BST). The purpose of each operation is to maintain the fundamental properties of a BST. ### Task: 1. **Insert a value into the BST**. 2. **Search for a value in the ...
class TreeNode: def __init__(self, key): self.left = None self.right = None self.val = key def insert(root, key): """ Insert a key into the BST. If the tree is empty, return a new node. Otherwise, recur down the tree and insert the key. Returned root should point to the new ...
from solution import TreeNode, insert, search, delete def test_insert(): root = TreeNode(4) root = insert(root, 2) root = insert(root, 6) root = insert(root, 1) root = insert(root, 3) root = insert(root, 5) root = insert(root, 7) # Test structure assert root.val == 4 assert...
[]
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, key):\n self.left = None\n self.right = None\n self.val = key\n\ndef insert(root, key):\n \"\"...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022367", "row_id": 22367, "seed_ids": "[287]" }
0.534557
Data_Structure_22367
I
[ "insert", "search", "delete", "minValueNode" ]
4
[ [ "delete", "minValueNode" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
efa1e0969db94b8d376d0ec5341a4b82e0487cd3
c1bcd05d88750561b6a44a3d61f1848fcab3e7ab
v1.0
instruct
Data_Structure
Data_Structure_22377_I
You are given an undirected graph represented by an adjacency list. Your task is to implement algorithms to find all maximal cliques in the graph. However, to demonstrate advanced understanding, you need to make the following enhancements: 1. Optimize the Bron-Kerbosch algorithm using pivoting to reduce the number of ...
from typing import List, Tuple, Set def bron_kerbosch_pivot(R: Set[int], P: Set[int], X: Set[int], adj_list: List[Set[int]], cliques: List[List[int]]): if not P and not X: cliques.append(list(R)) return u = next(iter(P.union(X))) for v in P - adj_list[u]: bron_kerbosch_pivot(R.union...
from solution import find_all_maximal_cliques, find_largest_clique def test_find_all_maximal_cliques_single_clique(): n = 5 edges = [(1, 2), (2, 3), (3, 1), (1, 4), (4, 5)] expected_cliques = [[1, 2, 3], [1, 4], [4, 5]] actual_cliques = find_all_maximal_cliques(n, edges) assert len(actual_cliques) ...
[ { "docstring": null, "function_declaration": "def bron_kerbosch_pivot(R, P, X, adj_list, cliques):", "function_name": "bron_kerbosch_pivot", "parameter_list": "(R, P, X, adj_list, cliques)" }, { "docstring": null, "function_declaration": "def find_all_maximal_cliques(n, edges):", "fu...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def find_all_maximal_cliques(n, edges):\n def bron_kerbosch(R, P, X, adj_list):\n if not P and not X:\n yield R\n else:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022377", "row_id": 22377, "seed_ids": "[236]" }
0.499093
Data_Structure_22377
I
[ "bron_kerbosch_pivot", "find_all_maximal_cliques", "find_largest_clique" ]
3
[ [ "find_all_maximal_cliques", "bron_kerbosch_pivot" ] ]
1
[]
false
[]
false
pytest
true
[]
true
9d8bbd4dbdd12cfafacaa20728d9a6a5f48a22ee
c8e02f9d78a0aac064dfe97d5f32181cdce633f4
v1.0
instruct
Data_Structure
Data_Structure_22392_I
**Problem: Binary Search Implementation and Application** You are to implement the binary search algorithm both iteratively and recursively. In addition, you will write a function to use binary search for finding the first and last occurrence of a given target in a sorted array. ### Function Definitions ```python def...
from typing import List, Tuple def binary_search_iter(array: List[int], target: int) -> int: """ Implement the binary search algorithm iteratively. Parameters: array (List[int]): A sorted list of integers in ascending order. target (int): An integer value to search for in the array. R...
from solution import binary_search_iter, binary_search_recur, find_first_and_last def test_binary_search_iter_found(): assert binary_search_iter([1, 2, 3, 4, 5], 3) == 2 def test_binary_search_iter_not_found(): assert binary_search_iter([1, 2, 3, 4, 5], 6) == -1 def test_binary_search_recur_found(): asse...
[ { "docstring": "Implement the binary search algorithm iteratively.\n\nParameters:\narray (List[int]): A sorted list of integers in ascending order.\ntarget (int): An integer value to search for in the array.\n\nReturns:\nint: The index of the target in the array if found, otherwise -1.", "function_declarati...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef binary_search_iter(array: List[int], target: int) -> int:\n low, high = 0, array.length - 1\n while low <= high:\n...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00022392", "row_id": 22392, "seed_ids": "[200]" }
0.739775
Data_Structure_22392
I
[ "binary_search_iter", "binary_search_recur", "find_first_and_last", "find_first_occurrence", "find_last_occurrence" ]
5
[ [ "find_first_and_last", "find_first_occurrence" ], [ "find_first_and_last", "find_last_occurrence" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ab291ab0ab8875a1045803194271eb692d7b944b
4a67aeac73824156b075b9864f3e83cd074ba0ca
v1.0
instruct
Data_Structure
Data_Structure_22447_I
#### **Title**: Advanced GCD Computation using Bitwise Operations #### **Objective**: Write a Python function to compute the Greatest Common Divisor (GCD) of two non-negative integers using bitwise operations efficiently. This function should handle large input values robustly. #### **Function Signature**: ```python ...
def trailing_zero(x): count = 0 while x and (x & 1) == 0: count += 1 x >>= 1 return count def gcd_bitwise(a: int, b: int) -> int: if a == 0: return b if b == 0: return a # Finding the number of trailing zero bits in both numbers shift = min(trailing_zero(a), trailing_zero(b...
from solution import gcd_bitwise def test_gcd_bitwise_basic(): assert gcd_bitwise(12, 15) == 3 def test_gcd_bitwise_large_numbers(): assert gcd_bitwise(1000000000, 500000000) == 500000000 def test_gcd_bitwise_one_zero(): assert gcd_bitwise(0, 10) == 10 assert gcd_bitwise(10, 0) == 10 def test_gcd_bi...
[ { "docstring": null, "function_declaration": "def trailing_zero(x):", "function_name": "trailing_zero", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def gcd_bitwise(a, b):", "function_name": "gcd_bitwise", "parameter_list": "(a, b)" } ]
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def trailing_zero(x):\n count = 0\n while x and not x & 1:\n count += 1\n x >>= 1\n return count\n\ndef gcd_bitwise(a: int, b: int) -> ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022447", "row_id": 22447, "seed_ids": "[166]" }
0.681999
Data_Structure_22447
I
[ "trailing_zero", "gcd_bitwise" ]
2
[ [ "gcd_bitwise", "trailing_zero" ] ]
1
[]
false
[]
false
pytest
true
[]
true
45d901b057fcfedecf3144e9a5b8aeecf2efa9a3
af4dc09cecdefb782c507458a13b23e3359dfd65
v1.0
instruct
Data_Structure
Data_Structure_22496_I
### Linked List Intersection Finder #### Problem Statement You are given two singly linked lists that may or may not intersect at some point. Write a function `find_intersection(head1, head2)` that returns the first common node in both lists. If no intersection exists, return `None`. #### Input * `head1` - The head ...
class Node: def __init__(self, val=None): self.val = val self.next = None def get_length(head): length = 0 current = head while current: length += 1 current = current.next return length def find_intersection(head1, head2): # Get lengths of both lists len1 = ...
from solution import Node, find_intersection def test_find_intersection_with_intersection(): a1 = Node(1) b1 = Node(3) c1 = Node(5) d = Node(7) a2 = Node(2) b2 = Node(4) c2 = Node(6) e = Node(9) f = Node(11) a1.next = b1 b1.next = c1 c1.next = d a2.next = b2 b2....
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "class Node:\n def __init__(self, val=None):\n self.val = val\n self.next = None\n\ndef get_length_and_tail(node):\n length = 0\n while ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022496", "row_id": 22496, "seed_ids": "[245]" }
0.571114
Data_Structure_22496
I
[ "get_length", "find_intersection" ]
2
[ [ "find_intersection", "get_length" ] ]
1
[]
false
[ "Node" ]
true
pytest
true
[]
true
576f1ddc00fa7edea31eda7d8035c6b7bfbae888
87163ea5f9a94fb3233382e08441ce3fa91c3159
v1.0
instruct
Data_Structure
Data_Structure_22511_I
**Graph Traversal Challenge** You are given an undirected graph represented as an adjacency list. Your task is to implement two different graph traversal algorithms: Depth First Search (DFS) and Breadth First Search (BFS). Additionally, you need to identify and return all the disconnected components in the graph. ###...
def dfs_component(graph, start): """ Perform a Depth First Search (DFS) to identify all nodes in the component connected to `start`. """ visited = set() stack = [start] result = [] while stack: node = stack.pop() if node not in visited: visited.add(node) ...
from solution import dfs_component, bfs_component, find_all_components def test_dfs_component(): graph = { 'A': ['B'], 'B': ['A', 'C'], 'C': ['B'], 'D': ['E'], 'E': ['D'] } result = dfs_component(graph, 'A') assert set(result) == {'A', 'B', 'C'} def test_bfs_component(): graph = { ...
[ { "docstring": "Perform a Depth First Search (DFS) to identify all nodes in the component connected to `start`.", "function_declaration": "def dfs_component(graph, start):", "function_name": "dfs_component", "parameter_list": "(graph, start)" }, { "docstring": "Perform a Breadth First Search...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def dfs_component(graph, start):\n \"\"\"\n Perform a Depth First Search (DFS) to find all nodes in the component connected to the start node.\n \"\"...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022511", "row_id": 22511, "seed_ids": "[224]" }
0.561459
Data_Structure_22511
I
[ "dfs_component", "bfs_component", "find_all_components" ]
3
[ [ "find_all_components", "bfs_component" ] ]
1
[]
false
[]
false
pytest
true
[]
true
446c1d35e8e36a31724e3f40476e857b6e857a11
20d0e9849ce1b94398b1b222daeafeb3689548c2
v1.0
instruct
Data_Structure
Data_Structure_22534_I
### Insertion Sort Implementation with Search Insert Helper #### Objective: Implement the insertion sort algorithm using the provided `search_insert` helper method to correctly insert elements into a sorted part of the array. #### Input: - A list of integers `arr` representing the unsorted array. #### Output: - A so...
def search_insert(array, val): low = 0 high = len(array) - 1 while low <= high: mid = low + (high - low) // 2 if val > array[mid]: low = mid + 1 else: high = mid - 1 return low def insertion_sort(arr): for i in range(1, len(arr)): val = arr[i]...
def test_search_insert(): assert search_insert([1, 2, 4, 5], 3) == 2 assert search_insert([1, 2, 4, 5], 0) == 0 assert search_insert([1, 2, 4, 5], 6) == 4 assert search_insert([1, 2, 4, 5], 4) == 2 def test_insertion_sort(): assert insertion_sort([3, 1, 4, 5, 2]) == [1, 2, 3, 4, 5] assert inser...
[ { "docstring": null, "function_declaration": "def search_insert(array, val):", "function_name": "search_insert", "parameter_list": "(array, val)" }, { "docstring": null, "function_declaration": "def insertion_sort(arr):", "function_name": "insertion_sort", "parameter_list": "(arr...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def search_insert(array, val):\n low = 0\n high = len(array) - 1\n while low <= high:\n mid = low + (high - low) // 2\n if val > array[...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022534", "row_id": 22534, "seed_ids": "[199]" }
0.6134
Data_Structure_22534
I
[ "search_insert", "insertion_sort" ]
2
[ [ "insertion_sort", "search_insert" ] ]
1
[]
false
[]
false
pytest
false
[]
true
f0adfca37dbfa52c46d1cb92521b6960ff0274d3
6b9514ff498834c5fa91383146b5b10756879fed
v1.0
instruct
Data_Structure
Data_Structure_22562_I
Matrix Inversion Implementation **Problem Statement:** Given an n x n matrix, write a function `invert_matrix(matrix)` that returns its inverse. If the matrix is not invertible or does not satisfy the required conditions, return a suitable error code within a matrix format as described below. **Function Signature:**...
from typing import List def get_matrix_minor(matrix, i, j): return [row[:j] + row[j+1:] for row in (matrix[:i] + matrix[i+1:])] def get_matrix_determinant(matrix): # Special case for 2x2 matrix if len(matrix) == 2: return matrix[0][0]*matrix[1][1] - matrix[0][1]*matrix[1][0] determinant = 0 ...
from solution import invert_matrix def test_valid_2x2_matrix(): matrix = [ [4, 7], [2, 6] ] expected = [ [0.6, -0.7], [-0.2, 0.4] ] result = invert_matrix(matrix) for r in range(len(expected)): for c in range(len(expected[r])): assert round(re...
[ { "docstring": null, "function_declaration": "def get_matrix_minor(matrix, i, j):", "function_name": "get_matrix_minor", "parameter_list": "(matrix, i, j)" }, { "docstring": null, "function_declaration": "def get_matrix_determinant(matrix):", "function_name": "get_matrix_determinant"...
[ 0, 0, 0, 1, 0, 0, 1, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef invert_matrix(matrix: List[List[float]]) -> List[List[float]]:\n def is_square(m):\n return all(len(row) == len(m) fo...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00022562", "row_id": 22562, "seed_ids": "[347]" }
0.594529
Data_Structure_22562
I
[ "get_matrix_minor", "get_matrix_determinant", "get_matrix_inverse", "invert_matrix" ]
4
[ [ "get_matrix_determinant", "get_matrix_minor" ], [ "get_matrix_inverse", "get_matrix_determinant" ], [ "get_matrix_inverse", "get_matrix_minor" ], [ "invert_matrix", "get_matrix_inverse" ] ]
4
[]
false
[]
false
pytest
true
[]
true
977162e252d653eb7be26f09899cd4b6a22a0032
f7a41aff0a8fdf481fce5010b7915fc6de9edece
v1.0
instruct
Data_Structure
Data_Structure_22583_I
### Quick Sort Implementation with Median-of-Three Optimization #### Background Quick Sort is a popularly used sorting algorithm. However, its performance largely depends on the choice of pivot. The median-of-three method is an optimization technique that selects the pivot as the median of three elements (first, middl...
def median_of_three(arr, low, mid, high): if (arr[low] - arr[mid]) * (arr[high] - arr[low]) >= 0: return low elif (arr[mid] - arr[low]) * (arr[high] - arr[mid]) >= 0: return mid else: return high def insertion_sort(arr, low, high): for i in range(low + 1, high + 1): key ...
from solution import optimized_quick_sort def test_optimized_quick_sort_small_array(): assert optimized_quick_sort([3, 1, 2], 2) == [1, 2, 3] def test_optimized_quick_sort_with_k_larger_than_array(): assert optimized_quick_sort([10, 5, 7, 9], 5) == [5, 7, 9, 10] def test_optimized_quick_sort_with_duplicates(...
[ { "docstring": null, "function_declaration": "def median_of_three(arr, low, mid, high):", "function_name": "median_of_three", "parameter_list": "(arr, low, mid, high)" }, { "docstring": null, "function_declaration": "def insertion_sort(arr, low, high):", "function_name": "insertion_s...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def median_of_three(arr, low, mid, high):\n if (arr[low] - arr[mid]) * (arr[high] - arr[low]) >= 0:\n return low\n elif (arr[mid] - arr[low]) * (...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022583", "row_id": 22583, "seed_ids": "[25]" }
0.624744
Data_Structure_22583
I
[ "median_of_three", "insertion_sort", "partition", "quick_sort", "optimized_quick_sort" ]
5
[ [ "optimized_quick_sort", "quick_sort" ], [ "partition", "median_of_three" ], [ "quick_sort", "insertion_sort" ], [ "quick_sort", "partition" ] ]
4
[]
false
[]
false
pytest
true
[]
true
3ace2e75655051187edc08c788205aa40a5f53d1
b72349513b5f8d9b0716481668b39cd838443167
v1.0
instruct
Data_Structure
Data_Structure_22593_I
You are tasked with enhancing a Markov Chain implementation. This Markov Chain is modeled using a dictionary with each state having a dictionary of possible next states and their respective probabilities. Your goal is to extend the functionality and improve efficiency. #### Requirements 1. **Function 1 - validate_chai...
import random def validate_chain(chain): """ Validates whether the provided Markov chain is valid. Parameters: - chain (dict): Dictionary representing the Markov chain. Returns: - bool: True if the chain is valid, False otherwise. """ for state, transitions in chain.items(): ...
from solution import validate_chain, predict_state def test_validate_chain_valid(): my_chain = { 'A': {'A': 0.6, 'E': 0.4}, 'E': {'A': 0.7, 'E': 0.3} } assert validate_chain(my_chain) == True def test_validate_chain_invalid_prob_sum(): my_chain = { 'A': {'A': 0.6, 'E': 0.5}, ...
[ { "docstring": "Validates whether the provided Markov chain is valid.\n\nParameters:\n- chain (dict): Dictionary representing the Markov chain. \n\nReturns:\n- bool: True if the chain is valid, False otherwise.", "function_declaration": "def validate_chain(chain):", "function_name": "validate_chain", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef validate_chain(chain):\n \"\"\"\n Validates whether the provided Markov chain is valid.\n \n Parameters:\n - chain (dict):...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022593", "row_id": 22593, "seed_ids": "[232]" }
0.437934
Data_Structure_22593
I
[ "validate_chain", "predict_state", "__choose_state" ]
3
[ [ "predict_state", "__choose_state" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8813bc8cbd678bab6f86b68b3d79941d0eed58c4
b05d0c249dde63aeded6c66da6e83778d63f80c5
v1.0
instruct
Data_Structure
Data_Structure_22600_I
## Problem Statement You are given an array of floating point numbers in the range [0, 1). Implement the `bucket_sort` function to sort this array. Each element is to be placed into bins, then bins are sorted individually using insertion sort, and finally, bins are concatenated to form the sorted array. Write a `bucke...
from typing import List def insertion_sort(arr: List[float]) -> List[float]: for i in range(1, len(arr)): key = arr[i] j = i - 1 while j >= 0 and key < arr[j]: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key return arr def bucket_sort(arr: List[float]) -> Li...
from solution import bucket_sort def test_bucket_sort(): assert bucket_sort([0.789, 0.123, 0.456, 0.333]) == [0.123, 0.333, 0.456, 0.789] assert bucket_sort([0.5, 0.7, 0.1]) == [0.1, 0.5, 0.7] assert bucket_sort([0.25, 0.85, 0.45, 0.65]) == [0.25, 0.45, 0.65, 0.85] assert bucket_sort([]) == [] asse...
[ { "docstring": null, "function_declaration": "def insertion_sort(arr):", "function_name": "insertion_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def bucket_sort(arr):", "function_name": "bucket_sort", "parameter_list": "(arr)" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef insertion_sort(bucket: List[float]) -> List[float]:\n for i in range(1, len(bucket)):\n key = bucket[i]\n j = ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022600", "row_id": 22600, "seed_ids": "[26]" }
0.552023
Data_Structure_22600
I
[ "insertion_sort", "bucket_sort" ]
2
[ [ "bucket_sort", "insertion_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0bd4775e30b7567a40ba79015f156ecde0020788
a363e7e5938eb81d1d26a1b44414a03e6b222f18
v1.0
instruct
Data_Structure
Data_Structure_22665_I
### Quick Sort Algorithm Implementation You are required to implement a recursive Quick Sort function. The function should take an array of integers as input and sort it in ascending order. A secondary function for partitioning the array around a pivot element is also to be implemented. #### Function Signature ```pyt...
from typing import List def partition(arr: List[int], first: int, last: int) -> int: pivot = arr[last] i = first - 1 for j in range(first, last): if arr[j] <= pivot: i += 1 arr[i], arr[j] = arr[j], arr[i] arr[i+1], arr[last] = arr[last], arr[i+1] return i+1 def quic...
from solution import quick_sort, partition def test_quick_sort_example_1(): assert quick_sort([3, 6, 8, 10, 1, 2, 1]) == [1, 1, 2, 3, 6, 8, 10] def test_quick_sort_example_2(): assert quick_sort([1, -1, 0]) == [-1, 0, 1] def test_quick_sort_empty(): assert quick_sort([]) == [] def test_quick_sort_single...
[ { "docstring": null, "function_declaration": "def partition(arr, first, last):", "function_name": "partition", "parameter_list": "(arr, first, last)" }, { "docstring": null, "function_declaration": "def quick_sort(arr):", "function_name": "quick_sort", "parameter_list": "(arr)" ...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef partition(arr: List[int], first: int, last: int) -> int:\n pivot = arr[last]\n i = first - 1\n for j in range(first, l...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022665", "row_id": 22665, "seed_ids": "[25]" }
0.623027
Data_Structure_22665
I
[ "partition", "quick_sort" ]
2
[ [ "quick_sort", "partition" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a1f5dc4c0db58ab9806dce80d2f3795e65a85881
1f4823f175e9a55f73f1107338054e719e41f45b
v1.0
instruct
Data_Structure
Data_Structure_22667_I
### Question: Bitwise Multiplier Imagine working in a low-level systems environment where standard arithmetic operations are restricted or require optimized procedures. Inspired by the concept of bitwise addition, you are tasked with implementing a function to multiply two non-negative integers using bitwise operation...
def multiply_bitwise_operator(x: int, y: int) -> int: """ Multiplies two non-negative integers using bitwise operations. """ result = 0 while y > 0: # If the rightmost bit of y is set, add x to the result if y & 1: result = add_bitwise(result, x) # Shift x left by...
import pytest from solution import multiply_bitwise_operator def test_multiply_bitwise_operator(): assert multiply_bitwise_operator(3, 4) == 12 assert multiply_bitwise_operator(0, 5) == 0 assert multiply_bitwise_operator(2, 10) == 20 assert multiply_bitwise_operator(1, 1) == 1 assert multiply_bitwi...
[ { "docstring": "Multiplies two non-negative integers using bitwise operations.", "function_declaration": "def multiply_bitwise_operator(x, y):", "function_name": "multiply_bitwise_operator", "parameter_list": "(x, y)" }, { "docstring": "Adds two non-negative integers using bitwise operations...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def multiply_bitwise_operator(x: int, y: int) -> int:\n \"\"\"\n Multiplies two non-negative integers using bitwise operations.\n \"\"\"\n result ...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022667", "row_id": 22667, "seed_ids": "[209]" }
0.689845
Data_Structure_22667
I
[ "multiply_bitwise_operator", "add_bitwise" ]
2
[ [ "multiply_bitwise_operator", "add_bitwise" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6a6948acebe082c14243cb95e88a0104499677a3
beceeca943c175449058187b6bd0fe3d7660e532
v1.0
instruct
Data_Structure
Data_Structure_22674_I
### Merge Sort Implementation Challenge Merge Sort is a highly efficient, stable, and comparison-based sorting algorithm. As you have learned, it works on the principle of divide and conquer. Your task is to implement the Merge Sort algorithm based on the provided guidelines. #### Problem Statement Implement the `mer...
from typing import List def merge_sort(arr: List[int]) -> List[int]: if len(arr) <= 1: return arr mid = len(arr) // 2 left = merge_sort(arr[:mid]) right = merge_sort(arr[mid:]) merged = [0] * len(arr) merge(left, right, merged) return merged def merge(left: List[int]...
from solution import merge_sort def test_merge_sort_empty_list(): assert merge_sort([]) == [] def test_merge_sort_single_element(): assert merge_sort([1]) == [1] def test_merge_sort_sorted_list(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_sorted_list(): assert...
[ { "docstring": null, "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def merge(left, right, merged):", "function_name": "merge", "parameter_list": "(left, right, merged)" }...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef merge_sort(arr: List[int]) -> List[int]:\n if len(arr) <= 1:\n return arr\n\n mid = len(arr) // 2\n left_half =...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022674", "row_id": 22674, "seed_ids": "[12]" }
0.66071
Data_Structure_22674
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a06f4fe7ff98ef204ecfff5a47163785af891439
e7d2722312f10aac0f6530afbe44e0147bf6b883
v1.0
instruct
Data_Structure
Data_Structure_22676_I
**Graph Traversal and Path Finding** As a software engineer, you are tasked with implementing an algorithm to determine if there exists a path between two nodes in an unweighted graph. The graph is represented as an adjacency list. Your task involves the following: 1. Implement an iterative DFS and BFS traversal fun...
from collections import deque from typing import List, Dict def does_path_exist_dfs(graph: Dict[int, List[int]], start: int, end: int) -> bool: """ Determine if a path exists from start to end using Depth-First Search (DFS). """ stack = [start] visited = set() while stack: node = s...
from solution import does_path_exist_dfs, does_path_exist_bfs, compare_performance def test_does_path_exist_dfs(): graph = { 0: [1, 2], 1: [3, 4], 2: [5], 3: [], 4: [], 5: [] } assert does_path_exist_dfs(graph, 0, 4) is True assert does_path_exist_dfs(gra...
[ { "docstring": "Determine if a path exists from start to end using Depth-First Search (DFS).", "function_declaration": "def does_path_exist_dfs(graph, start, end):", "function_name": "does_path_exist_dfs", "parameter_list": "(graph, start, end)" }, { "docstring": "Determine if a path exists ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\nfrom typing import Dict, List\n\ndef does_path_exist_dfs(graph: Dict[int, List[int]], start: int, end: int) -> bool:\n \"\"\...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022676", "row_id": 22676, "seed_ids": "[224]" }
0.625915
Data_Structure_22676
I
[ "does_path_exist_dfs", "does_path_exist_bfs", "compare_performance" ]
3
[ [ "compare_performance", "does_path_exist_bfs" ], [ "compare_performance", "does_path_exist_dfs" ] ]
2
[]
false
[]
false
pytest
true
[]
true
151ec0615832f0e5b528357c55d9a3e63cbf2d68
ebd3a197250b14bd569cab63b571e57811be42a5
v1.0
instruct
Data_Structure
Data_Structure_22776_I
### Context You work for an e-commerce company, and your task is to enhance the sorting mechanism used for listing item prices. Your company deals exclusively with non-negative integer prices. Efficient sorting helps in multiple operations, including searching for price ranges, filtering certain price points, and dynam...
from typing import List def counting_sort(arr: List[int], exp: int) -> List[int]: n = len(arr) output = [0] * n count = [0] * 10 # Since we're dealing with base 10 numbers for i in range(n): index = (arr[i] // exp) % 10 count[index] += 1 for i in range(1, 10): count[i] +=...
from solution import radix_sort_prices def test_radix_sort_empty_list(): assert radix_sort_prices([]) == [] def test_radix_sort_single_element_list(): assert radix_sort_prices([1]) == [1] def test_radix_sort_multiple_elements(): assert radix_sort_prices([170, 45, 75, 90, 802, 24, 2, 66]) == [2, 24, 45, 6...
[ { "docstring": null, "function_declaration": "def counting_sort(arr, exp):", "function_name": "counting_sort", "parameter_list": "(arr, exp)" }, { "docstring": null, "function_declaration": "def radix_sort_prices(prices):", "function_name": "radix_sort_prices", "parameter_list": ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef counting_sort(arr: List[int], exp: int) -> List[int]:\n n = len(arr)\n output = [0] * n\n count = [0] * 10\n\n for ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022776", "row_id": 22776, "seed_ids": "[15]" }
0.590967
Data_Structure_22776
I
[ "counting_sort", "radix_sort_prices" ]
2
[ [ "radix_sort_prices", "counting_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d9bc057c8832b3eaee6344faf1bb462dc6a97593
b0517b04b1c5fb85ac821ea72ae4331a71ca00bc
v1.0
instruct
Data_Structure
Data_Structure_22799_I
Implement Optimized Exchange Sort You are provided with an inefficient Exchange Sort algorithm. Your task is to implement a more efficient sorting algorithm to sort a given list of integers in ascending order. You can choose any of the following more efficient sorting algorithms: 1. Quick Sort 2. Merge Sort 3. Heap S...
def merge_sort(arr): """ Sorts an array of integers in ascending order using Merge Sort. """ if len(arr) <= 1: return arr # Split the array into two halves mid = len(arr) // 2 left_half = merge_sort(arr[:mid]) right_half = merge_sort(arr[mid:]) # Merge the sorted ha...
from solution import merge_sort def test_merge_sort_sorted(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_merge_sort_reverse_sorted(): assert merge_sort([5, 4, 3, 2, 1]) == [1, 2, 3, 4, 5] def test_merge_sort_unsorted(): assert merge_sort([64, 34, 25, 12, 22, 11, 90]) == [11, 12, 22, 2...
[ { "docstring": "Sorts an array of integers in ascending order using Merge Sort.", "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": "Merges two sorted lists into one sorted list.", "function_declaration": "def merge...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def optimized_sort(arr):\n \"\"\"\n Sorts a list of integers using Merge Sort algorithm.\n \"\"\"\n if len(arr) <= 1:\n return arr\n\n d...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022799", "row_id": 22799, "seed_ids": "[28]" }
0.602858
Data_Structure_22799
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
494f0387dc30be6ccf42488a87cb849422dee2b8
c34350248d1958b05a5b505a734457ce6d2f522b
v1.0
instruct
Data_Structure
Data_Structure_22825_I
## Problem Statement You have been provided with the implementation of the Extended Euclidean Algorithm. Your task is to use this algorithm to solve a real-world problem. ### Task Given two positive integers `a` and `b`, write a function `find_coprime_solution(a: int, b: int) -> Tuple[int, int, int]` that finds inte...
from typing import Tuple def extended_gcd(a: int, b: int) -> Tuple[int, int, int]: """ Extended Euclidean Algorithm to find the coefficients (x, y) such that a * x + b * y = gcd(a, b). """ if b == 0: return (1, 0, a) else: x1, y1, gcd = extended_gcd(b, a % b) x = y1 ...
from solution import find_coprime_solution def test_find_coprime_solution_example1(): x, y, gcd = find_coprime_solution(30, 50) assert 30 * x + 50 * y == gcd assert gcd == 10 def test_find_coprime_solution_example2(): x, y, gcd = find_coprime_solution(101, 10) assert 101 * x + 10 * y == gcd as...
[ { "docstring": "Extended Euclidean Algorithm to find the coefficients (x, y) such that\na * x + b * y = gcd(a, b).", "function_declaration": "def extended_gcd(a, b):", "function_name": "extended_gcd", "parameter_list": "(a, b)" }, { "docstring": "Find integers x and y such that a * x + b * y...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import Tuple\n\ndef extended_gcd(a: int, b: int) -> Tuple[int, int, int]:\n \"\"\"\n Extended Euclidean Algorithm to find the coefficients (...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022825", "row_id": 22825, "seed_ids": "[156]" }
0.689096
Data_Structure_22825
I
[ "extended_gcd", "find_coprime_solution" ]
2
[ [ "find_coprime_solution", "extended_gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3f1bd7224c8bbda4750c53cb130cd7c0fa946c37
32f7573c7eb44c087e9d34b086e5e94d6f5a86fb
v1.0
instruct
Data_Structure
Data_Structure_22836_I
### Insertion Sort with Binary Search You are required to implement the Insertion Sort algorithm using the binary search helper method `search_insert` provided. The objective is to optimize the insertion step using binary search to locate the position where each element should be inserted to maintain sorted order. ##...
from typing import List def search_insert(array: List[int], low: int, high: int, target: int) -> int: """ Helper function to perform binary search for the target in the array[low:high+1] and return the index where the target should be inserted. """ while low <= high: mid = (low + high) // 2...
from solution import insertion_sort def test_insertion_sort_example_1(): assert insertion_sort([12, 11, 13, 5, 6]) == [5, 6, 11, 12, 13] def test_insertion_sort_example_2(): assert insertion_sort([4, 3, 2, 10, 12, 1, 5, 6]) == [1, 2, 3, 4, 5, 6, 10, 12] def test_insertion_sort_empty(): assert insertion_s...
[ { "docstring": "Helper function to perform binary search for the target in the array[low:high+1]\nand return the index where the target should be inserted.", "function_declaration": "def search_insert(array, low, high, target):", "function_name": "search_insert", "parameter_list": "(array, low, high...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef search_insert(arr: List[int], value: int) -> int:\n \"\"\"\n Helper function to use binary search to find the index where...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022836", "row_id": 22836, "seed_ids": "[199]" }
0.585913
Data_Structure_22836
I
[ "search_insert", "insertion_sort" ]
2
[ [ "insertion_sort", "search_insert" ] ]
1
[]
false
[]
false
pytest
true
[]
true
83486e54469aff0aee4de530a43fd4e4d7dca2f6
dd213e7aee9246b920a4268e682b30cc87ddad21
v1.0
instruct
Data_Structure
Data_Structure_22839_I
Here is a coding challenge based on the Diffie-Hellman key exchange and its mathematical underpinnings: ### Problem Statement Alice and Bob want to securely establish a shared secret key using the Diffie-Hellman key exchange protocol. However, the current system requires enhancement to include prime number validation...
import random from sympy import isprime def secure_diffie_hellman_key_exchange(a: int, p: int) -> int: """ Perform a secure Diffie-Hellman key exchange and return the shared secret key. :param a: The primitive root modulo p :param p: A prime number :return: The shared secret key or None if validati...
def test_secure_diffie_hellman_key_exchange(): # Valid test case assert isinstance(secure_diffie_hellman_key_exchange(5, 23), int) # Invalid prime number assert secure_diffie_hellman_key_exchange(5, 22) == None # Invalid primitive root assert secure_diffie_hellman_key_exchange(4, 23) =...
[ { "docstring": "Perform a secure Diffie-Hellman key exchange and return the shared secret key.\n:param a: The primitive root modulo p\n:param p: A prime number\n:return: The shared secret key or None if validation fails.", "function_declaration": "def secure_diffie_hellman_key_exchange(a, p):", "functio...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom sympy import isprime\n\ndef secure_diffie_hellman_key_exchange(a: int, p: int) -> int:\n \"\"\"\n Perform a secure Diffie-Hellman ke...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00022839", "row_id": 22839, "seed_ids": "[146]" }
0.479194
Data_Structure_22839
I
[ "secure_diffie_hellman_key_exchange", "is_primitive_root", "prime_factors" ]
3
[ [ "is_primitive_root", "prime_factors" ], [ "secure_diffie_hellman_key_exchange", "is_primitive_root" ] ]
2
[]
false
[]
false
pytest
false
[ "sympy" ]
false
b41be1f39e536542efb9138b0bd2851cc46e4f42
b98cf6e2bf37b3831ca79a825c33c3bc9c730941
v1.0
instruct
Data_Structure
Data_Structure_22841_I
### Scenario You are designing a system that performs prime number checks as a critical part of its operation, which is commonly used in cryptography and number theory applications. A highly efficient and correctly implemented prime-checking function is necessary to ensure the performance and reliability of your system...
from typing import List import math def is_prime(n: int) -> bool: """ Checks if a number is prime. Parameters: - n (int): The number to check. Returns: - bool: True if the number is prime, False otherwise. """ if n <= 1: return False if n == 2 or n == 3: re...
from solution import find_prime_numbers def test_basic_cases(): assert find_prime_numbers([10, 11, 12, 13, 14, 15]) == [11, 13] assert find_prime_numbers([1, 2, 3, 4, 5]) == [2, 3, 5] def test_empty_list(): assert find_prime_numbers([]) == [] def test_one_element_list(): assert find_prime_numbers([1]...
[ { "docstring": "Checks if a number is prime.\n\nParameters:\n- n (int): The number to check.\n\nReturns:\n- bool: True if the number is prime, False otherwise.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Finds and retu...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef is_prime(n: int) -> bool:\n \"\"\"\n Returns True if n is a prime number otherwise False.\n \"\"\"\n if n <= 1:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022841", "row_id": 22841, "seed_ids": "[143]" }
0.721197
Data_Structure_22841
I
[ "is_prime", "find_prime_numbers" ]
2
[ [ "find_prime_numbers", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
ae303996edfcf4792b626d6a85fd8267b887f39f
47c67f4b4af53e6cac16d34a0a2b1215685e5948
v1.0
instruct
Data_Structure
Data_Structure_22848_I
**Context**: A predictive text application uses Markov Chains to suggest the next word in a sentence given the current word. Each word (current state) transitions to the next word (next state) based on known probabilities derived from large data analysis. **Task**: Write a function `generate_sequence(chain, initial_st...
import random def normalize_probabilities(transitions): total = sum(transitions.values()) return {state: prob / total for state, prob in transitions.items()} def generate_sequence(chain: dict, initial_state: str, length: int) -> list: """ Generates a sequence of states based on the given Markov chain....
from solution import generate_sequence def test_generate_sequence_basic_case(): chain = {"A": {"A": 0.6, "B": 0.4}, "B": {"A": 0.5, "B": 0.5}} sequence = generate_sequence(chain, "A", 5) assert len(sequence) == 5 assert sequence[0] == "A" def test_generate_sequence_single_state(): chain = {"A": {"...
[ { "docstring": null, "function_declaration": "def normalize_probabilities(transitions):", "function_name": "normalize_probabilities", "parameter_list": "(transitions)" }, { "docstring": "Generates a sequence of states based on the given Markov chain.\n\nParameters:\n chain (dict): The Mar...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef normalize_probabilities(probabilities):\n total = sum(probabilities.values())\n return {state: prob / total for state, prob in prob...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022848", "row_id": 22848, "seed_ids": "[232]" }
0.549518
Data_Structure_22848
I
[ "normalize_probabilities", "generate_sequence" ]
2
[ [ "generate_sequence", "normalize_probabilities" ] ]
1
[]
false
[]
false
pytest
true
[]
true
43deacd21fae76520b7e3f5263bf4a4f511649ef
ea431cd0a27b50008d8768c6d9453473caee8a60
v1.0
instruct
Data_Structure
Data_Structure_22965_I
You are given a square matrix `mat` and an integer `exp`. Write a function `matrix_power(mat: List[List[int]], exp: int) -> List[List[int]]` that computes the matrix raised to the power `exp` using efficient matrix exponentiation. ### Function Signature: ```python def matrix_power(mat: List[List[int]], exp: int) -> Li...
from typing import List def matrix_multiply(A: List[List[int]], B: List[List[int]]) -> List[List[int]]: n = len(A) result = [[0] * n for _ in range(n)] for i in range(n): for j in range(n): for k in range(n): result[i][j] += A[i][k] * B[k][j] return result def matri...
from solution import matrix_power def test_matrix_power_example1(): mat = [ [1, 2], [3, 4] ] exp = 2 result = matrix_power(mat, exp) expected = [ [7, 10], [15, 22] ] assert result == expected def test_matrix_power_example2(): mat = [ [2, 0], ...
[ { "docstring": null, "function_declaration": "def matrix_multiply(A, B):", "function_name": "matrix_multiply", "parameter_list": "(A, B)" }, { "docstring": null, "function_declaration": "def matrix_identity(n):", "function_name": "matrix_identity", "parameter_list": "(n)" }, ...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def matrix_power(mat, exp):\n \"\"\"\n Computes the matrix `mat` raised to the power `exp` using efficient matrix exponentiation.\n\n Parameters:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00022965", "row_id": 22965, "seed_ids": "[340]" }
0.543265
Data_Structure_22965
I
[ "matrix_multiply", "matrix_identity", "matrix_power" ]
3
[ [ "matrix_power", "matrix_identity" ], [ "matrix_power", "matrix_multiply" ] ]
2
[]
false
[]
false
pytest
true
[]
true
fa3f4f4f7cdc886668ea0c15997d706f307c033a
9d409ae65bae58156297c29cd379d15bf632b024
v1.0
instruct
Data_Structure
Data_Structure_22979_I
**Heap Sort Analysis and Implementation** ### Context: You have been given functions `max_heap_sort` and `min_heap_sort` to sort an array in ascending order using max-heap and min-heap methodologies, respectively. Now, as an experienced programmer, you are required to analyze these implementations and adapt them to so...
from typing import List def heapify(arr: List[int], n: int, i: int, ascending: bool) -> None: if ascending: largest = i l = 2 * i + 1 r = 2 * i + 2 if l < n and arr[i] < arr[l]: largest = l if r < n and arr[largest] < arr[r]: largest = r if...
def test_heap_sort_ascending(): arr = [3, 1, 4, 1, 5, 9, 2, 6] assert heap_sort(arr, ascending=True) == [1, 1, 2, 3, 4, 5, 6, 9] def test_heap_sort_descending(): arr = [3, 1, 4, 1, 5, 9, 2, 6] assert heap_sort(arr, ascending=False) == [9, 6, 5, 4, 3, 2, 1, 1] def test_heap_sort_empty(): assert hea...
[ { "docstring": null, "function_declaration": "def heapify(arr, n, i, ascending):", "function_name": "heapify", "parameter_list": "(arr, n, i, ascending)" }, { "docstring": null, "function_declaration": "def heap_sort(arr, ascending=True):", "function_name": "heap_sort", "paramete...
[ 0, 0, 0, 1, 1, 1, 0, 0, 0, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef heap_sort(arr: List[int], ascending: bool = True) -> List[int]:\n \"\"\"\n Sorts the array using heap sort algorithm in e...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00022979", "row_id": 22979, "seed_ids": "[8]" }
0.729646
Data_Structure_22979
I
[ "heapify", "heap_sort" ]
2
[ [ "heap_sort", "heapify" ] ]
1
[]
false
[]
false
pytest
false
[]
true
f862ebc99c06e7d7bb19a38850a53af8d875b2a1
040c8df0427a6cbc6d321e91079e8d618f996b14
v1.0
instruct
Data_Structure
Data_Structure_22993_I
### Maximum Flow Optimization Challenge You are provided with a flow network consisting of `n` vertices. Each vertex is represented as an integer from `0` to `n-1`, where vertex `0` is the source and vertex `n-1` is the sink. The network can be described by an adjacency matrix `capacity`, where `capacity[i][j]` repres...
from collections import deque def bfs(source, sink, parent, n, residual_capacity): # Perform BFS from source to sink and store the path in the parent array visited = [False] * n queue = deque([source]) visited[source] = True while queue: u = queue.popleft() for v in ra...
from solution import ford_fulkerson def test_max_flow_example1(): n = 4 capacity = [ [0, 1000, 1000, 0], [0, 0, 1, 1000], [0, 0, 0, 1000], [0, 0, 0, 0] ] assert ford_fulkerson(n, capacity) == 2000 def test_max_flow_zero_capacity(): n = 3 capacity = [ [0,...
[ { "docstring": null, "function_declaration": "def bfs(source, sink, parent, n, residual_capacity):", "function_name": "bfs", "parameter_list": "(source, sink, parent, n, residual_capacity)" }, { "docstring": null, "function_declaration": "def ford_fulkerson(n, capacity):", "function_...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef bfs(capacity, source, sink, parent):\n visited = [False] * len(capacity)\n queue = deque([source])\n visited[sou...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00022993", "row_id": 22993, "seed_ids": "[240]" }
0.63185
Data_Structure_22993
I
[ "bfs", "ford_fulkerson" ]
2
[ [ "ford_fulkerson", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
0949f0384c4441734752a0e15e665c64d0bd3420
fe435793014af327bd4917748e547ea158212485
v1.0
instruct
Data_Structure
Data_Structure_23027_I
Diffie-Hellman Key Exchange Enhancements **Context**: The Diffie-Hellman key exchange algorithm enables two parties to securely exchange cryptographic keys over a public channel. Your task is to enhance the current implementation by adding input validation, error handling, and key length flexibility. ### Task 1. Imp...
import random from sympy import isprime, primerange def validate_inputs(a, p): """ Validate the inputs `a` and `p` for the Diffie-Hellman key exchange. """ if not (isinstance(a, int) and a > 0): raise ValueError("Primitive root 'a' must be a positive integer.") if not (isinstance(p, int) an...
from solution import validate_inputs, generate_large_prime, diffie_hellman_key_exchange import pytest def test_validate_inputs_valid(): validate_inputs(2, 23) validate_inputs(5, 101) def test_validate_inputs_invalid_primitive_root(): with pytest.raises(ValueError, match="Primitive root 'a' must be a posit...
[ { "docstring": "Validate the inputs `a` and `p` for the Diffie-Hellman key exchange.", "function_declaration": "def validate_inputs(a, p):", "function_name": "validate_inputs", "parameter_list": "(a, p)" }, { "docstring": "Generate a large prime number of the specified bit length.", "fun...
[ 0, 1, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from sympy import isprime, primerange, primitive_root, randprime\nimport random\n\ndef validate_inputs(a, p):\n \"\"\"\n Validates that `a` is a primiti...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00023027", "row_id": 23027, "seed_ids": "[146]" }
0.521163
Data_Structure_23027
I
[ "validate_inputs", "generate_large_prime", "diffie_hellman_key_exchange" ]
3
[ [ "diffie_hellman_key_exchange", "generate_large_prime" ], [ "diffie_hellman_key_exchange", "validate_inputs" ] ]
2
[]
false
[]
false
pytest
true
[ "sympy" ]
false
a0733cce4fbf10eb1a21132854de4c0d861e8032
8e1133b9edc1a288827185ac600b62b0cea244ba
v1.0
instruct
Data_Structure
Data_Structure_23046_I
<|Analysis Begin|> ### Algorithm/Data Structure: * **Name**: Deletion in a Binary Search Tree (BST) * **Type**: Data Structure / Tree Algorithms * **Main Purpose**: This algorithm is used to delete a node from a Binary Search Tree (BST) while maintaining its properties. ### Complexity: * **Time Complexity**: O(h), ...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def delete_node(root: TreeNode, key: int) -> TreeNode: if not root: return root if key < root.val: root.left = delete_node(root.left, key) el...
import pytest def tree_to_list(root: TreeNode): """Helper function to convert tree to list for easy verification.""" if not root: return [] result = [] queue = [root] while queue: node = queue.pop(0) if node: result.append(node.val) queue.append(node....
[]
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef de...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023046", "row_id": 23046, "seed_ids": "[331]" }
0.581393
Data_Structure_23046
I
[ "delete_node", "find_min" ]
2
[ [ "delete_node", "find_min" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
false
[]
true
464ac7acacaf416ebb007877b9220d711b7244a7
74f081898de784af823a4bae3326c541f8343b32
v1.0
instruct
Data_Structure
Data_Structure_23047_I
You are given two implementations of the binary exponentiation algorithm – one iterative and one recursive. Implement a function `modular_exponentiation` that calculates \(a^n \mod \, mod\) using the provided power functions and compare the outputs for correctness. The function should take three parameters: two integer...
def iterative_power(a, n, mod=None): result = 1 base = a if mod is None else a % mod while n > 0: if n % 2 == 1: # If n is odd, multiply the current base to the result result = result * base if mod is None else (result * base) % mod base = base * base if mod is None else (base *...
from solution import modular_exponentiation def test_small_numbers(): assert modular_exponentiation(2, 10) == (1024, 1024) assert modular_exponentiation(3, 0) == (1, 1) def test_large_numbers(): a, n, mod = 2, 1000000000, 1000000007 result_iter, result_recur = modular_exponentiation(a, n, mod) ass...
[ { "docstring": null, "function_declaration": "def iterative_power(a, n, mod=None):", "function_name": "iterative_power", "parameter_list": "(a, n, mod=None)" }, { "docstring": null, "function_declaration": "def recursive_power(a, n, mod=None):", "function_name": "recursive_power", ...
[ 0, 0, 0, 0, 1, 0, 1, 0, 1, 0 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def iterative_power(a, n, mod=None):\n \"\"\"\n Iterative implementation of binary exponentiation.\n \"\"\"\n result = 1\n base = a if mod is N...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00023047", "row_id": 23047, "seed_ids": "[151]" }
0.653649
Data_Structure_23047
I
[ "iterative_power", "recursive_power", "modular_exponentiation" ]
3
[ [ "modular_exponentiation", "iterative_power" ], [ "modular_exponentiation", "recursive_power" ] ]
2
[]
false
[]
false
pytest
true
[]
true
f33f9c9adbf00f8a261f4ef5f8e67c88b76a5680
5c530b478b1ef325d64ae1945a54de24acab0985
v1.0
instruct
Data_Structure
Data_Structure_23074_I
**Task**: Implement a k-largest element finder using the max heap implementation of Heap Sort. **Objective**: Use Heap Sort with a max heap to find and return the k-largest elements of a given list. **Input/Output Formats**: * **Input**: * An array of integers `arr`. * An integer `k`. * **Output**: * A sorted...
def heapify(arr, n, i): """ Helper function to maintain the max heap property. """ largest = i # Initialize largest as root left = 2 * i + 1 # left child right = 2 * i + 2 # right child # If left child is larger than root if left < n and arr[left] > arr[largest]: larges...
from solution import k_largest_elements def test_k_largest_elements_basic(): assert k_largest_elements([3, 2, 1, 5, 6, 4], 2) == [6, 5] assert k_largest_elements([1, 2, 3, 4, 5, 6], 1) == [6] def test_k_largest_elements_large_k(): assert k_largest_elements([3, 2, 3, 1, 2, 4, 5, 5, 6], 4) == [6, 5, 5, 4] ...
[ { "docstring": "Helper function to maintain the max heap property.", "function_declaration": "def heapify(arr, n, i):", "function_name": "heapify", "parameter_list": "(arr, n, i)" }, { "docstring": "Main function to perform heap sort.", "function_declaration": "def heap_sort(arr):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\n\ndef find_k_largest_elements(arr, k):\n \"\"\"\n Returns the k-largest elements in arr in descending order using a max heap.\n \n P...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023074", "row_id": 23074, "seed_ids": "[8]" }
0.718766
Data_Structure_23074
I
[ "heapify", "heap_sort", "k_largest_elements" ]
3
[ [ "heap_sort", "heapify" ], [ "k_largest_elements", "heap_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
3690615e8cf9ebe807d63e00db9fd399b530bb95
478abc62ac75871a3f04943eb016c24289eb9e0c
v1.0
instruct
Data_Structure
Data_Structure_23110_I
You are given an array of non-negative integers. Your task is to implement a function `enhanced_bucket_sort(arr: List[int]) -> List[int]` that sorts the input array using the bucket sort mechanism provided in the below description. #### Function Signature The function should have the following signature: ```python fro...
from typing import List def insertion_sort(bucket: List[int]) -> List[int]: """ Helper function to perform insertion sort on a bucket. """ for i in range(1, len(bucket)): key = bucket[i] j = i - 1 while j >= 0 and key < bucket[j]: bucket[j + 1] = bucket[j] ...
from solution import enhanced_bucket_sort def test_enhanced_bucket_sort_empty(): assert enhanced_bucket_sort([]) == [] def test_enhanced_bucket_sort_single_element(): assert enhanced_bucket_sort([5]) == [5] def test_enhanced_bucket_sort_all_elements_same(): assert enhanced_bucket_sort([2, 2, 2, 2]) == [2...
[ { "docstring": "Helper function to perform insertion sort on a bucket.", "function_declaration": "def insertion_sort(bucket):", "function_name": "insertion_sort", "parameter_list": "(bucket)" }, { "docstring": null, "function_declaration": "def enhanced_bucket_sort(arr):", "function_...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef enhanced_bucket_sort(arr: List[int]) -> List[int]:\n if not arr:\n return [] # Edge case: empty input list\n \n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023110", "row_id": 23110, "seed_ids": "[26]" }
0.652
Data_Structure_23110
I
[ "insertion_sort", "enhanced_bucket_sort" ]
2
[ [ "enhanced_bucket_sort", "insertion_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fbb6db6c784749a408bc9f026be23cc31fbfa09f
d50253f7c0221966219175102c005c4d3d189924
v1.0
instruct
Data_Structure
Data_Structure_23128_I
### RSA Key Generation and Encryption/Decryption **Objective**: Implement RSA key generation, encryption, and decryption algorithms to understand asymmetric cryptographic systems. ### Problem Statement: You are asked to implement the RSA key generation algorithm and then write functions for encrypting and decrypting ...
import random from sympy import isprime, mod_inverse def generate_prime_candidate(length): """ Generate an odd integer randomly. """ p = random.getrandbits(length) # Apply a mask to set MSB and LSB to 1 p |= (1 << length - 1) | 1 return p def generate_prime_number(length): """ Gene...
from solution import generate_key, encrypt, decrypt def test_key_generation(): n, e, d = generate_key(16) assert isinstance(n, int) assert isinstance(e, int) assert isinstance(d, int) assert e == 65537 def test_encryption_decryption(): n, e, d = generate_key(16) data = 42 encrypted = e...
[ { "docstring": "Generate an odd integer randomly.", "function_declaration": "def generate_prime_candidate(length):", "function_name": "generate_prime_candidate", "parameter_list": "(length)" }, { "docstring": "Generate a prime number of the specified bit length.", "function_declaration":...
[ 0, 0, 0, 1, 0, 1, 0, 0, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom sympy import randprime\n\ndef generate_key(k):\n \"\"\"\n Generates an RSA public/private key pair.\n \n Parameters:\n ...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00023128", "row_id": 23128, "seed_ids": "[154]" }
0.608606
Data_Structure_23128
I
[ "generate_prime_candidate", "generate_prime_number", "generate_key", "encrypt", "decrypt" ]
5
[ [ "generate_key", "generate_prime_number" ], [ "generate_prime_number", "generate_prime_candidate" ] ]
2
[]
false
[]
false
pytest
true
[ "sympy" ]
false
48dff7b16d9c80a34f98dd0c844c2c70ca804739
c4a9f9eb5f6e02a7a5672efa13ea17350fe9b959
v1.0
instruct
Data_Structure
Data_Structure_23130_I
Given an array of integers, implement both Max Heap Sort and Min Heap Sort to sort the array in ascending order. You need to showcase your understanding by implementing the sorting algorithms and analyzing their performance. Implement two functions: 1. `max_heap_sort(arr: List[int], simulation: bool = False) -> List[i...
def max_heapify(arr, n, i, simulation=False): largest = i left = 2 * i + 1 right = 2 * i + 2 if left < n and arr[left] > arr[largest]: largest = left if right < n and arr[right] > arr[largest]: largest = right if largest != i: arr[i], arr[largest] = arr[lar...
from solution import max_heap_sort, min_heap_sort def test_max_heap_sort_empty(): assert max_heap_sort([]) == [] def test_max_heap_sort_single_element(): assert max_heap_sort([1]) == [1] def test_max_heap_sort_multiple_elements(): arr = [4, 10, 3, 5, 1] assert max_heap_sort(arr) == [1, 3, 4, 5, 10] ...
[ { "docstring": null, "function_declaration": "def max_heapify(arr, n, i, simulation=False):", "function_name": "max_heapify", "parameter_list": "(arr, n, i, simulation=False)" }, { "docstring": null, "function_declaration": "def max_heap_sort(arr, simulation=False):", "function_name"...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def max_heapify(arr, n, i, simulation):\n largest = i\n left = 2 * i + 1\n right = 2 * i + 2\n \n if left < n and arr[left] > arr[largest]:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023130", "row_id": 23130, "seed_ids": "[8]" }
0.65398
Data_Structure_23130
I
[ "max_heapify", "max_heap_sort", "min_heapify", "min_heap_sort" ]
4
[ [ "max_heap_sort", "max_heapify" ], [ "min_heap_sort", "min_heapify" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e0596d34b4fde165ac89f304707b8cc9fd452d25
c6784473e403faf0336b724709099742f48724a6
v1.0
instruct
Data_Structure
Data_Structure_23180_I
### Prime Check Algorithm Assessment **Objective**: You are tasked with verifying the primality of a sequence of numbers efficiently using an optimized prime-check algorithm. **Task**: Write a function `batch_prime_check` that takes a list of integers and returns a list of True/False values indicating if the corre...
def is_prime(n): if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 return True def batch_prime_check(numbers): """ Ch...
from solution import batch_prime_check def test_basic_primes(): assert batch_prime_check([2, 3, 5, 7, 11, 13, 17, 19]) == [True, True, True, True, True, True, True, True] def test_non_primes(): assert batch_prime_check([1, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20]) == [False, False, False, False, False, False, ...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Check primality of multiple numbers.\n\nParameters:\nnumbers (list): A list of integers to check for primality.\n\nReturns:\nlist: A list of boolean values...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"\n Check if a number is prime.\n \"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023180", "row_id": 23180, "seed_ids": "[143]" }
0.666251
Data_Structure_23180
I
[ "is_prime", "batch_prime_check" ]
2
[ [ "batch_prime_check", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
d4e343d121909d258a5d45cc54c897b6acab561f
e755f61693cdad567657d5d35492843ab26150cf
v1.0
instruct
Data_Structure
Data_Structure_23194_I
### Question: Implementing and Optimizing In-Order Traversal You are provided with a binary tree. Your task is to implement the in-order traversal for this tree. You need to complete two versions of the traversal: an iterative approach and a recursive approach. Also, you need to implement an additional function that w...
class Node: def __init__(self, val, left=None, right=None): self.val = val self.left = left self.right = right def inorder_iterative(root): """ Iterative In-Order Traversal """ res = [] stack = [] while root or stack: while root: stack.append(root) ...
from solution import Node, inorder_iterative, inorder_recursive, compare_traversals def test_inorder_traversal(): # Construct a test binary tree """ 1 / \ 2 3 / \ \ 4 5 6 """ n1 = Node(1) n2 = Node(2) n3 = Node(3) n4 = Node(4) n5 = No...
[]
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "class Node:\n def __init__(self, val, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef inorder_...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023194", "row_id": 23194, "seed_ids": "[310]" }
0.597134
Data_Structure_23194
I
[ "inorder_iterative", "inorder_recursive", "compare_traversals" ]
3
[ [ "compare_traversals", "inorder_iterative" ], [ "compare_traversals", "inorder_recursive" ] ]
2
[]
false
[ "Node" ]
true
pytest
true
[]
true
c29bacf00ef515383e204c2423a4ab20d284ae85
0b0f86b5047fcc900bbd83512ba694a67677ccfe
v1.0
instruct
Data_Structure
Data_Structure_23197_I
You are tasked with enhancing and fully implementing the RSA encryption system described below. Your enhancements should focus on: 1. Improving the efficiency of prime number generation. 2. Optimizing the calculation of the modular inverse. ### Task **Part 1: Efficient Prime Generation** Implement a more efficient v...
import random # Miller-Rabin Primality Test def is_prime(n, k=40): """ Test if a number is a prime """ if n == 2 or n == 3: return True if n <= 1 or n % 2 == 0: return False # Write (n - 1) as 2^s * d s, d = 0, n - 1 while d % 2 == 0: s += 1 d //= 2 # Witness...
from solution import gen_prime, modinv def test_gen_prime(): prime1 = gen_prime(16, seed=42) prime2 = gen_prime(16, seed=42) assert prime1 == prime2, f"Expected {prime1} to be equal to {prime2}" assert is_prime(prime1), f"Expected {prime1} to be prime" prime3 = gen_prime(512) assert is_pri...
[ { "docstring": "Test if a number is a prime ", "function_declaration": "def is_prime(n, k=40):", "function_name": "is_prime", "parameter_list": "(n, k=40)" }, { "docstring": "Generate a k-bit prime number ", "function_declaration": "def gen_prime(k, seed=None):", "function_name": "ge...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\n\ndef miller_rabin_primality_test(n, k=5):\n \"\"\"Miller-Rabin primality test to check if a number is prime.\"\"\"\n if n <= 1:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023197", "row_id": 23197, "seed_ids": "[154]" }
0.546181
Data_Structure_23197
I
[ "is_prime", "gen_prime", "modinv" ]
3
[ [ "gen_prime", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fc2a07abe02b7bdcf32fe283fd3622722b78fe38
34b03a0ea56abf3fe6c94312170c29a4b752d592
v1.0
instruct
Data_Structure
Data_Structure_23282_I
You need to implement a function that combines the concepts of GCD using Euclid's algorithm and counting the number of trailing zeros using bitwise operations. Given two non-negative integers, your task is to: 1. Compute their greatest common divisor (GCD) using bitwise operations. 2. Compute the least common multiple...
def gcd_lcm_trailing_zeros(a: int, b: int) -> (int, int, int): """ Computes the GCD using bitwise operations, LCM, and the number of trailing zeros in the LCM. Parameters: a (int): First non-negative integer. b (int): Second non-negative integer. Returns: (int, int, int): Tuple con...
def test_gcd_lcm_trailing_zeros(): assert gcd_lcm_trailing_zeros(12, 18) == (6, 36, 2) assert gcd_lcm_trailing_zeros(0, 5) == (5, 5, 0) assert gcd_lcm_trailing_zeros(10, 15) == (5, 30, 1) assert gcd_lcm_trailing_zeros(0, 0) == (0, 0, 0) assert gcd_lcm_trailing_zeros(7, 0) == (7, 7, 0) assert gcd...
[ { "docstring": "Computes the GCD using bitwise operations, LCM, and the number of trailing zeros in the LCM.\n\nParameters:\na (int): First non-negative integer.\nb (int): Second non-negative integer.\n\nReturns:\n(int, int, int): Tuple containing the GCD, LCM, and the number of trailing zeros in LCM.", "fu...
[ 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def gcd_lcm_trailing_zeros(a: int, b: int) -> (int, int, int):\n def gcd(x, y):\n if x == 0:\n return y\n if y == 0:\n ...
trial_gpt4o_4
{ "original_instruction": "", "prompt_id": "00023282", "row_id": 23282, "seed_ids": "[166]" }
0.641846
Data_Structure_23282
I
[ "gcd_lcm_trailing_zeros", "trailing_zeros" ]
2
[ [ "gcd_lcm_trailing_zeros", "trailing_zeros" ] ]
1
[]
false
[]
false
pytest
false
[]
true
31c116659743e39ae6aade1217ee4fb0cc0c3ddc
bb847088e2f66d896dc05d83af1cabb7b21bf029
v1.0
instruct
Data_Structure
Data_Structure_23356_I
### Context You are tasked with creating a library for handling various arithmetic operations needed in a number theory module. One of the crucial operations is to compute the Least Common Multiple (LCM) of multiple integers. Given that the LCM of two numbers can be derived from their Greatest Common Divisor (GCD), you...
from typing import List def trailing_zero(x): count = 0 while x and not x & 1: count += 1 x >>= 1 return count def gcd_bit(a, b): if a == 0: return b if b == 0: return a tza = trailing_zero(a) tzb = trailing_zero(b) a >>= tza b >>= tzb while b: ...
from solution import multi_lcm def test_single_element(): assert multi_lcm([5]) == 5 assert multi_lcm([0]) == 0 def test_two_elements(): assert multi_lcm([4, 6]) == 12 assert multi_lcm([7, 3]) == 21 def test_multiple_elements(): assert multi_lcm([4, 6, 8]) == 24 assert multi_lcm([5, 10, 20]) ...
[ { "docstring": null, "function_declaration": "def trailing_zero(x):", "function_name": "trailing_zero", "parameter_list": "(x)" }, { "docstring": null, "function_declaration": "def gcd_bit(a, b):", "function_name": "gcd_bit", "parameter_list": "(a, b)" }, { "docstring": n...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef trailing_zero(x: int) -> int:\n count = 0\n while x and not x & 1:\n count += 1\n x >>= 1\n return count...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023356", "row_id": 23356, "seed_ids": "[166]" }
0.66906
Data_Structure_23356
I
[ "trailing_zero", "gcd_bit", "multi_lcm" ]
3
[ [ "gcd_bit", "trailing_zero" ], [ "multi_lcm", "gcd_bit" ] ]
2
[]
false
[]
false
pytest
true
[]
true
a82dda6228e173f234f385dfb43257673b8c0c8f
52730e07eda740f2cda09621c6aa4f44110eb4e8
v1.0
instruct
Data_Structure
Data_Structure_23365_I
### Question You are given a text string and a pattern string. Using the Knuth-Morris-Pratt (KMP) algorithm, find all starting positions in the text where the pattern is found as a substring. #### Function Signature ```python def find_pattern_occurrences(text: str, pattern: str) -> List[int]: ``` #### Input * `text`...
from typing import List def compute_pi(pattern: str) -> List[int]: pi = [0] * len(pattern) j = 0 for i in range(1, len(pattern)): while (j > 0 and pattern[i] != pattern[j]): j = pi[j - 1] if pattern[i] == pattern[j]: j += 1 pi[i] = j return pi def find_p...
from solution import find_pattern_occurrences def test_empty_text(): assert find_pattern_occurrences('', 'pattern') == [] def test_empty_pattern(): assert find_pattern_occurrences('text', '') == [] def test_no_occurrences(): assert find_pattern_occurrences('this is a test', 'pattern') == [] def test_sin...
[ { "docstring": null, "function_declaration": "def compute_pi(pattern):", "function_name": "compute_pi", "parameter_list": "(pattern)" }, { "docstring": null, "function_declaration": "def find_pattern_occurrences(text, pattern):", "function_name": "find_pattern_occurrences", "para...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef compute_prefix_function(pattern: str) -> List[int]:\n m = len(pattern)\n pi = [0] * m\n j = 0\n for i in range(1, m...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023365", "row_id": 23365, "seed_ids": "[93]" }
0.592193
Data_Structure_23365
I
[ "compute_pi", "find_pattern_occurrences" ]
2
[ [ "find_pattern_occurrences", "compute_pi" ] ]
1
[]
false
[]
false
pytest
true
[]
true
3fdab48f664dd2e04e5f82fd47ec7e37e2da4506
816091ed73c40fe0e316313a1ca63e8d6f52a02d
v1.0
instruct
Data_Structure
Data_Structure_23371_I
#### Context You are given two sorting algorithms: Max Heap Sort and Min Heap Sort. These algorithms sort an array using heap structures (max heap and min heap respectively). Your task is to implement a new variant of heap sort called "Min-Max Heap Sort" that combines elements of both max heap and min heap. ### Task #...
def heapify(arr, n, i, is_max_heap): largest_or_smallest = i left = 2 * i + 1 right = 2 * i + 2 if is_max_heap: if left < n and arr[i] < arr[left]: largest_or_smallest = left if right < n and arr[largest_or_smallest] < arr[right]: largest_or_smallest = right ...
from solution import min_max_heap_sort def test_min_max_heap_sort_standard(): arr = [14, 3, 2, 8, 15, 17, 9] result = min_max_heap_sort(arr) assert result == [2, 3, 8, 9, 14, 15, 17] def test_min_max_heap_sort_empty(): arr = [] result = min_max_heap_sort(arr) assert result == [] def test_min_...
[ { "docstring": null, "function_declaration": "def heapify(arr, n, i, is_max_heap):", "function_name": "heapify", "parameter_list": "(arr, n, i, is_max_heap)" }, { "docstring": null, "function_declaration": "def build_heap(arr, n, is_max_heap):", "function_name": "build_heap", "pa...
[ 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def heapify(arr, n, i, max_heap=True):\n largest_or_smallest = i\n left = 2 * i + 1\n right = 2 * i + 2\n\n if max_heap:\n if left < n and ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00023371", "row_id": 23371, "seed_ids": "[8]" }
0.658316
Data_Structure_23371
I
[ "heapify", "build_heap", "min_max_heap_sort" ]
3
[ [ "build_heap", "heapify" ], [ "min_max_heap_sort", "build_heap" ] ]
2
[]
false
[]
false
pytest
true
[]
true
43b83a0bdf34eb93f077d88449fbd36bd2298ec7
baa6eabed04eaa230f5a1fbc8899f3cbeb46e145
v1.0
instruct
Data_Structure
Data_Structure_23387_I
### Matrix Exponentiation - Fast Fibonacci Computation **Objective**: Implement a function that uses matrix exponentiation to compute large Fibonacci numbers efficiently. **Description**: The Fibonacci sequence is defined as: - F(0) = 0 - F(1) = 1 - F(n) = F(n-1) + F(n-2) for n > 1 Matrix representation can be utili...
def matrix_multiply(A, B): """ Multiplies two 2x2 matrices A and B. """ return [ [A[0][0] * B[0][0] + A[0][1] * B[1][0], A[0][0] * B[0][1] + A[0][1] * B[1][1]], [A[1][0] * B[0][0] + A[1][1] * B[1][0], A[1][0] * B[0][1] + A[1][1] * B[1][1]] ] def matrix_exponentiation(matrix, power):...
from solution import fast_fibonacci def test_fast_fibonacci_base_cases(): assert fast_fibonacci(0) == 0 assert fast_fibonacci(1) == 1 def test_fast_fibonacci_small_numbers(): assert fast_fibonacci(2) == 1 assert fast_fibonacci(3) == 2 assert fast_fibonacci(4) == 3 assert fast_fibonacci(5) == 5...
[ { "docstring": "Multiplies two 2x2 matrices A and B.", "function_declaration": "def matrix_multiply(A, B):", "function_name": "matrix_multiply", "parameter_list": "(A, B)" }, { "docstring": "Raises the 2x2 matrix to the given power using exponentiation by squaring.", "function_declaratio...
[ 1, 1, 0 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def multiply_matrices(A, B):\n \"\"\"Multiplies two 2x2 matrices A and B.\"\"\"\n return [\n [\n A[0][0] * B[0][0] + A[0][1] * B[1][0]...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00023387", "row_id": 23387, "seed_ids": "[340]" }
0.683882
Data_Structure_23387
I
[ "matrix_multiply", "matrix_exponentiation", "fast_fibonacci" ]
3
[ [ "fast_fibonacci", "matrix_exponentiation" ], [ "matrix_exponentiation", "matrix_multiply" ] ]
2
[]
false
[]
false
pytest
true
[]
true
30d2e357d2ca61b0f22f61a355c279bc17869177
f6d8df2c642ddec24151927b7c8e67c21521ba48
v1.0
instruct
Data_Structure
Data_Structure_23395_I
### Problem: Advanced Elias Coding Algorithm Given the definitions and understanding of Elias Gamma and Elias Delta codings, your task is to implement a more advanced version of these codings that includes both encoding and decoding of positive integers. This added feature should be able to verify the correctness of t...
def elias_gamma_encode(x: int) -> str: """Encodes an integer x using Elias Gamma coding.""" if x <= 0: raise ValueError("Elias Gamma encoding is only defined for positive integers.") binary_representation = bin(x)[2:] # Get the binary representation of x without '0b' prefix n = len(binary_...
from solution import elias_gamma_encode, elias_gamma_decode, elias_delta_encode, elias_delta_decode def test_elias_gamma_encoding_decoding(): for x in range(1, 100): encoded = elias_gamma_encode(x) decoded = elias_gamma_decode(encoded) assert decoded == x, f"Failed for x={x}, encoded={encod...
[ { "docstring": "Encodes an integer x using Elias Gamma coding.", "function_declaration": "def elias_gamma_encode(x):", "function_name": "elias_gamma_encode", "parameter_list": "(x)" }, { "docstring": "Decodes a binary string encoded using Elias Gamma coding back to the integer.", "functi...
[ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def elias_gamma_encode(x: int) -> str:\n \"\"\"\n Encodes an integer x using Elias Gamma coding.\n \"\"\"\n if x <= 0:\n raise ValueError(\...
trial_gpt4o_5
{ "original_instruction": "", "prompt_id": "00023395", "row_id": 23395, "seed_ids": "[333]" }
0.51992
Data_Structure_23395
I
[ "elias_gamma_encode", "elias_gamma_decode", "elias_delta_encode", "elias_delta_decode" ]
4
[ [ "elias_delta_decode", "elias_gamma_decode" ], [ "elias_delta_encode", "elias_gamma_encode" ] ]
2
[]
false
[]
false
pytest
true
[]
true
de4e25c6f0cd9b9edc5b82d31d2bc913672002e6
afb7785fba96f5d874358efef556e5b6128a71f4
v1.0
instruct
Data_Structure
Data_Structure_23473_I
### RSA Encryption Algorithm You are required to implement a secure message exchange system using the RSA encryption algorithm. The system should allow the generation of public and private keys, encryption of messages using the public key, and decryption of messages using the corresponding private key. ### Requirement...
import random from sympy import isprime, mod_inverse def generate_large_prime(bits): while True: prime_candidate = random.getrandbits(bits) if isprime(prime_candidate): return prime_candidate def generate_key(k, seed=None): if seed is not None: random.seed(seed) p ...
from solution import generate_key, encrypt, decrypt def test_generate_key_deterministic(): n1, e1, d1 = generate_key(16, seed=42) n2, e2, d2 = generate_key(16, seed=42) assert n1 == n2 assert e1 == e2 assert d1 == d2 def test_encrypt_decrypt_small_message(): n, e, d = generate_key(16) mess...
[ { "docstring": null, "function_declaration": "def generate_large_prime(bits):", "function_name": "generate_large_prime", "parameter_list": "(bits)" }, { "docstring": null, "function_declaration": "def generate_key(k, seed=None):", "function_name": "generate_key", "parameter_list"...
[ 0, 0, 0, 0, 1, 0, 0, 1, 0, 0 ]
2
hard
0.2
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom Crypto.Util import number\n\ndef generate_key(k, seed=None):\n \"\"\"\n Generates RSA public and private key components.\n \n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00023473", "row_id": 23473, "seed_ids": "[154]" }
0.563928
Data_Structure_23473
I
[ "generate_large_prime", "generate_key", "encrypt", "decrypt" ]
4
[ [ "generate_key", "generate_large_prime" ] ]
1
[]
false
[]
false
pytest
true
[ "sympy" ]
false
12335a1500f8c7562e034902c68e87fed68b7469
6c265aadfe51e449144860412e001cd9cd544f4b
v1.0
instruct
Data_Structure
Data_Structure_23476_I
### Invert a Matrix **Objective**: Implement a function to find the inverse of an \( n \times n \) matrix, given the matrix is invertible (i.e., it has a non-zero determinant). **Function Signature**: ```python def invert_matrix(matrix: List[List[float]]) -> List[List[float]]: ``` **Instructions**: 1. The function s...
from typing import List def get_determinant(matrix: List[List[float]]) -> float: """Compute the determinant of a square matrix.""" n = len(matrix) if n == 1: return matrix[0][0] if n == 2: return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0] determinant = ...
from solution import invert_matrix def test_invert_2x2_matrix(): matrix = [ [4, 7], [2, 6] ] expected = [ [0.6, -0.7], [-0.2, 0.4] ] result = invert_matrix(matrix) for r, e in zip(result, expected): assert all(abs(x - y) < 1e-9 for x, y in zip(r, e)) def...
[ { "docstring": "Compute the determinant of a square matrix.", "function_declaration": "def get_determinant(matrix):", "function_name": "get_determinant", "parameter_list": "(matrix)" }, { "docstring": "Get the minor of a matrix excluding the specified row and column.", "function_declarat...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\nclass MatrixError(Exception):\n \"\"\"Exception raised for errors in the input matrix.\"\"\"\n def __init__(self, message):\n...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00023476", "row_id": 23476, "seed_ids": "[347]" }
0.552348
Data_Structure_23476
I
[ "get_determinant", "get_minor", "get_matrix_of_minors", "transpose", "get_cofactor_matrix", "invert_matrix" ]
6
[ [ "get_cofactor_matrix", "get_matrix_of_minors" ], [ "get_determinant", "get_minor" ], [ "get_matrix_of_minors", "get_determinant" ], [ "get_matrix_of_minors", "get_minor" ], [ "invert_matrix", "get_cofactor_matrix" ], [ "invert_matrix", "get_deter...
7
[]
false
[]
false
pytest
true
[]
true
9b909409da39d7e1cf50b298e53b9aae30825783
2ef5481dad78c920c5a0628e4905d75dd2641e87
v1.0
instruct
Data_Structure
Data_Structure_23513_I
### Radix Sorting Implementation and Analysis #### Scenario You are tasked with implementing the radix sort algorithm to sort a list of non-negative integers in increasing order. Your implementation should handle typical edge cases and provide a detailed examination of the algorithm's process. #### Task Write a funct...
def counting_sort_for_radix(arr, exp): """ A helper function to perform counting sort on arr based on the digit represented by exp. Args: arr (List[int]): List of non-negative integers to sort. exp (int): The digit position to sort by. Returns: List[int]: Partially sorted list. ...
from solution import perform_radix_sort def test_perform_radix_sort_basic(): assert perform_radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) == [2, 24, 45, 66, 75, 90, 170, 802] def test_perform_radix_sort_single_element(): assert perform_radix_sort([5]) == [5] def test_perform_radix_sort_same_elements(): a...
[ { "docstring": "A helper function to perform counting sort on arr based on the digit represented by exp.\n\nArgs:\narr (List[int]): List of non-negative integers to sort.\nexp (int): The digit position to sort by.\n\nReturns:\nList[int]: Partially sorted list.", "function_declaration": "def counting_sort_fo...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def perform_radix_sort(arr):\n \"\"\"\n Implement radix sort to arrange arr in ascending order.\n \n Args:\n arr (List[int]): List of non-negat...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023513", "row_id": 23513, "seed_ids": "[15]" }
0.68529
Data_Structure_23513
I
[ "counting_sort_for_radix", "perform_radix_sort" ]
2
[ [ "perform_radix_sort", "counting_sort_for_radix" ] ]
1
[]
false
[]
false
pytest
true
[]
true
7b0ab5e09a65d769222becdcc487cbe375a336f2
2f17f7450089bb9b66701622c952f8b02f13ffad
v1.0
instruct
Data_Structure
Data_Structure_23584_I
#### Context You have been hired to work on a spatial analysis tool. One of the primary functions of this tool is to identify the k points that are closest to a given origin. Your task is to write a function that efficiently finds these k closest points. #### Task Implement a function `k_closest(points, k, origin=(0, ...
import heapq from typing import List, Tuple def squared_distance(point: Tuple[int, int], origin: Tuple[int, int]) -> int: """ Calculate the squared Euclidean distance between a point and the origin. """ return (point[0] - origin[0])**2 + (point[1] - origin[1])**2 def k_closest(points: List[Tuple[int, ...
from solution import k_closest def test_k_closest_with_positive_points(): points = [(1, 2), (3, 4), (-1, -2), (2, 2)] k = 2 origin = (0, 0) result = k_closest(points, k, origin) assert set(result) == set([(1, 2), (2, 2)]) or set(result) == set([(1, 2), (-1, -2)]) or set(result) == set([(2, 2), (-1,...
[ { "docstring": "Calculate the squared Euclidean distance between a point and the origin.", "function_declaration": "def squared_distance(point, origin):", "function_name": "squared_distance", "parameter_list": "(point, origin)" }, { "docstring": "Find the k closest points to the origin.", ...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nfrom math import sqrt\n\ndef k_closest(points, k, origin=(0, 0)):\n \"\"\"\n Returns the k closest points to the origin.\n \n :param...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00023584", "row_id": 23584, "seed_ids": "[266]" }
0.685397
Data_Structure_23584
I
[ "squared_distance", "k_closest" ]
2
[ [ "k_closest", "squared_distance" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8ef2d8494d0f3b5d4d0f0ba369906b5c650617f6
93a928fb3284f70d9aa3e1953bcc74fbfaa61190
v1.0
instruct
Data_Structure
Data_Structure_23615_I
### Question: Secure Key Exchange You are tasked with implementing a secure key exchange system similar to Diffie-Hellman where two parties (Alice and Bob) can exchange keys over an insecure channel. **Function Signature**: `secure_key_exchange(p: int, a: int) -> bool` ### Input - `p`: A large prime number. - `a`: A...
def is_prime(n): """ Helper function to check if a number is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 ...
from solution import secure_key_exchange def test_valid_exchange(): assert secure_key_exchange(23, 5) == True # 5 is a primitive root of 23 def test_invalid_non_prime_p(): assert secure_key_exchange(15, 2) == False # 15 is not prime def test_invalid_non_primitive_root(): assert secure_key_exchange(23, ...
[ { "docstring": "Helper function to check if a number is prime. ", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Helper function to check if `a` is a primitive root of `p`. ", "function_declaration": "def is_primitive_r...
[ 0, 1 ]
1
medium
0.5
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"Helper function to check primality of a number.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00023615", "row_id": 23615, "seed_ids": "[146]" }
0.43852
Data_Structure_23615
I
[ "is_prime", "is_primitive_root", "secure_key_exchange" ]
3
[ [ "is_primitive_root", "is_prime" ], [ "secure_key_exchange", "is_prime" ], [ "secure_key_exchange", "is_primitive_root" ] ]
3
[]
false
[]
false
pytest
true
[]
true
ae6d8239349e5027b6e921fcd5f81e0c79adc6b3
d923e77928e02dd8843f716543e0810a90bf9f19
v1.0
instruct
Data_Structure
Data_Structure_23697_I
### Quick Sort Enhancement You are required to enhance the quick sort algorithm to use the "median-of-three" technique to choose a pivot, which helps in improving the worst-case performance on nearly sorted data. Additionally, implement edge case handling and optimized base case for sub-arrays with fewer than 10 eleme...
def insertion_sort(arr, left, right): for i in range(left + 1, right + 1): key = arr[i] j = i - 1 while j >= left and key < arr[j]: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key def median_of_three(arr, left, right): mid = (left + right) // 2 if arr[lef...
# Test cases for the enhanced_quick_sort function def test_basic_sort(): assert enhanced_quick_sort([34, 7, 23, 32, 5, 62]) == [5, 7, 23, 32, 34, 62] def test_empty_list(): assert enhanced_quick_sort([]) == [] def test_single_element(): assert enhanced_quick_sort([1]) == [1] def test_already_sorted(): ...
[ { "docstring": null, "function_declaration": "def insertion_sort(arr, left, right):", "function_name": "insertion_sort", "parameter_list": "(arr, left, right)" }, { "docstring": null, "function_declaration": "def median_of_three(arr, left, right):", "function_name": "median_of_three"...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def insertion_sort(arr, low, high):\n for i in range(low + 1, high + 1):\n key = arr[i]\n j = i - 1\n while j >= low and arr[j] > key:...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023697", "row_id": 23697, "seed_ids": "[25]" }
0.592366
Data_Structure_23697
I
[ "insertion_sort", "median_of_three", "partition", "quick_sort", "enhanced_quick_sort" ]
5
[ [ "enhanced_quick_sort", "quick_sort" ], [ "partition", "median_of_three" ], [ "quick_sort", "insertion_sort" ], [ "quick_sort", "partition" ] ]
4
[]
false
[]
false
pytest
false
[]
true
4fa3b0d665039c33ba7e55e631b00d9d9ad6a83e
6578ac7d56b77c52e4e44bcdb02a1a8838c35875
v1.0
instruct
Data_Structure
Data_Structure_23698_I
### Question: Implement and Optimize Merge Sort for Large Data You are given an array of integers, `arr`, which needs to be sorted in ascending order using the merge sort algorithm. While merge sort is efficient, it tends to use significant extra space. Your task is to: 1. Implement the merge sort algorithm. 2. Optimi...
from typing import List def insertion_sort(arr: List[int], left: int, right: int) -> None: for i in range(left + 1, right + 1): key = arr[i] j = i - 1 while j >= left and arr[j] > key: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key def merge(arr: List[int], lef...
from solution import merge_sort def test_empty_array(): assert merge_sort([]) == [] def test_single_element_array(): assert merge_sort([1]) == [1] def test_sorted_array(): assert merge_sort([1, 2, 3, 4, 5]) == [1, 2, 3, 4, 5] def test_reverse_sorted_array(): assert merge_sort([5, 4, 3, 2, 1]) == [1,...
[ { "docstring": null, "function_declaration": "def insertion_sort(arr, left, right):", "function_name": "insertion_sort", "parameter_list": "(arr, left, right)" }, { "docstring": null, "function_declaration": "def merge(arr, left, mid, right):", "function_name": "merge", "paramete...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef merge_sort(arr: List[int]) -> List[int]:\n # Use Insertion Sort for small sub-arrays\n def insertion_sort(sub_arr: List[i...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00023698", "row_id": 23698, "seed_ids": "[12]" }
0.636499
Data_Structure_23698
I
[ "insertion_sort", "merge", "merge_sort_util", "merge_sort" ]
4
[ [ "merge_sort", "merge_sort_util" ], [ "merge_sort_util", "insertion_sort" ], [ "merge_sort_util", "merge" ] ]
3
[]
false
[]
false
pytest
true
[]
true
4cddc3f8c33492f1b16762998e0b9139aec17f36
d69f884ef4b5cfb83cfff03dfe3662ee90fcd8a2
v1.0
instruct
Data_Structure
Data_Structure_23746_I
### Problem Description You are provided with an algorithm that adds two positive integers using bitwise operations. To further reinforce your understanding of bitwise operations, implement a function that multiplies two positive integers without using the '*' operator. ### Function Signature ```python def multiply_...
def multiply_bitwise_operator(a: int, b: int) -> int: """ Multiplies two positive integers using bitwise operations. """ result = 0 while b > 0: if b & 1: # Check if the least significant bit is 1 result = add_bitwise(result, a) a = a << 1 # Left shift a by 1 (equivalen...
from solution import multiply_bitwise_operator def test_multiply_bitwise_operator_1(): assert multiply_bitwise_operator(2, 3) == 6 def test_multiply_bitwise_operator_2(): assert multiply_bitwise_operator(7, 8) == 56 def test_multiply_bitwise_operator_3(): assert multiply_bitwise_operator(0, 5) == 0 a...
[ { "docstring": "Multiplies two positive integers using bitwise operations.", "function_declaration": "def multiply_bitwise_operator(a, b):", "function_name": "multiply_bitwise_operator", "parameter_list": "(a, b)" }, { "docstring": "Adds two integers using bitwise operations.", "function...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def multiply_bitwise_operator(a: int, b: int) -> int:\n \"\"\"\n Multiplies two positive integers using bitwise operations.\n \"\"\"\n result = 0\...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00023746", "row_id": 23746, "seed_ids": "[209]" }
0.674403
Data_Structure_23746
I
[ "multiply_bitwise_operator", "add_bitwise" ]
2
[ [ "multiply_bitwise_operator", "add_bitwise" ] ]
1
[]
false
[]
false
pytest
true
[]
true
2fd16f7731c50561829d1911cb8b7fc04278c269
3bcf52c4e23c5bbd571e17c99cece8b44e06d822
v1.0
instruct
Data_Structure
Data_Structure_23888_I
### Maximum Flow Challenge: Implement the Edmonds-Karp Algorithm #### Introduction You're given the task of finding the maximum flow in a directed, weighted graph. The graph is represented as an n x n adjacency matrix, where the value at `graph[i][j]` represents the capacity of the edge from vertex `i` to vertex `j`....
from typing import List from collections import deque def bfs(graph: List[List[int]], s: int, t: int, parent: List[int]) -> bool: visited = [False] * len(graph) queue = deque([s]) visited[s] = True while queue: u = queue.popleft() for ind, val in enumerate(graph[u]): ...
from solution import maximum_flow_bfs def test_maximum_flow_simple_case(): graph = [ [0, 16, 13, 0, 0, 0], [0, 0, 10, 12, 0, 0], [0, 4, 0, 0, 14, 0], [0, 0, 9, 0, 0, 20], [0, 0, 0, 7, 0, 4], [0, 0, 0, 0, 0, 0] ] assert maximum_flow_bfs(graph) == 23 def test_...
[ { "docstring": null, "function_declaration": "def bfs(graph, s, t, parent):", "function_name": "bfs", "parameter_list": "(graph, s, t, parent)" }, { "docstring": null, "function_declaration": "def maximum_flow_bfs(graph):", "function_name": "maximum_flow_bfs", "parameter_list": "...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\nfrom collections import deque\n\ndef bfs(graph: List[List[int]], s: int, t: int, parent: List[int]) -> bool:\n visited = [False] *...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00023888", "row_id": 23888, "seed_ids": "[241]" }
0.614179
Data_Structure_23888
I
[ "bfs", "maximum_flow_bfs" ]
2
[ [ "maximum_flow_bfs", "bfs" ] ]
1
[]
false
[]
false
pytest
true
[]
true
4fcc8b99e0bc53b940c0ae095b76fb7417629888
884b9ffb4a1babba8b72e58d7a68908b97982d57
v1.0
instruct
Data_Structure
Data_Structure_23929_I
You are tasked with writing an efficient Heap Sort function that sorts an array of integers. Unlike typical Heap Sort implementations which use either a max-heap or min-heap exclusively, your task requires you to implement a hybrid approach that uses a max-heap to partially sort the array and a min-heap to complete the...
import heapq from typing import List def hybrid_heap_sort(arr: List[int], simulation: bool = False) -> List[int]: def print_simulation(arr): if simulation: print(arr) # Phase 1: Max-Heap sort n = len(arr) # Build a max heap for i in range(n // 2 - 1, -1, -1): heapi...
from solution import hybrid_heap_sort def test_hybrid_heap_sort(): assert hybrid_heap_sort([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5]) == [1, 1, 2, 3, 3, 4, 5, 5, 5, 6, 9] assert hybrid_heap_sort([5, 3, 1, 4, 6]) == [1, 3, 4, 5, 6] assert hybrid_heap_sort([]) == [] assert hybrid_heap_sort([1]) == [1] assert...
[ { "docstring": null, "function_declaration": "def hybrid_heap_sort(arr, simulation=False):", "function_name": "hybrid_heap_sort", "parameter_list": "(arr, simulation=False)" }, { "docstring": null, "function_declaration": "def heapify_max(arr, n, i):", "function_name": "heapify_max",...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import heapq\nfrom typing import List\n\ndef hybrid_heap_sort(arr: List[int], simulation: bool = False) -> List[int]:\n def print_simulation(arr):\n ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00023929", "row_id": 23929, "seed_ids": "[8]" }
0.65183
Data_Structure_23929
I
[ "hybrid_heap_sort", "heapify_max" ]
2
[ [ "hybrid_heap_sort", "heapify_max" ] ]
1
[]
false
[]
false
pytest
true
[]
true
a80ad824ebec628c764af6b2f19a735c05a2ca6f
bcb482b1bf32c4568798c6c3d7c0f630ac02602a
v1.0
instruct
Data_Structure
Data_Structure_23944_I
### Minimum Spanning Tree with Kruskal's Algorithm **Context**: You are working as a network engineer for a smart city project. You need to design an efficient network to connect various infrastructure points (nodes) with the minimum cost. Each connection between nodes has a specified cost, and your goal is to create ...
def find(parent, i): """ Function to find the set of an element i with path compression. """ if parent[i] == i: return i else: parent[i] = find(parent, parent[i]) return parent[i] def union(parent, rank, x, y): """ Function to perform union of two sets x and y by ran...
from solution import minimum_spanning_tree def test_minimum_spanning_tree_basic_case(): vertex_count = 5 edges = [(0, 1, 3), (0, 2, 8), (1, 3, 5), (2, 3, 2), (2, 4, 4), (3, 4, 6)] assert minimum_spanning_tree(vertex_count, edges) == 14 def test_minimum_spanning_tree_single_edge(): vertex_count = 2 ...
[ { "docstring": "Function to find the set of an element i with path compression.", "function_declaration": "def find(parent, i):", "function_name": "find", "parameter_list": "(parent, i)" }, { "docstring": "Function to perform union of two sets x and y by rank.", "function_declaration": "...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def minimum_spanning_tree(vertex_count, edges):\n # Function to find the root of a node\n def find(parent, i):\n if parent[i] == i:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00023944", "row_id": 23944, "seed_ids": "[230]" }
0.76305
Data_Structure_23944
I
[ "find", "union", "minimum_spanning_tree" ]
3
[ [ "minimum_spanning_tree", "find" ], [ "minimum_spanning_tree", "union" ], [ "union", "find" ] ]
3
[]
false
[]
false
pytest
true
[]
true
365231d5c1eef15894805e08921e785752fce0a8
5ff02024e5769d6a02cc501d5e1fecc824556437
v1.0
instruct
Data_Structure
Data_Structure_23989_I
### Word Square Construction **Scenario**: You are tasked with developing an algorithm to solve a crossword puzzle problem. Given a list of words, you need to find all possible "word squares" that can be formed. A word square is a set of words that reads the same horizontally and vertically. **Problem**: Design a fun...
from typing import List, Dict from collections import defaultdict def build_prefix_dict(words: List[str]) -> Dict[str, List[str]]: prefix_dict = defaultdict(list) for word in words: for i in range(len(word)): prefix_dict[word[:i]].append(word) return prefix_dict def search_word_squares...
from solution import word_squares def test_word_squares_example_1(): input_words = ["area","lead","wall","lady","ball"] output = [ ["wall","area","lead","lady"], ["ball","area","lead","lady"] ] assert word_squares(input_words) == output def test_word_squares_example_2(): input_words = ...
[ { "docstring": null, "function_declaration": "def build_prefix_dict(words):", "function_name": "build_prefix_dict", "parameter_list": "(words)" }, { "docstring": null, "function_declaration": "def search_word_squares(step, word_length, square, prefix_dict, results):", "function_name"...
[ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import defaultdict\nfrom typing import List\n\ndef build_prefix_hash(words: List[str]) -> dict:\n \"\"\" Build a hash map for storing word...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00023989", "row_id": 23989, "seed_ids": "[87]" }
0.599583
Data_Structure_23989
I
[ "build_prefix_dict", "search_word_squares", "word_squares" ]
3
[ [ "word_squares", "build_prefix_dict" ], [ "word_squares", "search_word_squares" ] ]
2
[]
false
[]
false
pytest
true
[]
true
ef3846f2c08074c569730b25ffbb2ff61d99583f
cdc0b86b2176aa83f4a5411a072843374fcf913c
v1.0
instruct
Data_Structure
Data_Structure_24013_I
Implement an optimized prime-checking function and utilize it to filter out all prime numbers from a given list of integers. **Objective**: Write a function, `filter_primes(nums: List[int]) -> List[int]`, that utilizes an efficient algorithm to identify and return only the prime numbers from the input list. ### Funct...
from typing import List import math def is_prime(n: int) -> bool: if n <= 1: return False if n == 2: return True if n % 2 == 0: return False max_divisor = int(math.sqrt(n)) + 1 for d in range(3, max_divisor, 2): if n % d == 0: return False return True...
from solution import filter_primes, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(16) == False assert is_prime(17) == True assert is_prime(-3) == False assert is_prime(0) == Fals...
[ { "docstring": null, "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": null, "function_declaration": "def filter_primes(nums):", "function_name": "filter_primes", "parameter_list": "(nums)" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\nimport math\n\ndef is_prime(n: int) -> bool:\n if n <= 1:\n return False\n if n == 2:\n return True\n if n % 2...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00024013", "row_id": 24013, "seed_ids": "[143]" }
0.651359
Data_Structure_24013
I
[ "is_prime", "filter_primes" ]
2
[ [ "filter_primes", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
89568944738e193d3792990db0dd3bf4a94a7985
d6a7dbf52dae14c5eac90b86d1b287baec62eb2f
v1.0
instruct
Data_Structure
Data_Structure_24072_I
### Question: Clone an Undirected Graph Given an undirected graph, write a function to clone the graph. Each node in the graph contains a unique label and a list of its neighbors. You need to implement the function `clone_graph(node: UndirectedGraphNode) -> UndirectedGraphNode` that returns a deep copy of the graph st...
class UndirectedGraphNode: def __init__(self, label): self.label = label self.neighbors = [] def shallow_copy(self): return UndirectedGraphNode(self.label) def add_neighbor(self, node): self.neighbors.append(node) def clone_graph(node): def dfs(node, dic): for...
from solution import UndirectedGraphNode, clone_undirected_graph def test_empty_graph(): assert clone_undirected_graph("") == "" def test_single_node_graph(): graph_str = "0" assert clone_undirected_graph(graph_str) == graph_str def test_two_nodes_graph(): graph_str = "0,1#1" clone = clone_undire...
[]
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "class UndirectedGraphNode:\n def __init__(self, label):\n self.label = label\n self.neighbors = []\n\ndef clone_graph(node):\n if not node...
trial_gpt4o_9
{ "original_instruction": "", "prompt_id": "00024072", "row_id": 24072, "seed_ids": "[239]" }
0.523205
Data_Structure_24072
I
[ "clone_graph", "parse_graph", "serialize_graph", "clone_undirected_graph" ]
4
[ [ "clone_undirected_graph", "clone_graph" ], [ "clone_undirected_graph", "parse_graph" ], [ "clone_undirected_graph", "serialize_graph" ] ]
3
[]
false
[ "UndirectedGraphNode" ]
true
pytest
true
[]
true
8d5562a42fae95c9d15242e5c544499bc9d4a5a5
b4339b2e79f7e516d98b08b141877bcc00ccb13c
v1.0
instruct
Data_Structure
Data_Structure_24104_I
### Diffie-Hellman Key Exchange Implementation You are tasked with implementing a secure key exchange mechanism using the Diffie-Hellman protocol. This protocol allows two parties, Alice and Bob, to establish a shared secret key over an unsecured communication channel. #### Problem Statement Implement a function `d...
def diffie_hellman_key_exchange(a: int, p: int) -> bool: """ Perform the Diffie-Hellman key exchange protocol and return True if both parties compute the same shared secret, else False. """ # Check that p is a valid prime number. if not is_prime(p): return False # Check that a is a ...
from solution import diffie_hellman_key_exchange, is_prime def test_is_prime(): assert is_prime(2) == True assert is_prime(3) == True assert is_prime(4) == False assert is_prime(5) == True assert is_prime(11) == True assert is_prime(13) == True assert is_prime(15) == False assert is_pri...
[ { "docstring": "Perform the Diffie-Hellman key exchange protocol and return True\nif both parties compute the same shared secret, else False.", "function_declaration": "def diffie_hellman_key_exchange(a, p):", "function_name": "diffie_hellman_key_exchange", "parameter_list": "(a, p)" }, { "d...
[ 0, 0, 0, 1, 1, 0, 0, 0, 1, 1 ]
4
medium
0.4
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def diffie_hellman_key_exchange(a, p):\n \"\"\"\n Performs Diffie-Hellman key exchange to verify both parties compute the same shared secret.\n\n Arg...
trial_gpt4o_3
{ "original_instruction": "", "prompt_id": "00024104", "row_id": 24104, "seed_ids": "[146]" }
0.561871
Data_Structure_24104
I
[ "diffie_hellman_key_exchange", "is_prime" ]
2
[ [ "diffie_hellman_key_exchange", "is_prime" ] ]
1
[]
false
[]
false
pytest
true
[]
true
c159c6dd82fc3bef78c2fcbd3158ed2885b8be3b
6084cf2ea15f72cd00858a93a0b49b4237ce3f09
v1.0
instruct
Data_Structure
Data_Structure_24129_I
You are tasked with designing a function that performs multiple transformations on a given matrix, incorporating both rotation and inversion operations. The goal is to amalgamate these operations in a single function, showcasing your understanding of matrix manipulation. ### Function Definition You need to implement ...
from typing import List def rotate_clockwise(matrix: List[List[int]]) -> List[List[int]]: return [list(reversed(col)) for col in zip(*matrix)] def rotate_counterclockwise(matrix: List[List[int]]) -> List[List[int]]: return rotate_clockwise(rotate_clockwise(rotate_clockwise(matrix))) def top_left_invert(matri...
from solution import transform_matrix def test_rotate_clockwise(): matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9], ] operations = ["rotate_clockwise"] expected = [ [7, 4, 1], [8, 5, 2], [9, 6, 3], ] assert transform_matrix(matrix, operations) == expec...
[ { "docstring": null, "function_declaration": "def rotate_clockwise(matrix):", "function_name": "rotate_clockwise", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def rotate_counterclockwise(matrix):", "function_name": "rotate_counterclockwise", "par...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef rotate_clockwise(matrix: List[List[int]]) -> List[List[int]]:\n return [list(reversed(col)) for col in zip(*matrix)]\n\ndef ...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00024129", "row_id": 24129, "seed_ids": "[337]" }
0.525456
Data_Structure_24129
I
[ "rotate_clockwise", "rotate_counterclockwise", "top_left_invert", "bottom_left_invert", "transform_matrix" ]
5
[ [ "rotate_counterclockwise", "rotate_clockwise" ], [ "transform_matrix", "bottom_left_invert" ], [ "transform_matrix", "rotate_clockwise" ], [ "transform_matrix", "rotate_counterclockwise" ], [ "transform_matrix", "top_left_invert" ] ]
5
[]
false
[]
false
pytest
true
[]
true
51d45fc050ad19e2bbcd818a2546db1916882c38
658e00cd5ac025566e957234044d8312e19a418f
v1.0
instruct
Data_Structure
Data_Structure_24160_I
### Matrix Inversion Coding Challenge **Context**: You are tasked with implementing a function to invert an `n x n` matrix using the classical method involving minors, cofactors, and adjugation. This function should be robust and handle typical edge cases such as non-square matrices and singular matrices. **Function ...
from typing import List def get_determinant(matrix: List[List[float]]) -> float: n = len(matrix) if n == 1: return matrix[0][0] if n == 2: return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0] determinant = 0.0 for c in range(n): minor = [[matrix[i][j] for j...
from solution import invert_matrix def test_square_matrix_inversion(): matrix = [ [4, 7], [2, 6] ] expected_result = [ [0.6, -0.7], [-0.2, 0.4] ] result = invert_matrix(matrix) for i in range(len(expected_result)): for j in range(len(expected_result[0])):...
[ { "docstring": null, "function_declaration": "def get_determinant(matrix):", "function_name": "get_determinant", "parameter_list": "(matrix)" }, { "docstring": null, "function_declaration": "def get_matrix_of_minors(matrix):", "function_name": "get_matrix_of_minors", "parameter_l...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef get_determinant(matrix: List[List[float]]) -> float:\n n = len(matrix)\n if n == 2: # Base case for 2x2 matrix\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024160", "row_id": 24160, "seed_ids": "[347]" }
0.547902
Data_Structure_24160
I
[ "get_determinant", "get_matrix_of_minors", "transpose_matrix", "multiply_matrix_by_scalar", "invert_matrix" ]
5
[ [ "get_matrix_of_minors", "get_determinant" ], [ "invert_matrix", "get_determinant" ], [ "invert_matrix", "get_matrix_of_minors" ], [ "invert_matrix", "multiply_matrix_by_scalar" ], [ "invert_matrix", "transpose_matrix" ] ]
5
[]
false
[]
false
pytest
true
[]
true
0ef6343cf577382d1b9e36de7a7b303ddc46d52e
5ab9c3a2a55cc0fe5d30f89bcfe8a2d309f6efc2
v1.0
instruct
Data_Structure
Data_Structure_24162_I
You are tasked with implementing a modified version of the Bitonic Sort algorithm. This version will sort arrays of integers both in increasing and decreasing order. Additionally, it must handle edge cases where the array size is not a power of two by padding the array with a maximum integer value until the closest pow...
import math def bitonic_merge(arr, low, cnt, direction): if cnt > 1: k = cnt // 2 for i in range(low, low + k): if (direction and arr[i] > arr[i + k]) or (not direction and arr[i] < arr[i + k]): arr[i], arr[i + k] = arr[i + k], arr[i] bitonic_merge(arr, low, k, d...
from solution import modified_bitonic_sort def test_modified_bitonic_sort_ascending(): assert modified_bitonic_sort([3, 7, 2, 8, 1, 5, 4], False) == [1, 2, 3, 4, 5, 7, 8] def test_modified_bitonic_sort_descending(): assert modified_bitonic_sort([3, 7, 2, 8, 1, 5, 4], True) == [8, 7, 5, 4, 3, 2, 1] def test_m...
[ { "docstring": null, "function_declaration": "def bitonic_merge(arr, low, cnt, direction):", "function_name": "bitonic_merge", "parameter_list": "(arr, low, cnt, direction)" }, { "docstring": null, "function_declaration": "def bitonic_sort(arr, low, cnt, direction):", "function_name"...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import math\n\ndef modified_bitonic_sort(arr, reverse=False):\n \"\"\"\n Sort an array in either ascending or descending order using a modified Bitonic ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024162", "row_id": 24162, "seed_ids": "[17]" }
0.677025
Data_Structure_24162
I
[ "bitonic_merge", "bitonic_sort", "next_power_of_two", "modified_bitonic_sort" ]
4
[ [ "bitonic_sort", "bitonic_merge" ], [ "modified_bitonic_sort", "bitonic_sort" ], [ "modified_bitonic_sort", "next_power_of_two" ] ]
3
[]
false
[]
false
pytest
true
[]
true
757eec32faf7ef3c4f12998a2e14470c80bf749d
2637ad0a1b82026e62f80a86c2492e64f8f46e62
v1.0
instruct
Data_Structure
Data_Structure_24192_I
### Digit Power Sum Identification #### Scenario You are tasked with writing a function that identifies special numbers within a given range. These are numbers for which the sum of each digit raised to consecutive powers (starting from 1) equals the number itself. This concept is named "Eureka numbers." ### Function ...
def sum_dig_pow(low, high): """ Finds and returns a list of numbers within the specified range such that the sum of each digit of the number raised to consecutive powers equals the number itself. """ result = [] for num in range(low, high + 1): if is_eureka(num): result.appen...
from solution import sum_dig_pow def test_basic_case(): assert sum_dig_pow(1, 10) == [1, 2, 3, 4, 5, 6, 7, 8, 9] def test_case_with_89(): assert sum_dig_pow(1, 100) == [1, 2, 3, 4, 5, 6, 7, 8, 9, 89] def test_large_range(): assert sum_dig_pow(50, 150) == [89, 135] def test_single_value(): assert sum...
[ { "docstring": "Finds and returns a list of numbers within the specified range such that\nthe sum of each digit of the number raised to consecutive powers equals the number itself.", "function_declaration": "def sum_dig_pow(low, high):", "function_name": "sum_dig_pow", "parameter_list": "(low, high)...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def sum_dig_pow(low, high):\n \"\"\"\n Returns list of Eureka numbers within the range [low, high].\n \"\"\"\n def is_eureka(num):\n digits...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024192", "row_id": 24192, "seed_ids": "[135]" }
0.629794
Data_Structure_24192
I
[ "sum_dig_pow", "is_eureka" ]
2
[ [ "sum_dig_pow", "is_eureka" ] ]
1
[]
false
[]
false
pytest
true
[]
true
6872dff9cf635bb13d8a84bc9ac670cd6b161674
40f31ccaff285d6a76c63b0920f0a14707561306
v1.0
instruct
Data_Structure
Data_Structure_24212_I
### Exponentiation Problem **Problem Statement:** You are tasked with designing a function to compute the power of a given base using binary exponentiation method. Your solution should account for both regular and modular calculations efficiently. **Function Signature:** ```python def power(a: int, n: int, mod: int ...
def power(a: int, n: int, mod: int = None) -> int: """ Computes the power a^n using binary exponentiation. If mod is provided, returns (a^n) % mod. """ result = 1 base = a if mod: base = base % mod while n > 0: if n % 2 == 1: result = (result * ...
from solution import power def test_power_regular_cases(): assert power(2, 10) == 1024 assert power(3, 7) == 2187 assert power(5, 3) == 125 assert power(10, 6) == 1000000 def test_power_with_mod(): assert power(2, 10, 1000) == 24 assert power(3, 7, 100) == 87 assert power(5, 3, 13) == 8 ...
[ { "docstring": "Computes the power a^n using binary exponentiation.\n\nIf mod is provided, returns (a^n) % mod.", "function_declaration": "def power(a, n, mod=None):", "function_name": "power", "parameter_list": "(a, n, mod=None)" }, { "docstring": null, "function_declaration": "def _tes...
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def power(a: int, n: int, mod: int = None) -> int:\n result = 1\n base = a\n\n while n > 0:\n if n % 2 == 1:\n if mod:\n ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00024212", "row_id": 24212, "seed_ids": "[151]" }
0.633144
Data_Structure_24212
I
[ "power", "_test" ]
2
[ [ "_test", "power" ] ]
1
[]
false
[]
false
pytest
true
[]
true
8ba01c078f37959ea09d27d3545c34371bc68da8
1a3ecadfb045e3d78b48ab57a979de4f0434982a
v1.0
instruct
Data_Structure
Data_Structure_24223_I
### Context: You are given methods to serialize and deserialize a binary tree. Serialization converts the tree into a string, and deserialization converts the string back into the original tree structure. This serialization method uses pre-order traversal and denotes null nodes with "#". ### Task: **Function Implement...
class TreeNode: def __init__(self, x): self.val = x self.left = None self.right = None def serialize(root): """ Encodes a tree to a single string. :type root: TreeNode :rtype: str """ def helper(node): if node is None: return "#" retu...
from solution import TreeNode, are_trees_identical def test_identical_trees(): root1 = TreeNode(1) root1.left = TreeNode(2) root1.right = TreeNode(3) root1.right.left = TreeNode(4) root1.right.right = TreeNode(5) root2 = TreeNode(1) root2.left = TreeNode(2) root2.right = TreeNode(3...
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, x):\n self.val = x\n self.left = None\n self.right = None\n\ndef serialize(root):\n \"\"\"Enco...
trial_gpt4o_1
{ "original_instruction": "", "prompt_id": "00024223", "row_id": 24223, "seed_ids": "[330]" }
0.553249
Data_Structure_24223
I
[ "serialize", "are_trees_identical" ]
2
[ [ "are_trees_identical", "serialize" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
5c6c4dde3928bbd1a04350d94fd1fa6c3a1cf1bc
5b388d0e6d3d2d091757e368b3718d9a7f08d874
v1.0
instruct
Data_Structure
Data_Structure_24231_I
You are given an array of integers that needs to be sorted using heap sort. However, the twist is that you must implement both max-heap sort and min-heap sort, and compare their performance under different input conditions. ### Requirements 1. Implement heap sorting using both max-heap and min-heap approaches. 2. Wri...
import time def max_heapify(arr, n, i, simulation_count): largest = i left = 2 * i + 1 right = 2 * i + 2 if simulation_count is not None: simulation_count[0] += 1 if left < n and arr[left] > arr[largest]: largest = left if right < n and arr[right] > arr[largest]: larg...
from solution import max_heap_sort, min_heap_sort, compare_heap_sorts def test_max_heap_sort(): arr = [3, 1, 5, 4, 2] sorted_arr = max_heap_sort(arr[:]) assert sorted_arr == sorted(arr, reverse=False) def test_min_heap_sort(): arr = [3, 1, 5, 4, 2] sorted_arr = min_heap_sort(arr[:]) assert sor...
[ { "docstring": null, "function_declaration": "def max_heapify(arr, n, i, simulation_count):", "function_name": "max_heapify", "parameter_list": "(arr, n, i, simulation_count)" }, { "docstring": null, "function_declaration": "def min_heapify(arr, n, i, simulation_count):", "function_n...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import time\n\ndef max_heapify(arr, n, i, iterations):\n largest = i\n left = 2 * i + 1\n right = 2 * i + 2\n \n if left < n and arr[i] < arr[l...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024231", "row_id": 24231, "seed_ids": "[8]" }
0.629878
Data_Structure_24231
I
[ "max_heapify", "min_heapify", "max_heap_sort", "min_heap_sort", "compare_heap_sorts" ]
5
[ [ "compare_heap_sorts", "max_heap_sort" ], [ "compare_heap_sorts", "min_heap_sort" ], [ "max_heap_sort", "max_heapify" ], [ "min_heap_sort", "min_heapify" ] ]
4
[]
false
[]
false
pytest
true
[]
true
cc06c3a4c738505048879bf3560c395fdcd7b8d2
b96719583c618d3c9d7a2d3570a9e4ffd06e773a
v1.0
instruct
Data_Structure
Data_Structure_24239_I
### Binary Search Challenge You are provided with two sorted arrays of integers. Your task is to determine the number of common elements between the two arrays using the Binary Search algorithm. Implement the function `count_common_elements(arr1, arr2)` that returns the number of common elements in the two sorted arr...
def binary_search(arr, target): """ Function to perform binary search on a sorted array. Returns True if target is found, otherwise returns False. """ left, right = 0, len(arr) - 1 while left <= right: mid = (left + right) // 2 if arr[mid] == target: return True ...
from solution import count_common_elements def test_common_elements(): arr1 = [1, 3, 4, 6, 7, 9] arr2 = [1, 2, 4, 5, 9, 10] assert count_common_elements(arr1, arr2) == 3 def test_no_common_elements(): arr1 = [1, 3, 5, 7] arr2 = [2, 4, 6, 8] assert count_common_elements(arr1, arr2) == 0 def te...
[ { "docstring": "Function to perform binary search on a sorted array.\nReturns True if target is found, otherwise returns False.", "function_declaration": "def binary_search(arr, target):", "function_name": "binary_search", "parameter_list": "(arr, target)" }, { "docstring": "Returns the numb...
[ 0, 0, 1 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def count_common_elements(arr1, arr2):\n \"\"\"\n Returns the number of common elements in two sorted arrays using Binary Search.\n \"\"\"\n def b...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024239", "row_id": 24239, "seed_ids": "[200]" }
0.687952
Data_Structure_24239
I
[ "binary_search", "count_common_elements" ]
2
[ [ "count_common_elements", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
093966e7c49f53755d8ee2502efc523688070e6d
6489ca3021cfee6eb41311b588a4de29cd167444
v1.0
instruct
Data_Structure
Data_Structure_24240_I
### Problem Description You are given an array of integers which you need to sort in ascending order using the merge sort algorithm. The provided merge sort algorithm splits the array until each sub-array contains a single element, then merges the sub-arrays by comparing the elements and sorting them. You need to imple...
from typing import List def merge_sort(arr: List[int]) -> List[int]: if len(arr) <= 1: return arr mid = len(arr) // 2 left_half = merge_sort(arr[:mid]) right_half = merge_sort(arr[mid:]) return merge(left_half, right_half) def merge(left: List[int], right: List[int]) -> List[int]...
from solution import merge_sort def test_merge_sort_basic(): assert merge_sort([4, 1, 7, 3, 2, 9, 8]) == [1, 2, 3, 4, 7, 8, 9] def test_merge_sort_single_element(): assert merge_sort([12]) == [12] def test_merge_sort_empty(): assert merge_sort([]) == [] def test_merge_sort_sorted_array(): assert mer...
[ { "docstring": null, "function_declaration": "def merge_sort(arr):", "function_name": "merge_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def merge(left, right):", "function_name": "merge", "parameter_list": "(left, right)" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef merge_sort(arr: List[int]) -> List[int]:\n if len(arr) <= 1:\n return arr\n \n def merge(left: List[int], r...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024240", "row_id": 24240, "seed_ids": "[12]" }
0.713377
Data_Structure_24240
I
[ "merge_sort", "merge" ]
2
[ [ "merge_sort", "merge" ] ]
1
[]
false
[]
false
pytest
true
[]
true
52d45914ccc6bc33ae8ed14f33e933d10f5475eb
e22ce5ef26855237c8016bb66fceaf4536b9d523
v1.0
instruct
Data_Structure
Data_Structure_24254_I
**Problem Statement:** Write an efficient Python function `find_primitive_root(n)` that returns all primitive roots of the given positive integer `n`. If `n` has no primitive roots, return an empty list. This function determines the existence of primitive roots using Euler's Totient Function and Order Calculation prin...
from typing import List def gcd(a: int, b: int) -> int: while b: a, b = b, a % b return a def euler_totient(n: int) -> int: result = n p = 2 while p * p <= n: if n % p == 0: while n % p == 0: n //= p result -= result // p p += 1 i...
from solution import find_primitive_root def test_find_primitive_root_prime(): assert find_primitive_root(7) == [3, 5] def test_find_primitive_root_one(): assert find_primitive_root(1) == [0] def test_find_primitive_root_no_roots(): assert find_primitive_root(10) == [] def test_find_primitive_root_small...
[ { "docstring": null, "function_declaration": "def gcd(a, b):", "function_name": "gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def euler_totient(n):", "function_name": "euler_totient", "parameter_list": "(n)" }, { "docstring": null, ...
[ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 ]
1
hard
0.1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\nimport math\n\ndef euler_totient(n: int) -> int:\n \"\"\"\n Calculate Euler's Totient function for an integer n.\n \"\"\"\n ...
trial_gpt4o_7
{ "original_instruction": "", "prompt_id": "00024254", "row_id": 24254, "seed_ids": "[160]" }
0.521898
Data_Structure_24254
I
[ "gcd", "euler_totient", "find_order", "find_primitive_root" ]
4
[ [ "find_order", "gcd" ], [ "find_primitive_root", "euler_totient" ], [ "find_primitive_root", "find_order" ], [ "find_primitive_root", "gcd" ] ]
4
[]
false
[]
false
pytest
true
[]
true
9eb83dd640543174ecec3d3feb1d464fbf3b500e
4af7b2df5f303a0cb831500db2240563c75c1826
v1.0
instruct
Data_Structure
Data_Structure_24326_I
### Question Statement You are given two functions that implement the Extended Euclidean Algorithm and calculate the modular inverse. Your task is to extend this functionality to solve a set of linear congruences using the Chinese Remainder Theorem (CRT). ### Problem Description Given a list of n pairwise coprime in...
from typing import List, Tuple def extended_gcd(a: int, b: int) -> Tuple[int, int, int]: if a == 0: return b, 0, 1 gcd, x1, y1 = extended_gcd(b % a, a) x = y1 - (b // a) * x1 y = x1 return gcd, x, y def modular_inverse(a: int, m: int) -> int: gcd, x, y = extended_gcd(a, m) if gcd !...
import pytest from solution import chinese_remainder_theorem def test_crt_example(): a = [2, 3, 2] m = [3, 5, 7] assert chinese_remainder_theorem(a, m) == 23 def test_crt_single_equation(): a = [4] m = [7] assert chinese_remainder_theorem(a, m) == 4 def test_crt_large_values(): a = [1, 2,...
[ { "docstring": null, "function_declaration": "def extended_gcd(a, b):", "function_name": "extended_gcd", "parameter_list": "(a, b)" }, { "docstring": null, "function_declaration": "def modular_inverse(a, m):", "function_name": "modular_inverse", "parameter_list": "(a, m)" }, ...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List, Tuple\n\ndef extended_gcd(a: int, b: int) -> Tuple[int, int, int]:\n \"\"\"\n Returns a tuple (g, x, y) such that g is gcd(a, b...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024326", "row_id": 24326, "seed_ids": "[161]" }
0.602107
Data_Structure_24326
I
[ "extended_gcd", "modular_inverse", "chinese_remainder_theorem" ]
3
[ [ "chinese_remainder_theorem", "modular_inverse" ], [ "modular_inverse", "extended_gcd" ] ]
2
[]
false
[]
false
pytest
true
[]
true
e3c309628695406ac1261626d1fb6abb173b032a
15c67d464a51f47a0e0546399e799053238755ce
v1.0
instruct
Data_Structure
Data_Structure_24433_I
### Question: Advanced GCD and LCM Calculation You are tasked with implementing a function that calculates the Least Common Multiple (LCM) of two non-negative integers using an advanced GCD calculation method based on bitwise operations. Below is the detailed requirement for the task. #### Function Signature ```pytho...
def advanced_gcd(a: int, b: int) -> int: """ Returns the greatest common divisor of a and b using bitwise operations. """ if a == b: return a if a == 0: return b if b == 0: return a # a and b are both even if (a & 1) == 0 and (b & 1) == 0: return advanced...
from solution import advanced_gcd, advanced_lcm def test_advanced_gcd(): assert advanced_gcd(12, 15) == 3 assert advanced_gcd(6, 8) == 2 assert advanced_gcd(0, 5) == 5 assert advanced_gcd(10**6, 10**6) == 10**6 assert advanced_gcd(54, 24) == 6 def test_advanced_lcm(): assert advanced_lcm(12, 1...
[ { "docstring": "Returns the greatest common divisor of a and b using bitwise operations.", "function_declaration": "def advanced_gcd(a, b):", "function_name": "advanced_gcd", "parameter_list": "(a, b)" }, { "docstring": "Returns the least common multiple of a and b using the advanced gcd cal...
[ 1, 0, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def advanced_gcd(a: int, b: int) -> int:\n \"\"\"\n Returns the greatest common divisor of a and b using bitwise operations.\n \"\"\"\n if a == b:...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00024433", "row_id": 24433, "seed_ids": "[166]" }
0.627455
Data_Structure_24433
I
[ "advanced_gcd", "advanced_lcm" ]
2
[ [ "advanced_lcm", "advanced_gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
922166e72955fcb005bae196d8403cc9aa846a75
a5c21637cbb0f0de241be2cefed39d2a2da07f12
v1.0
instruct
Data_Structure
Data_Structure_24447_I
### Question: Enhanced Greatest Common Divisor and Trailing Zero Computation #### Problem Statement You are tasked with enhancing and improving existing number-theoretic functions. Your task includes the development of optimized and robust versions for calculating the greatest common divisor (GCD), least common multi...
def optimized_gcd(a, b): """ Compute the greatest common divisor of a and b using the Euclidean algorithm. Handles negative inputs and ensures at least one of the numbers is non-zero. """ if a == 0 and b == 0: raise ValueError("At least one of the integers must be non-zero") a, b = abs(a...
from solution import optimized_gcd, advanced_lcm, count_trailing_zeros def test_optimized_gcd(): # Test gcd with positive numbers assert optimized_gcd(48, 18) == 6 assert optimized_gcd(54, 24) == 6 # Test gcd with negative numbers assert optimized_gcd(-48, 18) == 6 assert optimized_gcd(48, -18)...
[ { "docstring": "Compute the greatest common divisor of a and b using the Euclidean algorithm.\nHandles negative inputs and ensures at least one of the numbers is non-zero.", "function_declaration": "def optimized_gcd(a, b):", "function_name": "optimized_gcd", "parameter_list": "(a, b)" }, { ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def optimized_gcd(a, b):\n \"\"\"\n Compute the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm.\n \"\"\"\n if a == 0 ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024447", "row_id": 24447, "seed_ids": "[166]" }
0.577666
Data_Structure_24447
I
[ "optimized_gcd", "advanced_lcm", "count_trailing_zeros" ]
3
[ [ "advanced_lcm", "optimized_gcd" ] ]
1
[]
false
[]
false
pytest
true
[]
true
fc2ec23f3059276e2624775fdf4ba99aceb36ec2
aa5b4aa0bd457c0703bca31066ef9a95b523a5cf
v1.0
instruct
Data_Structure
Data_Structure_24566_I
Enhanced Search Implementation **Scenario:** You are working in a data science company that deals with large datasets. To efficiently search through the datasets, you need to implement a search algorithm that performs well with uniformly distributed data. Your task is to implement an enhanced version of the interpolat...
def binary_search(array, search_key, low, high): while low <= high: mid = (low + high) // 2 if array[mid] == search_key: return mid elif array[mid] < search_key: low = mid + 1 else: high = mid - 1 return -1 def enhanced_interpolation_search(ar...
from solution import enhanced_interpolation_search def test_uniform_distribution(): array = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19] assert enhanced_interpolation_search(array, 7) == 3 assert enhanced_interpolation_search(array, 19) == 9 assert enhanced_interpolation_search(array, 1) == 0 assert enhance...
[ { "docstring": null, "function_declaration": "def binary_search(array, search_key, low, high):", "function_name": "binary_search", "parameter_list": "(array, search_key, low, high)" }, { "docstring": null, "function_declaration": "def enhanced_interpolation_search(array, search_key):", ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef binary_search(array: List[int], search_key: int, low: int, high: int) -> int:\n while low <= high:\n mid = low + (hig...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024566", "row_id": 24566, "seed_ids": "[192]" }
0.568661
Data_Structure_24566
I
[ "binary_search", "enhanced_interpolation_search" ]
2
[ [ "enhanced_interpolation_search", "binary_search" ] ]
1
[]
false
[]
false
pytest
true
[]
true
f376206971694817016d3476805d44346f87e088
8165c637f105916a2cf73c65c1b49705f761175f
v1.0
instruct
Data_Structure
Data_Structure_24616_I
You are given an array of integers, which we assume are non-negative. Implement the Bucket Sort algorithm to sort this array. You will need to both distribute the integers into buckets and sort the values within each bucket using insertion sort. ### Function Signature ```python def bucket_sort(arr: List[int]) -> List[...
from typing import List def insertion_sort(arr): for i in range(1, len(arr)): key = arr[i] j = i - 1 while j >= 0 and key < arr[j]: arr[j + 1] = arr[j] j -= 1 arr[j + 1] = key return arr def bucket_sort(arr: List[int]) -> List[int]: if len(arr) == 0:...
from solution import bucket_sort def test_bucket_sort_normal_case(): assert bucket_sort([3, 6, 8, 2, 5, 10, 15, 1, 14, 9]) == [1, 2, 3, 5, 6, 8, 9, 10, 14, 15] def test_bucket_sort_reversed(): assert bucket_sort([4, 3, 2, 1]) == [1, 2, 3, 4] def test_bucket_sort_empty(): assert bucket_sort([]) == [] def...
[ { "docstring": null, "function_declaration": "def insertion_sort(arr):", "function_name": "insertion_sort", "parameter_list": "(arr)" }, { "docstring": null, "function_declaration": "def bucket_sort(arr):", "function_name": "bucket_sort", "parameter_list": "(arr)" } ]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from typing import List\n\ndef bucket_sort(arr: List[int]) -> List[int]:\n if not arr:\n return []\n\n max_value = max(arr)\n bucket_count = l...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024616", "row_id": 24616, "seed_ids": "[26]" }
0.608819
Data_Structure_24616
I
[ "insertion_sort", "bucket_sort" ]
2
[ [ "bucket_sort", "insertion_sort" ] ]
1
[]
false
[]
false
pytest
true
[]
true
b0026fb8121bc979b409b18f22957331c33a01c8
231354c277b67cb6b40fcb31b8e8380b3e096023
v1.0
instruct
Data_Structure
Data_Structure_24690_I
### Question: Maximum Flow in a Transportation Network #### Context: A transportation company needs to optimize its freight routes to ensure that goods are transported from a central warehouse to multiple distribution centers with maximum efficiency. You are tasked with implementing a scheduling system that utilizes m...
from collections import deque def bfs(capacity, source, sink, parent): """ Breadth-First Search to find if there's a path from source to sink. Returns True if there is a path, False otherwise. """ visited = [False] * len(capacity) queue = deque([source]) visited[source] = True while qu...
def test_simple_case(): capacity = [ [0, 16, 13, 0, 0, 0], [0, 0, 10, 12, 0, 0], [0, 4, 0, 0, 14, 0], [0, 0, 9, 0, 0, 20], [0, 0, 0, 7, 0, 4], [0, 0, 0, 0, 0, 0] ] source = 0 sink = 5 assert compute_max_flow(capacity, source, sink) == 23 def test_no_c...
[ { "docstring": "Breadth-First Search to find if there's a path from source to sink.\nReturns True if there is a path, False otherwise.", "function_declaration": "def bfs(capacity, source, sink, parent):", "function_name": "bfs", "parameter_list": "(capacity, source, sink, parent)" }, { "docs...
[ 0, 1, 1 ]
2
easy
0.667
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "from collections import deque\n\ndef bfs(capacity, source, sink, parent):\n \"\"\"\n Perform BFS to find an augmenting path in the residual graph.\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024690", "row_id": 24690, "seed_ids": "[240]" }
0.585549
Data_Structure_24690
I
[ "bfs", "compute_max_flow" ]
2
[ [ "compute_max_flow", "bfs" ] ]
1
[]
false
[]
false
pytest
false
[]
true
e306ddc144b8bcdd33e14644bebdb10623410126
d80ddbde5e4c378031d8dff2fd6faa2d928cc53f
v1.0
instruct
Data_Structure
Data_Structure_24756_I
### Question: Implement and Extend Radix Sort with Specific Edge Cases #### Context: You are required to implement a sorting function to sort a list of positive integers using the radix sort algorithm detailed above. Additionally, you should extend the radix sort to handle edge cases like sorting arrays with mixed pos...
def radix_sort(arr): """ Helper function to perform radix sort on a list of non-negative integers. """ max_element = max(arr) exp = 1 while max_element // exp > 0: counting_sort(arr, exp) exp *= 10 def counting_sort(arr, exp): """ Helper function to perform counting sort...
from solution import enhanced_radix_sort def test_enhanced_radix_sort_mixed_positive_negative(): assert enhanced_radix_sort([170, 45, 75, 90, 802, 24, 2, 66]) == [2, 24, 45, 66, 75, 90, 170, 802] assert enhanced_radix_sort([-5, -10, 0, -3, 8, 5, -1]) == [-10, -5, -3, -1, 0, 5, 8] def test_enhanced_radix_sort_...
[ { "docstring": "Helper function to perform radix sort on a list of non-negative integers.", "function_declaration": "def radix_sort(arr):", "function_name": "radix_sort", "parameter_list": "(arr)" }, { "docstring": "Helper function to perform counting sort based on exponent value `exp`.", ...
[ 1, 0, 0 ]
1
medium
0.333
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def radix_sort(arr):\n \"\"\"\n Helper function to perform radix sort on a list of non-negative integers.\n \"\"\"\n max_element = max(arr)\n e...
trial_gpt4o_0
{ "original_instruction": "", "prompt_id": "00024756", "row_id": 24756, "seed_ids": "[15]" }
0.616093
Data_Structure_24756
I
[ "radix_sort", "counting_sort", "enhanced_radix_sort" ]
3
[ [ "enhanced_radix_sort", "radix_sort" ], [ "radix_sort", "counting_sort" ] ]
2
[]
false
[]
false
pytest
true
[]
true
b3ccbb153f9a5d2c3714d4ca7a671f1713a9e424
ed6d995eca53bdcd512e73259a22524a7103876d
v1.0
instruct
Data_Structure
Data_Structure_24792_I
You are given two binary trees `T1` and `T2`. Your task is to determine if `T2` is a subtree of `T1`. A subtree of `T1` is a tree consisting of a node in `T1` and all of its descendants in `T1`. ### Function Signature ```python def is_subtree(big: Optional[TreeNode], small: Optional[TreeNode]) -> bool: ``` ### Input ...
class TreeNode: def __init__(self, val=0, left=None, right=None): self.val = val self.left = left self.right = right def is_subtree(big: TreeNode, small: TreeNode) -> bool: if not small: return True # An empty tree is always a subtree if not big: return False # Non...
from solution import TreeNode, is_subtree def test_is_subtree_case1(): # tree 1 setup big = TreeNode(3) big.left = TreeNode(4) big.right = TreeNode(5) big.left.left = TreeNode(1) big.left.right = TreeNode(2) # tree 2 setup small = TreeNode(4) small.left = TreeNode(1) small....
[]
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "class TreeNode:\n def __init__(self, val=0, left=None, right=None):\n self.val = val\n self.left = left\n self.right = right\n\ndef is...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024792", "row_id": 24792, "seed_ids": "[288]" }
0.539879
Data_Structure_24792
I
[ "is_subtree", "is_same_tree" ]
2
[ [ "is_subtree", "is_same_tree" ] ]
1
[]
false
[ "TreeNode" ]
true
pytest
true
[]
true
456104648930acf20e7bdaeef0939276a43eb7a1
2648f0b0b94d8b1798558cb08c70b0c99ab0459d
v1.0
instruct
Data_Structure
Data_Structure_24793_I
### Question: Enhance and Analyze Bogo Sort #### Context You are asked to implement and enhance a sorting algorithm known as Bogo Sort. Given its inefficiency, your task will also involve analyzing the performance under various conditions to understand and demonstrate its impracticality for real-world sorting tasks. ...
import random from typing import List, Tuple def is_sorted(arr: List[int]) -> bool: """Helper function to check if the array is sorted.""" for i in range(len(arr) - 1): if arr[i] > arr[i + 1]: return False return True def bogo_sort(arr: List[int], simulation: bool = False) -> Tuple[Lis...
from solution import bogo_sort def test_bogo_sort_with_simulation(): sorted_array, iterations, shuffles = bogo_sort([3, 2, 1], simulation=True) assert sorted_array == [1, 2, 3] assert iterations > 0 assert shuffles > 0 def test_bogo_sort_with_empty_array(): sorted_array, iterations, shuffles = bog...
[ { "docstring": "Helper function to check if the array is sorted.", "function_declaration": "def is_sorted(arr):", "function_name": "is_sorted", "parameter_list": "(arr)" }, { "docstring": "Sort the array using Bogo Sort algorithm.\n\nParameters:\n arr (List[int]): The array to sort.\n ...
[ 1, 1, 1 ]
3
easy
1
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "import random\nfrom typing import List, Tuple\n\ndef is_sorted(arr: List[int]) -> bool:\n for i in range(len(arr) - 1):\n if arr[i] > arr[i + 1]:\n ...
trial_gpt4o_2
{ "original_instruction": "", "prompt_id": "00024793", "row_id": 24793, "seed_ids": "[16]" }
0.578585
Data_Structure_24793
I
[ "is_sorted", "bogo_sort" ]
2
[ [ "bogo_sort", "is_sorted" ] ]
1
[]
false
[]
false
pytest
true
[]
true
782731a5a2d6416540fa30f533c5208a3b4c3bcf
46e1547e14b75e6f6e8c21f9c6b374f3dd2911b0
v1.0
instruct
Data_Structure
Data_Structure_24865_I
Secure Communication using Diffie-Hellman Key Exchange **Scenario**: Alice and Bob wish to communicate securely over an unencrypted channel. They decide to use the Diffie-Hellman key exchange algorithm to establish a shared secret key. **Task**: Write a Python function `secure_shared_key(g, p)` that: 1. Confirms whe...
def is_prime(n): """ Efficiently checks if a number n is prime. """ if n <= 1: return False if n <= 3: return True if n % 2 == 0 or n % 3 == 0: return False i = 5 while i * i <= n: if n % i == 0 or n % (i + 2) == 0: return False i += 6 ...
def test_is_prime(): assert is_prime(23) == True assert is_prime(24) == False assert is_prime(2) == True assert is_prime(1) == False assert is_prime(29) == True def test_find_primitive_root(): assert find_primitive_root(23) != None # should return a valid primitive root assert find_primiti...
[ { "docstring": "Efficiently checks if a number n is prime.", "function_declaration": "def is_prime(n):", "function_name": "is_prime", "parameter_list": "(n)" }, { "docstring": "Finds a primitive root modulo p. Returns None if no such root exists.", "function_declaration": "def find_primi...
[ 0, 0, 0, 0, 1, 0, 0, 0, 1, 1 ]
3
hard
0.3
{ "trial_gpt4o_0": { "file_source": "CodeGen_instruction_data_structure_50000_1740122759_sanitized_prepared0_results_combined.jsonl", "solution_code": "def is_prime(n):\n \"\"\"Returns True if n is a prime number.\"\"\"\n if n <= 1:\n return False\n if n <= 3:\n return True\n if n % ...
trial_gpt4o_8
{ "original_instruction": "", "prompt_id": "00024865", "row_id": 24865, "seed_ids": "[146]" }
0.458241
Data_Structure_24865
I
[ "is_prime", "find_primitive_root", "prime_factors", "diffie_hellman", "secure_shared_key" ]
5
[ [ "find_primitive_root", "is_prime" ], [ "find_primitive_root", "prime_factors" ], [ "secure_shared_key", "diffie_hellman" ], [ "secure_shared_key", "find_primitive_root" ], [ "secure_shared_key", "is_prime" ] ]
5
[]
false
[]
false
pytest
false
[]
true
142b9254325222b1b41a324377c13c80f1eef2ae
8ef533aa2dd46ca3d49053d8db5bfacdb9b78ace