Home > SparkNotes > Computer Science Study Guides > Linear >

sparknotes

Linear Search


Problems

Problem : You are given an array of linked lists (each element in the array points to a linked list), as follows:


typedef struct _list_t_ {
	int data;
	struct _list_t_ *next;
} list_t;

list_t *arr[100];
Write a function to find the largest data element in any of the lists.


Problem : You are given a malformed linked list in which one of the list element's next pointer points back to the same element. Write a function to return a pointer to the list structure with the incorrect next pointer.


Problem : You are given a pointer to somewhere in the middle of a doubly-linked list of integers:


typedef struct _list_t_ {
	int data;
	struct _list_t_ *next;
	struct _list_t_ *prev;
} list_t;


Find the largest element in the list.


Problem : If a linked list were in sorted order, would you be able to write a search routine that worked in less than $O(n)$ time?


Problem : Given a singly-linked list, return a pointer to the first element whose data field is less than or equal to the data element of the last value in the list.