Consider the following function for linear search that takes a list of elements sorted in increasing order and an element to search in the list. def search_inc(alist, elem): for i in range(len(alist)): if alist[i] == elem: return True if alist[i] > elem: return False return False Consider the following code, which is an alternative version of search_inc. def search_inc3(alist, elem): if alist[0] == elem: return True elif alist[0] > elem: return False else: return search_inc3(alist[1:], elem) : Which of the following statements is correct? You may assume that each function is tested with a list alist whose elements are sorted in increasing order. For simplicity, assume alist is a list of integers. Question 5 options: search_inc and search_inc3 return the same answers search_inc and search_inc3 do not return the same answers. search_inc and search_inc3 return the same answers for lists of length 0 and 1 only. search_inc and search_inc3 return the same answers provided L is non-empty and e is in L. search_inc and search_inc3 return the same answers provided L is non-empty.
Types of Linked List
A sequence of data elements connected through links is called a linked list (LL). The elements of a linked list are nodes containing data and a reference to the next node in the list. In a linked list, the elements are stored in a non-contiguous manner and the linear order in maintained by means of a pointer associated with each node in the list which is used to point to the subsequent node in the list.
Linked List
When a set of items is organized sequentially, it is termed as list. Linked list is a list whose order is given by links from one item to the next. It contains a link to the structure containing the next item so we can say that it is a completely different way to represent a list. In linked list, each structure of the list is known as node and it consists of two fields (one for containing the item and other one is for containing the next item address).
Consider the following function for linear search that takes a list of elements sorted in increasing order and an element to search in the list.
Consider the following code, which is an alternative version of search_inc.
:
Which of the following statements is correct? You may assume that each function is tested with a list alist whose elements are sorted in increasing order. For simplicity, assume alist is a list of integers.
Question 5 options:
|
search_inc and search_inc3 return the same answers |
|
search_inc and search_inc3 do not return the same answers. |
|
search_inc and search_inc3 return the same answers for lists of length 0 and 1 only. |
|
search_inc and search_inc3 return the same answers provided L is non-empty and e is in L. |
|
search_inc and search_inc3 return the same answers provided L is non-empty. |
Step by step
Solved in 3 steps with 1 images