Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

NAME: JOSHUA NZIOKA

DEGREE: BACHELOR OF BUSINESS INFORMATION TECHNOLOGY


QN1.Demonstrate linear search using singly linked lists.
Linear search is a basic searching algorithm that sequentially checks each element in a list or array until it
finds the target element or reaches the end of the list

➢ Singly linked lists:

In a singly linked list, linear search can be performed by starting at the head of the list and iterating

through each node until the target element is found or the end of the list is reached. If the target
element is found, the search is successful, and the index of the element is returned. Otherwise, the
search continues until the end of the list is reached.

Example;

Class Node:
def_init_ (self, data):
Self.head=data
Self.head=None
Class LinkedList:
def_init_(self):
self. head=None
def_Linear Search (self, target);
Current = self. head
While current is not None:
If current. Data==target:
return current
current=current. Next
Return None

You might also like