Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Sprint Challenge: Algorithms


///////////////////////////////////////////////////////////////////////////////////////////
////////// https://github.com/LambdaSchool/Sprint-Challenge--Algorithms/pull/443 /////////
///////////////////////////////////////////////////////////////////////////////////////////



In this week's Sprint you explored and implemented some classic algorithmic approaches and used them to solve novel problems. You also implemented some classic and fundamental sorting algorithms and learned how to go about evaluating their respective runtimes and performance. This Sprint Challenge aims to assess your comfort with these topics through exercises that build on the algorithmic intuition you've started to build up.

## Instructions
Expand Down
12 changes: 12 additions & 0 deletions Short-Answer/Algorithms_Answers.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@

a)

This is a clear example of 0(n), we are utilizing the while loop to add an iterator that executes a sequence of statements this also executes the N times, we understand that it is being multiplied by each iteration.


b)

Clearly another while loop 0(n^2) that is nested , you will notice a curve in runtime as the numbers increase, in order for this to work we need to consider the iteration of inner and outer loops, we can also understand that each loop will produce a new number each time.



c)

This is clearly and example of BigO 0(n) again, as this is a recursive function it will call itself (N) times.


## Exercise II

This is interesting, when thinking on the amount of eggs I would break so I would start on F floor, however, we can use 0(n) and this will allow us to iterate through each floor until an egg breaks.

We can also assume that we can use a BST if we are looking to limit the numbers of eggs we lose.

I can not think of any quicker way then to use a complexity of 0(log n), this is the way to go to solve this problem.
17 changes: 13 additions & 4 deletions recursive_count_th/count_th.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@
Your function should return a count of how many occurences of ***"th"*** occur within `word`. Case matters.
Your function must utilize recursion. It cannot contain any loops.
'''


def count_th(word):

# TBC

pass
count = 0

if len(word) < 2:
return 0

if word[0] == 't' and word[1] == 'h':
count += 1

count += count_th(word[1:])

return count
23 changes: 21 additions & 2 deletions robot_sort/robot_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,27 @@ def sort(self):
"""
Sort the robot's list.
"""
# Fill this out
pass
## MY SOLUTION STARTS HERE

self.set_light_on()
while self.light_is_on():
self.set_light_off()
while self.can_move_right():
self.swap_item()
self.move_right()
if self.compare_item() == 1:
self.swap_item()
self.move_left()
self.swap_item()
self.move_right()
self.set_light_on()
else:
self.move_left()
self.swap_item()
self.move_right()
while self.can_move_left():
self.move_left()



if __name__ == "__main__":
Expand Down