GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — algorithms/sort/comb_sort.py at master · RajaRamu/algorithms

Expand file tree

/

comb_sort.py

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
41 lines (30 loc) · 742 Bytes
/

comb_sort.py

Copy path

File metadata and controls

41 lines (30 loc) · 742 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
https://en.wikipedia.org/wiki/Comb_sort
Worst-case performance: O(N^2)
"""
from math import floor
def comb_sort(arr):
def swap(i, j):
arr[i], arr[j] = arr[j], arr[i]
n = len(arr)
gap = n
shrink = 1.3
sorted = False
while not sorted:
gap = int(floor(gap/shrink))
if gap > 1:
sorted = False
else:
gap = 1
sorted = True
i = 0
while i + gap < n:
if arr[i] > arr[i + gap]:
swap(i, i + gap)
sorted = False
i = i + 1
array = [1, 5, 65, 23, 57, 1232, -1, -5, -2, 242, 100,
4, 423, 2, 564, 9, 0, 10, 43, 64, 32, 1, 999]
print(array)
comb_sort(array)
print(array)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.