Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

DSA Assignment: Linear Search and Quadratic Time Complexity Search Algorithms, Assignments of Data Structures and Algorithms

solution to various assignment questions

Typology: Assignments

2019/2020

Uploaded on 05/07/2020

bhavya-sikri
bhavya-sikri 🇮🇳

2 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Bhavya Sikri 101706048 ECE2
DSA Assignment
Ques. Select two searching algorithms with Big O(n) and Big O(n^2) and
compare them with the help of an example. Write the pseudo code too.
Big O(n) : Searching algorithm with time complexity O(n) is such that we go to each entry and
look for the required entry such that in Linear Searching. In it running time increases linearly
with the size of the input data
For value in data:
Print(value)
For Example: Imagine a class of 50 students in which you gave your notebook to one person.
Now you want that notebook back, therefor you go to each student and ask them individually.
Pseudo Code: LinearSearch(list,ReqEntry)
{
Int i = 0
While (i<number of items in the list)
{
If (list[i] == ReqEntry)
{
Return i
}
i++
}
Return -1
}
pf3

Partial preview of the text

Download DSA Assignment: Linear Search and Quadratic Time Complexity Search Algorithms and more Assignments Data Structures and Algorithms in PDF only on Docsity!

DSA Assignment

Ques. Select two searching algorithms with Big O(n) and Big O(n^2) and

compare them with the help of an example. Write the pseudo code too.

Big O(n) : Searching algorithm with time complexity O(n) is such that we go to each entry and

look for the required entry such that in Linear Searching. In it running time increases linearly with the size of the input data For value in data: Print(value) For Example : Imagine a class of 50 students in which you gave your notebook to one person. Now you want that notebook back, therefor you go to each student and ask them individually. Pseudo Code: LinearSearch(list,ReqEntry) { Int i = 0 While (i<number of items in the list) { If (list[i] == ReqEntry) { Return i } i++ } Return - }

Big O(n^2) : Searching algorithm with time complexity O(n^2) is such that we go to the first

entry, see if this is the required entry. In it the first entry has the information of other entries, so we ask it about the remaining entries such that in Quadratic Time Complexity Searching. For x in data: For y in data: Print(x,y) For Example : Imagine a class of 50 students in which you gave your notebook to one person. Now you want that notebook back, therefor you go and ask the first person whether he has the notebook. Also you ask this person about other 49 people in the classroom if they have the notebook and so on. Pseudo Code: QuadTimeComplexitySearch(list,ReqEntry) { Int i Int j If (list[i] == ReqEntry) { Return i } Else { For (i=0; i<number of items in the list; i++) { For(j=0; j<i; j++) { If (list[j] == ReqEntry)