Anda di halaman 1dari 2

1) Define algorithm. What are its properties?

Ans :- An algorithm is a set of instructions that provide step-by-step specifications toperform a task.Ex:-Step by step procedure for display 10 natural numbers:-1. Set the value of counter to 12. Display counter3. Increment counter by 14. If counter <= 10, go to step 2The preceding step -by -step procedure is an algorithm because it produces thecorrect result inA finite number of steps.The properties of an algorithm are:

Input : Specifies the data set that is applied to the algorithm to check its validity.

Output : Specifies the data set that is produced as a result of the algorithm execution.

Definiteness : Specifies that the instructions described in the algorithm should be welldefined and should not create any ambiguity.

Termination : Specifies that the instructions described in the algorithm must contain aproper termination condition.

Effectiveness : Specifies that the algorithm take less time and less memory spaceduring its execution.

2) Give atleast four real life examples where we use stack operations.Ans:- The real life examples of stacks are:

Bangles in a hand : The bangles wore in a hand follow last-in-first-out (LIFO) strategy of stack. The bangle that you wear first is thelast one to be taken out while removing all the bangles from thehand. The bangle that is worn last is the first one to be taken out Same circumference circular rings in a pole : The rings havingsame circumference placed into a pole also follow LIFO strategy.The topmost ring, which was the last to be placed in the pole, is thefirst one to be taken out.

The bolts screwed to a single nut

: When the bolts are screwed to asingle nut, the last screwed bolt is unscrewed first and the bolt thatwas screwed first is unscrewed in the last.

Battery cells in a torch : The battery cells in a torch also follow thesame LIFO strategy of stack. 3) Differentiate full and complete binary trees. Ans:- The following table lists the differences between complete binarytrees and full binary trees: Complete binary trees Full binary trees All the nodes at the previous level are fullyaccommodated before thenext level is accommodated. All levels are maximallyaccommodated. Number of nodes at the last (n) level may or may not equal to 2 n . Number of nodes at the last (n)level is exactly equal to 2 n . Leaf nodes may or may not be at the same level. All leaf nodes are at the samelevel. A complete binary tree mayor may not be full binarytree. A full binary tree is always acomplete binary tree. 4) What are the demerits of recursion? Ans:- Demerits of recursion are:Many programming languages do not support recursion; hence,recursive mathematical function is implemented using iterativemethods.Even though mathematical functions can be easily implemented usingrecursion, it is always at the cost of execution time and memory space. The recursive programs take considerably more storage and take moretime during processing

Anda mungkin juga menyukai