Basic CS-Data Structures [3i Infotech Placement]: Sample Questions 7 - 8 of 52

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 7

Data Structures
Edit

Describe in Detail

Essay▾

What are the notations used in Evaluation of Arithmetic Expression using prefix and postfix forms?

Explanation

Arithmetic Expressions and Trees
  • Polish and reverse polish are the notations used in evaluation of arithmetic expression using prefix and postfix forms.

Polish Notation

  • Polish notation is also called as prefix notation.
  • A form of notation for logic, arithmetic, and algebra.
  • Its distinguishing feature is that it places operators to the left of their operands.
  • While prefixing the operator to the number, it is called polish notation.

    For example, ( (a + B) ⚹ C (D E) ^ (F + G) )

    Prefix notation: ^ -⚹ + ABC-DE + FG

Reverse Polish Notation

  • A mathematical notation where every operator follows all of its operands, in contrast to Polish notation, which puts the operator in the prefix position.
  • It suffixes the operator to the number called reverse polish notation.

Ex. . ( (a + B) ⚹ C (D E) ^ (F + G) )

Postfix notation: AB + C ⚹ DE — FG + ^

Question 8

Data Structures
Edit

Describe in Detail

Essay▾

What is your favourite sorting algorithm? Why?

Explanation

A Bubble Sort Example
  • Bubble sort is a good simple algorithm.
  • Not suitable for large data sets as its average and worst-case complexity are of where n is the number of items.
  • Beautiful algorithm easy to visualize with sorted elements bubbling up.

Bubble sort:

  • let՚s solve unsorted array:
The Sorting Algorithm
  • 1st Iteration:
  • Start with two elements, comparing them to check which one is greater.
The Sorting Algorithm
  • Value 33 is greater than 14
  • Therefore, they are in sorted locations.
  • We compare 33 with 27.
The Sorting Algorithm
  • New array looks like
The Sorting Algorithm
  • Compare 33 and 35.
  • Both are in sorted positions.
The Sorting Algorithm
  • The next two values, 35 and 10
The Sorting Algorithm
  • 10 is smaller then 35 and hence are not sorted.
The Sorting Algorithm
  • Swap values.
  • We find that we reached the end of the array.
The Sorting Algorithm
  • We are showing how an array should looks like each iteration. One iteration brought 35 to its correct location it bubbled to the top
  • After the second iteration.
The Sorting Algorithm
  • After each iteration, one value moves to correct position.
The Sorting Algorithm
  • When no swap is required, bubble sort learns that array is completely sorted.
The Sorting Algorithm

Developed by: