-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lecture "Brute-force algorithms", exercise 1 #15
Comments
|
A linear search finds a value in a list and then return its position.
|
|
def linear_search(input_list, value_to_search): list_of_books = list(["Coraline", "American Gods", "The Graveyard Book", "Good Omens", "Neverwhere"]) #enumerate(list_ of_books) will result in: # enumerate ([(0, "Coraline"), (1, "American Gods"), # (2, "The Graveyard Book"), (3, "Good Omens"), # (4, "Neverwhere")]) #Iteration 1 #Iteration 2 #Iteration 3 #Iteration 4 #Iteration 5 Output: None |
linear_search(list(["Coraline", "American Gods", "The Graveyard Book", "Good Omens", "Neverwhere"]), "The Sandman")
#the algorithm will run in the following way: #Iteration 2 #Iteration 3 #Iteration 4 #Iteration 5 Output: None |
#function to enumerate the list #creating the list #enumerate ([0, "Coraline", 1 "American Gods", 2 "The Graveyard Book", 3 "Good Omens", 4, "Neverwhere"])) linear_search(list_of_books, "The Sandman") #iterate 1 #iterate 2 #iterate 3 #iterate 4 #iterate 5 Return None |
def linear_search (input_list, value_to_search): #Iteration 1 #Iteration 2 #Iteration 3 #Iteration 4 #Iteration 5 Output: None |
|
Iteration 1 # Iteration 2 Iteration 3 # Iteration 4 Iteration 5 |
Write down the execution steps of
linear_search(list(["Coraline", "American Gods", "The Graveyard Book", "Good Omens", "Neverwhere"]), "The Sandman")
, as explained in Listing 7.The text was updated successfully, but these errors were encountered: