changed to only single for loop in quick for to reduce time complexity. thanks to mr. lalit hinduja

This commit is contained in:
K 2023-12-11 09:47:09 +05:30
parent d8ad39d234
commit 3a6ad7c77f
Signed by: notkshitij
GPG Key ID: C5B8BC7530F8F43F

View File

@ -12,16 +12,14 @@ def quickSort(arr):
''' '''
## ALTERNATIVE WAY OF WRITING THE UPPER 3 LINES (for easy understanding) ## ALTERNATIVE WAY OF WRITING THE UPPER 3 LINES (for easy understanding)
left = [] # Empty list to store left part left = [] # Empty list to store left part
middle = [] # Empty list to store middle element
right = [] # Empty list to store right part
for i in arr: for i in arr:
if (i < pivot): if (i < pivot):
left.append(i) left.append(i)
middle = [] # Empty list to store middle element elif (i == pivot):
for i in arr:
if (i == pivot):
middle.append(i) middle.append(i)
right = [] # Empty list to store right part else:
for i in arr:
if (i > pivot):
right.append(i) right.append(i)
''' '''
@ -47,4 +45,4 @@ def main():
# Calling main function: # Calling main function:
main() main()
# END OF CODE # END OF CODE