• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# fds

a guest Apr 26th, 2019 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. import random
2.
3. def BinSearch(li, x):
4.     t = 0
5.     if1 = 0
6.     else1 = 0
7.     i = 0
8.     j = len(li)-1
9.     m = int(j/2)
10.     while li[m] != x and i < j:
11.         t += 1
12.         if x > li[m]:
13.             if1 += 1
14.             i = m+1
15.         else:
16.             else1 += 1
17.             j = m-1
18.         m = int((i+j)/2)
19.     if i > j:
20.         print(t)
21.         print(if1)
22.         print(else1)
23.         return 'Не найдено'
24.     else:
25.         print(t)
26.         print(if1)
27.         print(else1)
28.         return m
29.
30. def quicksort(nums):
31.    if len(nums) <= 1:
32.        return nums
33.    else:
34.        q = random.choice(nums)
35.        s_nums = []
36.        m_nums = []
37.        e_nums = []
38.        for n in nums:
39.            if n < q:
40.                s_nums.append(n)
41.            elif n > q:
42.                m_nums.append(n)
43.            else:
44.                e_nums.append(n)
45.        return quicksort(s_nums) + e_nums + quicksort(m_nums)
46.
47. arr = [random.randint(0, 10000) for i in range(1000000)]
48.
49.
50. arr = quicksort(arr)
51.
52. print(BinSearch(arr, 55))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top