Back to marketplace

Search routines (paper 2)

No description yet. This curated deck is ready for daily study.

Total cards: 5•Content version: v4•Public deck•Updated: 8/1/2026

Card preview (5)

#1
Front (Question)

what happens in a linear search

Back (Answer)

each item to be searched from will be checked one by one in the list until the item is found or an error is outputted

#2
Front (Question)

what are the two types of search

Back (Answer)

• linear • bubble sort

#3
Front (Question)

What is the code for a linear search algorithm

Back (Answer)

// perform a linear search of an array DECLARE AList : ARRAY[1:10] OF INTEGER AList <- [14, 2, 3 ,11, 1, 9, 5, 8, 10, 6] OUTPUT “List to be searched:”, AList Found <- FALSE Index <- 1 INPUT SearchItem WHILE Found = FALSE AND Index <= LENGTH(AList) DO IF AList[Index] = SearchItem THEN Found <- TRUE ELSE Index <- Index + 1 ENDIF ENDWHILE IF Found = TRUE THEN OUTPUT SearchItem, “in position”, Index, “of the list” ELSE OUTPUT “Item not found” ENDIF

#4
Front (Question)

what happens in a bubble sort

Back (Answer)

it repeatedly goes through the list to be sortedd, swapping adjacent elements if they are in the wrong order

#5
Front (Question)

what is the pseudocode for a bubble sort

Back (Answer)

//bubble sort with flag set when no swaps are made AList <-[17, 3, 7, 15, 12, 23, 20] // get number of items in the array NumItems <- LENGTH(AList) Comparisions <- NumItems - 1 SwapMade <- TRUE WHILE Comparisons > 0 AND SwapMade = TRUE SwapMade <- FALSE FOR i <- 1 TO Comparisons IF AList[i] > AList[i + 1] THEN Temp <- AList[i] AList[i] <- AList[i + 1] AList[i + 1] <- Temp SwapMade <- TRUE ENDIF NEXT i Comparisons <- Comparisons - 1 ENDWHILE OUTPUT “Sorted list: “, AList