forked from duliodenis/mit-6.0001-intro-cs-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlec10_complexity_part1.py
52 lines (43 loc) · 947 Bytes
/
lec10_complexity_part1.py
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
42
43
44
45
46
47
48
49
50
51
52
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 9 11:27:54 2016
@author: ericgrimson
"""
def linear_search(L, e):
found = False
for i in range(len(L)):
if e == L[i]:
found = True
return found
testList = [1, 3, 4, 5, 9, 18, 27]
def search(L, e):
for i in range(len(L)):
if L[i] == e:
return True
if L[i] > e:
return False
return False
def isSubset(L1, L2):
for e1 in L1:
matched = False
for e2 in L2:
if e1 == e2:
matched = True
break
if not matched:
return False
return True
testSet = [1, 2, 3, 4, 5]
testSet1 = [1, 5, 3]
testSet2 = [1, 6]
def intersect(L1, L2):
tmp = []
for e1 in L1:
for e2 in L2:
if e1 == e2:
tmp.append(e1)
res = []
for e in tmp:
if not(e in res):
res.append(e)
return res