Skip to content

Done precourse2 #1751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions Exercise_1.cpp

This file was deleted.

21 changes: 0 additions & 21 deletions Exercise_1.java

This file was deleted.

16 changes: 0 additions & 16 deletions Exercise_1.js

This file was deleted.

38 changes: 28 additions & 10 deletions Exercise_1.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
""""
// Time Complexity :O( log n)
// Space Complexity :O(1)
// Did this code successfully run on Leetcode :
// Any problem you faced while coding this :


// Your code here along with comments explaining your approach


"""


# Python code to implement iterative Binary
# Search.

# It returns location of x in given array arr
# if present, else returns -1
def binarySearch(arr, l, r, x):

#write your code here



while l <= r:
mid = l + (r - l) // 2 # Avoids overflow compared to (l + r) // 2
if arr[mid] == x:
return mid
elif arr[mid] < x:
l = mid + 1
else:
r = mid - 1
return -1

# Test array
arr = [ 2, 3, 4, 10, 40 ]
arr = [2, 3, 4, 10, 40]
x = 10

# Function call
result = binarySearch(arr, 0, len(arr)-1, x)

if result != -1:
print "Element is present at index % d" % result
print("Element is present at index %d" % result)
else:
print "Element is not present in array"
print("Element is not present in array")
47 changes: 0 additions & 47 deletions Exercise_2.cpp

This file was deleted.

48 changes: 0 additions & 48 deletions Exercise_2.java

This file was deleted.

41 changes: 0 additions & 41 deletions Exercise_2.js

This file was deleted.

17 changes: 16 additions & 1 deletion Exercise_2.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@

# Python program for implementation of Quicksort Sort

# give you explanation for the approach
def partition(arr,low,high):
pivot = arr[high] # Last element as pivot
i = low - 1 # Index of smaller element

for j in range(low, high):
if arr[j] <= pivot:
i += 1
arr[i], arr[j] = arr[j], arr[i] # Swap

arr[i + 1], arr[high] = arr[high], arr[i + 1] # Place pivot in the middle
return i + 1


#write your code here


# Function to do Quick sort
def quickSort(arr,low,high):
def quickSort(arr,low,high):
if low < high:
pi = partition(arr, low, high)
quickSort(arr, low, pi - 1)
quickSort(arr, pi + 1, high)

#write your code here

Expand Down
50 changes: 0 additions & 50 deletions Exercise_3.cpp

This file was deleted.

53 changes: 0 additions & 53 deletions Exercise_3.java

This file was deleted.

Loading