Last active
September 25, 2018 14:02
-
-
Save deshmukhrajvardhan/f7de3ae29022dbdd945258e0d34fbb84 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Q2 | |
# to denote ayymptotic time complexity use the following notation | |
# O(l) O(m) O(a) O(b) | |
# e.g. traversing through l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] is O(l) | |
#1 | |
def merge(): | |
l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
m = [15, 16, 17, 18] | |
lm = [] | |
for l_i in l: | |
lm.append(l_i) | |
for m_i in m: | |
lm.append(m_i) | |
print("lm:{}".format(lm)) | |
#2 | |
def merge_a_lot(): | |
l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
m = [15, 16, 17, 18] | |
lm = [] | |
for l_i in l: | |
lm.append(l_i) | |
for m_i in m: | |
lm.append(m_i) | |
print("lm:{}".format(lm)) | |
#3 | |
def go_through(): | |
l = 10 | |
lm = [] | |
while l>0: | |
lm.append(l) | |
l=int(l/2) | |
print("lm:{}".format(lm)) | |
#4 | |
def go_through_two(): | |
l = 10 | |
m = 5 | |
lm = [] | |
while l > 0: | |
lm.append(l) | |
l = int(l/2) | |
m1=1 | |
while m1*m1 <= m: | |
print("in") | |
lm.append(m1) | |
m1 +=1 | |
print("lm:{}".format(lm)) | |
#5 | |
def go_through_cross_two(): | |
l = 10 | |
m = 5 | |
lm = [] | |
while l*l > 1: | |
lm.append(l) | |
l -= 1 | |
m1 = 1 | |
while m1*m1 <= m: | |
lm.append(m1) | |
m1 += 1 | |
print("lm:{}".format(lm)) | |
#6 | |
def times(): | |
a=100 | |
b=5 | |
sum=b | |
count=0 | |
while sum<=a: | |
sum+=b | |
count+=1 | |
print("count:{}".format(count)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment