in DS recategorized by
22,965 views
35 votes
35 votes

Linked lists are not suitable data structures for which one of the following problems?

  1. Insertion sort

  2. Binary search

  3. Radix sort

  4. Polynomial manipulation

in DS recategorized by
23.0k views

2 Comments

How is it helpful in case of other algorithms?
0
0
@Adiaspirant My ans may address ur concern.
1
1

4 Answers

43 votes
43 votes
Best answer

Linked lists are suitable for:

Insertion sort: No need to swap here just find appropriate place and join the link

Polynomial manipulation: Linked List is a natural solution for polynomial manipulation 

Radix sort: Here we are putting digits according to same position(unit,tens) into  buckets; which can be effectively handled by linked lists.

Not Suitable for:

Binary search: Because finding mid element itself takes $O(n)$ time.

So, Option B is answer.

edited by

3 Comments

B also because Binary Search requires random access which isn't possible in case of Binary Search.
0
0

Binary Search on Singly Linked List takes $O(n)$ time.

Ref: https://www.geeksforgeeks.org/binary-search-on-singly-linked-list/

3
3

About Polynomial Manipulation taken from rohini_98345869271.pdf (rcet.org.in):- 

Consider a polynomial $6x^3 + 9x^2 + 7x + 1$. Every individual term in a polynomial consists of two parts, a coefficient and a power. Here, $6, 9, 7, and \ 1$ are the coefficients of the terms that have $3, 2, 1, and \ 0$ as their powers respectively. Every term of a polynomial can be represented as a node of the linked list

 

Linked representation of a polynomial :-

 

1
1
28 votes
28 votes
B. Because in binary search we need to have access to the mid of the list in constant time. and finding the mid itself in a linked list takes $O(n)$ time which makes no sense to Binary search which otherwise takes $O(\log n)$.
13 votes
13 votes

the answer is B.

 The binary search algorithm is based on the logic of reducing your input size by half in every step until your search succeeds or input  gets exhausted. The important point here is "the step to reduce input size should take constant time". In a case of an array, it's always a simple comparison based on array indexes that take O(1) time.

But in a case of Linked list, you don't have indexes to access items. To perform any operation on a list item, you first have to reach it by traversing all items before it. So to divide list by half you first have to reach the middle of the list then perform a comparison. Getting to the middle of the list takes O(n/2)[you have to traverse half of the list items] and comparison takes O(1).
Total = O(n/2) + O(1) = O(n/2)

So the input reduction step does not take constant time. It depends on list size. hence violates the essential requirement of Binary search.

edited by

1 comment

please edit : answer as b
0
0
4 votes
4 votes

Correct Answer would be A) Binary Search

Because, Its will take $O(n/2)$ times for finding the middle element of the Linked list. 

by

4 Comments

Sir, array uses indexing mechanism, we can directly goto a[ i ] and hence by direct access , we can compare our search element to middle element and then recur for left or right half..
1
1

@kapil thanks ...this indicates i know nothing about anything laugh

0
0
@shekhar sir,

your doubts help me very much to revise all the concepts and be up to date...

keep it up sir,,, :)
0
0
Answer:

Related questions