Uploaded by yodak18196

Assignment 01 - DSA

advertisement
DATA STRUCTURES & ALGORITHMS
ASSIGNMENT 01
MARKS: 05
SUBMISSION BEFORE: 05-11-2022 11:59PM
Note: Only hardcopy will be accepted.
Q1. Develop Method in java which can find the largest and the smallest value from integer
Array.
Q2. What is meant by effectiveness of Algorithm? How do you determine efficiency of an
algorithm? Analyze the given code and find the upper bound using Big-O Notation:
import java.util.Scanner;
public class LinearSearch {
public static void main(String[] args) {
int[] arr = {3, 7, 4, 14, 6, 11, 15};
int item,flag=0;
Scanner sc = new Scanner(System.in);
System.out.println("Enter Item ?");
item = sc.nextInt();
for(int i = 0; i<10; i++)
{
if(arr[i]==item)
{
flag = i+1;
break;
}
else
flag = 0;
}
if(flag != 0)
{
System.out.println("Item found at location" + flag);
}
else
System.out.println("Item not found");
}
}
Q3. Arrange the following expressions by growth rate from slowest to fastest.
4n2
log3n
n!
3n
20n
2
log2n
n2/3
Q4. Suppose that a particular algorithm has time complexity T(n) = 3*2n, and that executing an
implementation of it on a particular machine takes t seconds for n inputs. Now suppose that we are
presented with a machine that is 64 times as fast. How many inputs could we process on
the new machine in t seconds?
Q5. In an array holding an even number of data items, there is no middle item, which item does
the binary search algorithm examine first?
Q6. Following are the three known searching methods when data are stored in an array.
1) Linear Search
2) Binary Search
3) Jump Search
a) Write a generic implementation for the above searching methods so that they can be used with
any type of data stored in the array.
b) Obtain a time and space comparison of the above methods and then conclude which is/are to
be taken as the best searching method(s).
Q7. Declare 6 arrays are required to store the student’s records each of size say, 25. Initialize each
array with appropriate data and use the following operations on your data structures:
a)
b)
c)
d)
e)
f)
List all the records on the screen
Search for a record whose Roll No. is say, X
Delete a record whose Roll No. is say, X
Insert a new record just after the record, whose Roll No. = X
Sort all the records according to the descending order of Total.
Suppose, we want to merge the records of two classes. Obtain the merging in such a case.
Roll No.
Marks1 Marks2 Marks3 Total
Grade
…
…
…
…
…
Arrays: Storing the Student's records
Q8. What is the concept of ‘Optimality’ so far as an algorithm to solve a problem is concerned?
Justify your answer with some example.
Download