linear

Cards (32)

  • best-case scenario: smallest possible number of steps eg 1st in list
  • worse-case scenario:largest possible number of steps eg last in list
  • Linear Search sequentially checks each element in the list until it finds a match or exhausts the list
  • What is a linear search?
    A method to iterate through a collection
  • What is the runtime complexity of a linear search?
    Big O of n
  • How does the size of the data set affect a linear search?
    The number of steps increases proportionately
  • What is a disadvantage of a linear search?
    They are slow for large data sets
  • What is an advantage of a linear search?
    They are fast for small to medium data sets
  • What type of data structures are linear searches useful for?
    Data structures without random access
  • What is the basic structure of a linear search function?
    • Loop through the array
    • Check each element against the value
    • Return the index if found
    • Return -1 if not found
  • What is the initial value of the index in a linear search?
    Zero
  • What happens if the value is found in a linear search?
    The index of the value is returned
  • What is returned if the value is not found in a linear search?
    Negative one
  • What will the output be if searching for the number ten?
    Element not found
  • What are the key characteristics of a linear search?
    • Iterates through elements one at a time
    • Slow for large data sets
    • Fast for small to medium data sets
    • Does not require sorted data
  • Why is it beneficial that linear searches do not need sorted data?
    It simplifies the search process
  • How does a linear search compare to binary and interpolation searches?
    Linear searches do not require sorted data
  • What type of search is described in the study material?
    Linear search
  • What are the steps of the linear search algorithm?
    1. Start at the beginning of the list.
    2. Check each item one at a time.
    3. If the current item is the target, stop.
    4. If the end of the list is reached without finding the target, conclude it is not present.
  • What should you do at the beginning of the linear search?
    Start at the beginning of the list
  • How does the linear search check items?
    It checks each item one at a time
  • What happens if the current item is the target during a linear search?
    You stop the search
  • What should you do if you reach the end of the list without finding the target?
    Conclude it is not present
  • What are the key characteristics of a linear search?
    • Simple and straightforward
    • Checks each item sequentially
    • Inefficient for large datasets
    • Best for small or unsorted lists
  • What is the stopping condition for the linear search?
    Finding the target item or reaching the end
  • What does it mean if the current item is the target during the search?
    It matches the item you are looking for
  • What is the final step if the target is found?
    Stop the search
  • What is the significance of the term "target" in the context of the linear search?
    It refers to the item being searched for
  • How does the linear search algorithm handle large datasets?
    It becomes inefficient
  • What is the main limitation of a linear search?
    It is inefficient for large datasets
  • Why might a linear search be preferred for small lists?
    It is simple and straightforward
  • What is the overall process of a linear search?
    Sequentially check each item until found