Computing revision - Linear and Binary searches

Descrição

Flashcards
Dean Owen
FlashCards por Dean Owen, atualizado more than 1 year ago
Dean Owen
Criado por Dean Owen mais de 2 anos atrás
10
0
1 2 3 4 5 (0)

Resumo de Recurso

Questão Responda
How does a linear search check for a selected item? A linear search checks each item of the list in order to see if it is the item it's looking for.
What is an advantage of using a linear search? It is much simpler than a binary search.
What are the disadvantages of a linear search? - Due to its inefficiency, the linear search is usually only used on small lists. - If it is a large list of items, the item you are looking for can take a long period of time to be found.
If I had Chocolate, Butterscotch, Vanilla and Strawberry, and I wanted to find Strawberry using a linear search, what would the program look like? It would look like: Chocolate ≠ Strawberry Butterscotch ≠ Strawberry Vanilla ≠ Strawberry Strawberry = Strawberry ITEM FOUND
What does a Binary Search look for items in? They look for items in ordered lists.
What is an advantage of a binary search? A binary search is much more efficient than a linear search; it takes fewer steps to search for an item.
If I had 9 items in a list, what would the first step be? The first step would be to find the middle term.
How do you do the first step? To find the middle item in the list of 9 items, you would: - Do 9 + 1 (= 10) - Divide that number (10) by 2 (10/2) = 5 - The answer to the sum above (5) will be the middle term (this means that the 5th term is the middle term in this case).
What's the second step? If it's the item that is being looked for, stop the search because you've found it. If not, carry on to step 3.
What's the third step? If the item is not the middle term, compare it to the middle term; if it is above the middle term, remove the first half of the list, but if it's below the middle term, remove the second half of the list.
What's the fourth step? The list will be half the size of the original list, so you can repeat steps 1 and 3 until you find the item that is being searched for.
What is a disadvantage of binary searches? They are more complex than linear searches.

0 comentários

There are no comments, be the first and leave one below:

Semelhante

2. Poderes administrativos
marcusmoskao
Direito Civil - Personalidade Jurídica
Lucas Ávila
SUBSTANTIVOS
Viviana Veloso
CONCURSO BANCO DOBRASIL- ESCRITURÁRIO
Alessandra S.
Histologia Humana - Tecido Epitelial
Marcella F. Brunhara
5 Passos para Aprendizagem de Sucesso
GoConqr suporte .
Acentuação gráfica
Lúcia Amaral
SIMULADÃO EA-HSG FATOS DA HISTÓRIA NAVAL PARTE 2
isac rodrigues
EA-HSG-2015 Questões achadas no app QUIZADA na playstore
carloshenriquetorrez .
PROCESSO LEGISLATIVO
Mateus de Souza