Today, I have learned about searching algorithms in Binary Search Trees. It is important to keep track of certain elements if the Trees consist of hundreds or even thousands or elements per tree. I am reviewing selection and the best and worst case insertion algorithms and even trying to find possible ways of binary searching. The assignment two which involves regexes to return True of False or permuations, will require many huge lists and recursive structures to generate desired results. So this is what I have learned in class and I hope I learn more throughout my practices, even though they are not easy to do.
I am trying to put examples in my blogs to show what I know and I hope I can use this knowledge to improve my works. I do try and write this information down on paper and put that into my computer, sometimes I need to change things and it gets tiring and bothersome to get the code working.
Here are some attempted pseudocodes to get the general idea of searching algorithms used in lists and trees.
def selection (list) -> sorted list:
""" Takes the first element of the list and compares it to the . This process is repeated and the left side of the tree remains unchanged as it is sorted and reaches n-1 elements and ensures the last one is the same sorted one. By selecting the smallest number and swap it with the n position.
"""
def insertion (list) -> sorted list:
""" Takes the first list and . The problem is that there exists a worst case scenario that is very inefficient and takes up quite a bit of memory. Usually the worst case insertion performs hundreds to the power of hundreds of tasks to sort out a list, whereas the best case takes the shortest. Insertion usually requires take i position and insert it into leftmost i + 1 position without touching the right positions, the opposite direction.
"""
def searchlist(list, number) -> bool:
""" Takes a list and finds the number in the list, if the number is not there, it returns False. usually by splitting
the given list into two lists, left and right, and searches for the number in both lists using recursion
"""
middle = len(list) / 2
max = max(the middle index, left and right index)
min = min(the middle index, left and right index)
if number is in list[middle], list[middle - 1] or list[element after middle]:
return True;
if x is in left list:
searchlist(of left list[0 : left element of middle], number);
elif x is in right list:
searchlist(of right list[right element: last element], number);
else:
return False;
No comments:
Post a Comment