0
0
DSA Typescriptprogramming~5 mins

Linear Search Algorithm in DSA Typescript - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the main idea behind the Linear Search Algorithm?
Linear Search checks each item in a list one by one until it finds the target or reaches the end.
Click to reveal answer
beginner
What is the time complexity of Linear Search in the worst case?
The worst-case time complexity is O(n), where n is the number of items in the list.
Click to reveal answer
intermediate
In which scenario is Linear Search preferred over other search algorithms?
When the list is small or unsorted, Linear Search is simple and effective without extra setup.
Click to reveal answer
beginner
What does Linear Search return if the target is not found in the list?
It returns -1 or a special value indicating the target is not present.
Click to reveal answer
beginner
Show a simple TypeScript code snippet for Linear Search.
function linearSearch(arr: number[], target: number): number {
  for (let i = 0; i < arr.length; i++) {
    if (arr[i] === target) {
      return i;
    }
  }
  return -1;
}
Click to reveal answer
What does Linear Search do when it finds the target element?
ASorts the list
BStops and returns the index of the target
CContinues searching the entire list
DDeletes the target element
What is the best case time complexity of Linear Search?
AO(n log n)
BO(n)
CO(log n)
DO(1)
Which of these lists is Linear Search most suitable for?
AA large sorted list
BA hash table
CA small unsorted list
DA balanced binary search tree
If the target is not in the list, what does Linear Search return?
A-1
B0
CThe last index
DThe length of the list
How does Linear Search check elements in the list?
AOne by one from start to end
BRandomly
CFrom the middle to the ends
DUsing binary splitting
Explain how Linear Search works step-by-step on a list of numbers.
Think about looking for a name in a phone book by checking every entry.
You got /4 concepts.
    Describe when you would choose Linear Search over other search methods.
    Consider situations where sorting or complex structures are not worth the effort.
    You got /4 concepts.