Professional Documents
Culture Documents
Unit 1 To 5 Qbank Ans
Unit 1 To 5 Qbank Ans
Unit 1 To 5 Qbank Ans
Linear search is a very simple search algorithm. In this type of search, a sequential search is
made over all items one by one. Every item is checked and if a match is found then that
particular item is returned, otherwise the search continues till the end of the data collection.
Algorithm
Linear Search ( Array A, Value x)
Step 1: Set i to 1
Step 2: if i > n then go to step 7
Step 3: if A[i] = x then go to step 6
Step 4: Set i to i + 1
Step 5: Go to Step 2
Step 6: Print Element x Found at index i and go to step 8
Step 7: Print element not found
Step 8: Exit
Pseudocode
procedure linear_search (list, value)
end procedure
n this article, we will discuss why algorithm and its analysis is important?
In the analysis of the algorithm, it generally focused on CPU (time) usage, Memory usage,
Disk usage, and Network usage. All are important, but the most concern is about the CPU
time. Be careful to differentiate between:
Algorithm Analysis:
Algorithm analysis is an important part of computational complexity theory, which provides
theoretical estimation for the required resources of an algorithm to solve a specific
computational problem. Analysis of algorithms is the determination of the amount of time
and space resources required to execute it.
1. Best case
2. Worst case
3. Average case
Best case: Define the input for which algorithm takes less time or minimum time. In
the best case calculate the lower bound of an algorithm. Example: In the linear search
when search data is present at the first location of large data then the best case occurs.
Worst Case: Define the input for which algorithm takes a long time or maximum
time. In the worst calculate the upper bound of an algorithm. Example: In the linear
search when search data is not present at all then the worst case occurs.
Average case: In the average case take all random inputs and calculate the
computation time for all inputs.
And then we divide it by the total number of inputs.
Average case = all random case time / total no of case
4.What is Time-Space Tradeoff? Design a space efficient and time efficient algorithm
for swapping the numbers and reversing the contents of an array
1.If data is stored uncompressed,it takes more space but less time.
2.Storing only the source and rendering it as an image everytime the page is requested
would be trading time for space. More time used but less space
5.Define recurrence equation. Describe the methods for solving recurrences with
time complexity of different algorithms
https://www.geeksforgeeks.org/how-to-solve-time-complexity-recurrence-relations-using-
recursion-tree-method/