Two marks.
1. What is linear data structure? Give an example.
Ans:A linear data structure is known as a data structure that allows data
elements to be arranged in a sequential or linear fashion. Each element
is attached with its next and previous adjacent. A linear data structure
only has one level and performs linear searching in the data structure.
We can therefore traverse all elements in a single run. Because computer
memory is linearly arranged, linear data structures are simple to
implement. Linear data structure examples are array, linked list, stack,
queue, etc.
2. Define the space and time complexities of an algorithm.
Ans:The valid algorithm takes a finite amount of time for execution. The
time required by the algorithm to solve given problem is called time
complexity of the algorithm. Problem-solving using computer requires
memory to hold temporary data or final result while the program is in
execution. The amount of memory required by the algorithm to solve given
problem is called space complexity of the algorithm.
3. What is recursion?
Ans: Recursion is defined as a process which calls itself directly or
indirectly and the corresponding function is called a recursive function.
4. What is dynamic memory allocation?
Ans: The mechanism by which storage/memory/cells can be allocated to
variables during the run time is called Dynamic Memory Allocation (not to
be confused with DMA). So, as we have been going through it all, we can
tell that it allocates the memory during the run time which enables us to
use as much storage as we want, without worrying about any wastage.
5. Define stack.
Ans: Stack is a linear data structure that follows a particular order in
which the operations are performed. The order may be LIFO(Last In First
Out) or FILO(First In Last Out). LIFO implies that the element that is
inserted last, comes out first and FILO implies that the element that is
inserted first, comes out last.
6. Compare linear search and binary search methods.
Ans:
Linear Search Binary Search
1. In linear search input data
need not to be in sorted.
1. In binary search input data
need to be in sorted order.
2. It is also called sequential
search.
2. It is also called half-interval
search.
3. The time complexity of linear
search O(n).
3. The time complexity of binary
search O(log n).
4. Multidimensional array can be
used.
4. Only single dimensional array
is used.
5. Linear search performs equality
comparisons.
5. Binary search performs ordering
comparisons.
6. It is less complex. 6. It is more complex.
7. It is very slow process. 7. It is very fast process.