Stats: 3,190,083 members, 7,939,379 topics. Date: Wednesday, 04 September 2024 at 01:28 AM |
Nairaland Forum / Science/Technology / Programming / Criticize My Algorithm (1004 Views)
Forex Market Algorithm IPDA part 2 / Please Guys Help Me Criticize My New Forum Site Design / Thread For Nairaland Algorithm Questions (2) (3) (4)
Criticize My Algorithm by Nobody: 3:16pm On Mar 26, 2020 |
Hey Gurus in d house they is a python script am working on that makes make manipulation of scripts easy although python has it on easy methods to do so bt i had to re-invent d wheel with a couple of algorithm implemnetation i just want you guyz to help me scrutinize nd check my codes nd show me where i can improve on You can DM me on whatsapp using this number 07013927220 to talk or just check the code here from math import floor ##please## class LMM: def __init__(self,list): self.list=list def print(self): for i in self.list: print(i) def Add(self,index,item): indx=index length=len(list)-1 self.list+=[0] while length>=indx: self.list[length+1]=self.list[length] length-=1 self.list[indx]=item return self.list def Remove(self,index): tempindx=index indx=index self.list[tempindx]=self.list[tempindx+1] self.list.remove(self.list[indx]) return self.list def Sort(self): length=len(list)-1 for turns in range(length): for i in range(length): if self.list[i]>self.list[i+1]: tempdata=self.list[i] self.list[i]=self.list[i+1] self.list[i+1]=tempdata return self.list def Reverse(self): listx=[] for i in range(len(self.list)-1,-1,-1): listx.append(self.list[i]) return listx def Index(self,num): for i in range(len(self.list)): if self.list[i]==num: return i def Bindex(self,num): LB=0 UB=len(self.list)-1 Found=None while Found==None: if LB>UB: print("The number {} does not exist".format(num)) break Mid=floor((LB+((UB-LB)/2))) if self.list[Mid]<num: LB=Mid+1 if self.list[Mid]>num: UB=Mid-1 if self.list[Mid]==num: #print("Found {} at index:{}".format(num,Mid)) Found=True break return Mid list=[1,2,3,4,5,6,7,8] LMM=LMM(list) a=LMM.Bindex(7) print(a) Thanks ur for time |
Re: Criticize My Algorithm by Shepherdd(m): 3:31pm On Mar 26, 2020 |
Can you upload this as a GitHub gist and post a link. It's kinda hard to read because of Python's indentation. |
Re: Criticize My Algorithm by Nobody: 3:34pm On Mar 26, 2020 |
Shepherdd: Sorry don't knw hw to wrk github that's y i left my number |
Re: Criticize My Algorithm by Shepherdd(m): 3:54pm On Mar 26, 2020 |
By mere going through the code like that I could observe that your code will run in O(N²) quadratic time which simply translates that as your input increases the time the algorithm takes doubles. The bubble sort is algorithm is a good example of this. Your search method I think is doing a binary search but you fail to account for the fact that binary search only works on a sorted array. Try and add a line inside the search method to sort the array first. If you feel comfortable with Python you could replace your sort method with a merge sort implementation which is very acceptable as it has a linear time O(n) worst case scenario. There is a fairly correct saying that for loops are evil. Try and replace for loops with functional programming methods like filter, reduce e.t.c with Python lambda. But all in all bravo to you for even trying to code this as many programmers only care about data types and algorithm a week to an interview. 2 Likes |
Re: Criticize My Algorithm by Shepherdd(m): 4:14pm On Mar 26, 2020 |
Also try and work on your variable naming and comments keeping in mind that you won't be the only one working with your code and even you after some years might find it hard to figure what a line does when you don't have good variable names and concise comments. |
Re: Criticize My Algorithm by Nobody: 4:58pm On Mar 26, 2020 |
Shepherdd: Thanks � |
Re: Criticize My Algorithm by Nobody: 5:02pm On Mar 26, 2020 |
Shepherdd: Noted |
Re: Criticize My Algorithm by damtan(m): 5:43pm On Mar 26, 2020 |
I've been searching for a link to download Python environment on my system for practice. I wanna start learning to code and all. Can anyone be of help please? |
Re: Criticize My Algorithm by Anonime1105(m): 8:15pm On Mar 26, 2020 |
damtan: Visit Python.org the official python programming language website |
(1) (Reply)
2021 Magico Box / Practical Guide For Newbies That Wants To Learn How To Code. / How Much To Charge To Build A Custom Mobile App In 2021?
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 21 |