-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add Quicksort Specific Checks - Pivot Selection Patterns - Element Swapping Patterns (Done) - Complexity analysis add for quicksort detector (Done) - Implementation of Confidence Calculation for robust detection (Done) -Add Test Cases for Quicksort (Done)
- Loading branch information
1 parent
7be2185
commit 10dc47b
Showing
4 changed files
with
111 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
25 01 25 | ||
27 01 25 | ||
- Complexity Analysis Mindmap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
|
||
def partition(arr, low, high): | ||
pivot = arr[high] | ||
i = low - 1 | ||
for j in range(low, high): | ||
if arr[j] <= pivot: | ||
i += 1 | ||
arr[i], arr[j] = arr[j], arr[i] | ||
arr[i+1], arr[high] = arr[high], arr[i+1] | ||
return i+1 | ||
|
||
def quicksort(arr, low=0, high=None): | ||
if high is None: | ||
high = len(arr) - 1 | ||
if low < high: | ||
pi = partition(arr, low, high) | ||
quicksort(arr, low, pi-1) | ||
quicksort(arr, pi+1, high) | ||
# tests/test_quicksort.py | ||
TEST_CASES = [ | ||
{ | ||
"code": """ | ||
def quicksort(arr): | ||
if len(arr) <= 1: return arr | ||
pivot = arr[0] | ||
less = [x for x in arr[1:] if x <= pivot] | ||
greater = [x for x in arr[1:] if x > pivot] | ||
return quicksort(less) + [pivot] + quicksort(greater) | ||
""", | ||
"expected": True, | ||
"complexity": "O(n log n)" | ||
}, | ||
{ | ||
"code": """ | ||
def fake_sort(arr): # Looks like quicksort but isn't | ||
if len(arr) < 2: return arr | ||
mid = arr[len(arr)//2] | ||
left = [x for x in arr if x < mid] | ||
right = [x for x in arr if x > mid] | ||
return fake_sort(left) + [mid] + fake_sort(right) | ||
""", | ||
"expected": False | ||
} | ||
] |