Showing posts with label QUESTIONS on C and data structures. Show all posts
Showing posts with label QUESTIONS on C and data structures. Show all posts

Saturday, 19 May 2012

C-Programming Challenge Interview Question


Given a list of words, L, that are all the same length, and a string, S, find the starting position of the substring of S that is a concatenation of each word in L exactly once and without any intervening characters.  This substring will occur exactly once in S.
Example:
L: "fooo", "barr", "wing", "ding", "wing"
S: "lingmindraboofooowingdingbarrwingmonkeypoundcake"
                 fooowingdingbarrwing
Answer: 13

L: "mon", "key"
S: "monkey
    monkey
Answer: 0

L: "a", "b", "c", "d", "e"
S: "abcdfecdba"

Friday, 11 May 2012

HASHING


1) The function that transforms a key into a table index is called a _________
  1. Hash function
  2. Key function
  3. Transformation function
  4. Table function
Ans) A ,
Function that transforms key to table index is called hash function

2) One of the techniques of dealing with the hash collision is
  1. Chaining
  2. Addressing
  3. Resolving
  4. Probing
Ans) A

3) ________ builds a linked list of all items whose keys hash to the same values.
  1. Chaining
  2. Addressing
  3. Resolving
  4. Probing
Ans) A

4) Hashing allows direct access to the _______
  1. Link
  2. Tuple
  3. Data
  4. Table
Ans) D

5) One way to eliminate all clustering is
  1. Quadratic rehash
  2. Rehashing
  3. Hashing
  4. Double hashing
Ans) D

6) Mark the statement(s) that is/are true
a.       Attempt made to insert a record K2 in the position where K1 is already placed
             is defined as Hash collision
b.      Transforming a key into a table index is called hash function
c.       Attempt made to insert a record K2 in the position where K1 is already placed
               is defined as Hash function
       d.   Transforming a key into a table index is called Hash collision
Ans) A, B



7) If the ________ of the item is found to be occupied during a search the rehash function is again used to locate the item.
  1. Proper position
  2. Hash position
  3. Search position
  4. Key position
Ans) B

8) The larger the range of the hash functions the less likely it is that the two keys yield the same _________.
  1. Hash value.
  2. Key value
  3. Table value
  4. Tuple value
Ans) A

9) Different keys that hash to the same value follow the same rehash path. This is called
  1. Secondary clustering
  2. Primary clustering
  3. Double hashing
  4. Quadratic rehash
Ans) A

10) __________ permits a hash table to expand and shrink dynamically
       without requiring an index.
  1. Linear hashing
  2. Linear rehashing
  3. Extendible hashing
  4. Dynamic hashing
Ans) A

11) The function that transforms a key into a __________ is called a hash function.
  1. Key index
  2. Data table
  3. Table index
  4. Record
Ans) C

12) __________ involves using a secondary hash function on the hash key of the item.
  1. Probing
  2. Addressing
  3. Resolving
  4. Rehashing
Ans)D


13) All items whose keys hash to the same values is built into a linked list, this is called
  1. Addressing
  2. Resolving
  3. Chaining
  4. Probing
Ans) C

14) Two keys that hash into different values compete with each other in _________
       is called primary clustering.
  1. Hash table
  2. Successive rehashes
  3. Link table
  4. Secondary hash
Ans) B

15) The _______of a hashing method is usually measured by the average number of table positions that must be examined in searching for a particular item.
  1. Accuracy
  2. Efficiency
  3. Complexity
  4. Easiness
Ans) B

16) If r is the record whose key hashes into hr, hr is called
  1. Function of r
  2. Hash key of r.
  3. Function key of r
  4. Key of r
Ans) B

17) Rehashing involves using a secondary hash function on the __________ of the item.
  1. Hash Key
  2. Data Key
  3. Table Key
  4. Index Key

Ans) A

18) A good hash function is one that
  1. Spreads the records uniformly throughout the table
  2. Minimizes duplication
  3. Reduces link fields
  4. Reduces duplication
Ans) A,B

19) One way of eliminating _________is to allow the rehash function to depend on the number of times that the function is applied to a particular hash value.
  1. Secondary clustering
  2. Primary clustering
  3. Double hashing
  4. Quadratic rehash
Ans) B

20) ________is defined as any hashing scheme in which any newly inserted element is equally likely to be placed at any of the empty positions of the hash table.
  1. Quadratic rehash
  2. Double hashing
  3. Uniform hashing
  4. Rehashing
Ans) C

21) The function that transforms a ______ into a table index is called a hash function.
  1. Key
  2. Data
  3. Table
  4. Index
Ans) A

22) Hash collision can be dealt with techniques like
  1. Resolving and addressing
  2. Probing
  3. Rehashing and chaining
  4. Hashing
Ans) C

23) Chaining builds __________of all items whose keys hash to the same values
  1. An index
  2. A linked list
  3. A collection
  4. A grouping
Ans) B

24) The phenomenon, where two keys that hash into different values compete with each other in successive rehashes is called _____________.
  1. Double hashing
  2. Quadratic rehash
  3. Primary clustering
  4. Secondary clustering
Ans) C

25) It is difficult to delete items from the hash table that uses ________for search and insertion.
  1. Rehashing
  2. Addressing
  3. Probing
  4. Linking
Ans) A

26) If h is a hash and key is key______ is called the hash of key.
  1. h-key
  2. key(h)
  3. h(k)
  4. h(key)
Ans) D

27) Rehashing involves using a secondary ________ on the hash key of the item.
  1. Hash function
  2. Key function
  3. Transformation function
  4. Table function
Ans) A

28) A good hash function is one that minimizes ___________.
  1. Collisions
  2. Duplication
  3. Creation
  4. Link fields
Ans) A

29) Any __________ that depends solely on the index to be rehashed causes
        primary clustering.
  1. Rehash function
  2. Key function
  3. Hash function
  4. Table function
 Ans) A

30) The Efficiency of a hashing method is usually measured by the average number of
________ that must be examined in searching for a particular item.
  1. Table positions
  2. Tuple
  3. Data
  4. Links
Ans) A


31) Hash collision is defined as
  1. An attempt made to insert a record K2 in the position where K1 is already placed
  2. Transforming a key into a table index
  3. Inserting an already existing record
  4. Inserting a record into the wrong position
Ans) A

32) The hash function is applied successfully until ________is found where the items can be inserted.
  1. Proper position
  2. Hash position
  3. Empty position
  4. Key position
Ans) C

33) The _________ the range of the Hash function, the less likely it is that the two keys yield the same hash value.
  1. Smaller
  2. Larger
  3. Closer
  4. Farther
Ans) B

34) One way of eliminating primary clustering is to allow there hash function to depend on the number of times that the function is applied to a particular ________.
  1. Data
  2. Table Key
  3. Hash value
  4. Index value
Ans) C

35) Uniform hashing is defined as any newly inserted element is equally likely to be placed at any of the empty positions of the____________.
  1. Index table
  2. Hash table
  3. Sorted list
  4. Grouped elements
Ans) B

36) If h is a hash and key is key, h(key) is called the
  1. Key of hash
  2. Hash of key
  3. Function key
  4. Key function
Ans) B

37) Rehashing involves using __________hash function on the hash key of the item.
  1. Primary
  2. First
  3. Second
  4. Secondary
Ans) D

38) The chaining technique involves adding an extra_________ to each table position.
  1. Series of data
  2. Line
  3. Tuple
  4. Link field
Ans) D

39) Any rehash function that depends solely on the index to be rehashed causes __________.
  1. Double hashing
  2. Quadratic rehash
  3. Primary clustering
  4. Secondary clustering
Ans) C

40) The Efficiency of a________ is usually measured by the average number of table positions that must be examined in searching for a particular item
  1. Rehash method
  2. Linking method
  3. Hashing method
  4. Searching method
Ans) C

41) One of the techniques of dealing with the hash collision is
  1. Probing
  2. Addressing
  3. Resolving
  4. Rehashing
Ans) D

42) If the Hash function of the item is found to be occupied during a search the _______ is again used to locate the item.
  1. Key function
  2. Hash function
  3. Transformation function
  4. Rehash function
Ans) D


43) ___________ allows direct access to the table.
  1. Probing
  2. Rehashing
  3. Hashing
  4. Addressing
Ans) C

44) Secondary clustering is the phenomenon where different keys that hash to the same      value follow ___________
  1. Different rehash path
  2. Same rehash path
  3. Selected path
  4. Ideal path
Ans) B

45) Linear hashing permits a________ to expand and shrink dynamically
       without requiring an index.
  1. Index table
  2. Hash table
  3. Sorted list
  4. Grouped elements
Ans) B

46) If an attempt is made to insert a record k2 in the position where k1 is already placed
The situation that results is called
  1. Hash collision
  2. Probing
  3. Hash clash
  4. Invalid insertion
Ans) A, C

47) The _________is applied successfully until an empty position is found where the items can be inserted.
  1. Key function
  2. Hash function
  3. Transformation function
  4. Table function
Ans) B

48) The larger the range of the _________ the less likely it is that the two keys yield the same hash value.
  1. Key function
  2. Hash function
  3. Transformation function
  4. Table function
Ans) B

49) One way of eliminating primary clustering is to allow the ________ to depend on the number of times that the function is applied to a particular hash value.
  1. Key function
  2. Hash function
  3. Table function
  4. Rehash function
Ans) A

50) Uniform hashing is defined as any___________ in which any newly inserted element is equally likely to be placed at any of the empty positions of the hash table
  1. Sorting scheme
  2. Hashing scheme
  3. Searching scheme
  4. Linking scheme
Ans) B

51)  The following paragraph is connected with hashing:

The process of mapping large amounts of data into a smaller table is called …… (i) ……. A good hash function should satisfy two criteria, namely quickness to compute and minimisation of the number of   …… (ii) ……. Minimization of …… (iii) …… can be achieved by choosing a hash function that spreads the incoming data as evenly as possible over the hash table.
Correct terms for the blanks positions are:

(a)  (i) indexing   (ii) collisions    (iii) couplings
(b)  (i) hashing      (ii) collisions    (iii) couplings
(c)  (i) hashing    (ii) collisions     (iii) collisions
(d)  (i) indexing     (ii) collisions    (iii) collisions  
(e)  (i) hashing    (ii) couplings     (iii) couplings

Ans :c

52. Consider the following five (v) terms:
                 (i)   Coupling
                 (ii)  Double hashing
                 (iii) Collision
                 (iv) Linear probing
                (v) Quadratic probing
Which of the above is a/are hashing method(s)?

(a)   (ii) only
(b)   (ii) and (iv) only
(c)   (ii),(iv) and (v) only
(d)   (ii) and (iii) only
(e)   All of these
Ans :c

53. Which of the following is a /are hash function(s)?

(a) Shortest path
(b) Folding
(c) Mid-square
(d)Extraction
(e)Binary

Ans : b, c, e

54. Which of the following are not hash functions?

(a) division
 (b) folding
(c) coupling
(d) mid square
(e) extraction

Ans : c





Stack


Questions on Stack


1.          A Stack is a _______ DS
a.       LIFO
b.      FIFO
c.       LILO
d.      FILO
Ans. : a, d : A Stack is a Data Structure behaving Last in And First out or First In and Last Out.. They are one and the Same...

2.          In a Stack the elements are entered from ________.
a.       End
b.      Top
c.       Random
d.      Bottom
Ans. :  b. , The elements are entered and deleted from the stack from the top only.
3.          The basic Operations on the Stack are
a.       Push & Pop
b.      Insert & Delete
c.       Enter & Remove
d.      Add & Subtract
Ans. : a, Push and Pop are the terminologies used in use of the stack.

4.          Condition Checked before Pushing
a.       Stack Overflow
b.      Stack Underflow
c.       No Condition to be checked
d.      Both the conditions
Ans . :  a.  : Check Stack Overflow before pushing.

5.          Condition Checked before Poping
a.       Stack Overflow
b.      Stack Underflow
c.       No Condition to be checked
d.      Both the conditions
Ans . :  b.  : Check Stack Underflow before poping.

6.          The total nos of pair of brackets in an expression is called _______
a.       Open Scopes
b.      To be closed Scopes
c.       Nesting Depth
d.      Depth Sequence
Ans.   : c  Nesting Depth is the total nos. of open brackets in an expression at any time to be closed.
7.          Stacks are implemented using _________.
a.       Arrays
b.      Linked Lists
c.       Static Variables
d.      Register Variables
Ans.   :    a, b, Stack are implemented using arrays as well as linked list.

8.          Recursive function call uses _________ Data Structure.
a.       Stacks
b.      Queues
c.       Linked Lists
d.      Trees
Ans. :  a, Recursive Function Calls uses Stacks.
9. Entries in a stack are "ordered". What is the meaning of this statement?
    1. A collection of stacks can be sorted.
    2. Stack entries may be compared with the '<' operation.
    3. The entries must be stored in a linked list.
    4. There is a first entry, a second entry, and so on.
Ans. :  b, That is the reason it is used by infix and prefix expressions.
10. The operation for adding an entry to a stack is traditionally called:
a.       add
b.      append
c.       insert
d.      push
Ans. : d, Push is the operation traditionally used.
  1. The operation for removing an entry from a stack is traditionally called:
    1. delete
    2. peek
    3. pop
    4. remove
Ans.  :  c, pop is the operation used for removing an entry.
  1. Which of the following stack operations could result in stack underflow?
    1. is empty
    2. Continuously poping
    3. Continuously pushing
    4. This can never happen
Ans. : b,  Continuously poping can result in stack underflow.
  1. Which of the following applications may use a stack?
    1. A parentheses balancing program.
    2. Keeping track of local variables at run time.
    3. Syntax analyzer for a compiler.
    4. All of the above.
Ans. : d, All of the above use a stack because they need kinda ordering.
  1. Consider the following pseudo code:
  declare a stack of characters
  while ( there are more characters in the word to read )
   {
      read a character
      push the character on the stack
   }
   while ( the stack is not empty )
   {
      write the stack's top character to the screen
      pop a character off the stack
   }
What is written to the screen for the input "carpets"?
    1. serc
    2. carpets
    3. steprac
    4. ccaarrppeettss
Ans. : c, After working out it comes out to be “steprac” since stack is a last in first out system.
  1. Here is an INCORRECT pseudo code for the algorithm which is supposed to determine whether a sequence of parentheses is balanced:
 
   declare a character stack 
   while ( more input is available)
   {
      read a character
      if ( the character is a '(' ) 
         push it on the stack
      else if ( the character is a ')' and the stack is not empty )
         pop a character off the stack
      else
         print "unbalanced" and exit
    }
    print "balanced"
Which of these unbalanced sequences does the above code think is balanced?
    1. ((( ))
    2. ( ))(( )
    3. (( )( )))
    4. (( )))( )

Ans. : a, (   -> push => top = 0
             (   -> push => top = 1
            (   -> push => top = 2
            )  -> pop  =>  top = 1
           )  -> pop =>   top = 0
      While loop ends, and balanced is printed, but exp is unbalanced.                            
  1. Consider the usual algorithm for determining whether a sequence of parentheses is balanced. What is the maximum number of parentheses that will appear on the stack AT ANY ONE TIME when the algorithm analyzes: (()(())(()))?
    1. 1
    2. 2
    3. 3
    4. 4
    5. 5 or more
Ans.  :  c, Max number of parentheses at a time will not be more than 3.
  1. Suppose we have an array implementation of the stack, with ten items in the stack stored at data[0] through data[9]. The CAPACITY is 42. Where does the push member function place the new entry in the array?
    1. data[0]
    2. data[1]
    3. data[9]
    4. data[10]
Ans. : d, the next data is stored in data[10]
  1. Consider the implementation of the stack using a partially-filled array. What goes wrong if we try to store the top of the stack at location [0] and the bottom of the stack at the last used position of the array?
    1. Both peek and pop would require linear time.
    2. Both push and pop would require linear time.
    3. The stack could not be used to check balanced parentheses.
    4. The stack could not be used to evaluate postfix expressions.
Ans. : b, because both push and pop will be required to be done on the top of the stack.
  1. In the linked list implementation of the stack , where does the push member function place the new entry on the linked list?
    1. At the head
    2. At the tail
    3. After all other entries those are greater than the new entry.
    4. After all other entries those are smaller than the new entry.
Ans. a, The head acts as the top.
  1. In the array version of the stack (with a fixed-sized array), which operations require linear time for their worst-case behavior?
    1. is_empty
    2. peek
    3. pop
    4. push
Ans. : c, Pop uses linear time.
  1. In the linked-list version of the stack class, which operations require linear time for their worst-case behavior?
    1. is_empty
    2. peek
    3. pop
    4. push
Ans. : c, Pop would require linear time.
  1. What is the value of the postfix expression 6 3 2 4 + - *:
    1. Something between -15 and -100
    2. Something between -5 and -15
    3. Something between 5 and -5
    4. Something between 5 and 15
Ans. : a, ans works out to be -18 and the infix expr. being 6*(3-(2+4))
  1. Here is an infix expression: 4+3*(6*3-12). Suppose that we are using the usual stack algorithm to convert the expression from infix to postfix notation. What is the maximum number of symbols that will appear on the stack AT ONE TIME during the conversion of this expression?
    1. 1
    2. 2
    3. 3
    4. 4
    5. 5
Ans . c, works out to be 3 at the max.


24.  The operation on stack that increments the top is called
  1. Overflow
  2. Push
  3. Pop
  4. Underflow
Ans)B

25.  The situation of deleting an element from a stack which doesn’t have elements is called
  1. Overflow
  2. Push
  3. Pop
  4. Underflow
Ans)D

26.   The time complexity of adding an element to a stack of n elements is?
  1. O(1)
  2. O(n)
  3. O(n*n)
  4. None
Ans)A

27.  The time complexity of deleting an element from a stack of n elements is?
  1. O(n+1)
  2. O(n)
  3. O(1)
  4. None
Ans)C

28.  A stack is said to be Full when it is _________
  1. Unsorted
  2. Underflow
  3. Over flow
  4. Sorted
Ans)C


29.  B(i) represents the bottom of I the stack and T(i) represents the
top of I the stack. When a Stack I will becomes full?
  1. B(i)=T(i)
  2. B(i+1) = T(i)+1
  3. B(i-1)  = T(i+1)
  4. B(i-1)  = T(i-1)
Ans)B

30.   what type of storage is used to represent stacks and queues
    1. Random
    2. Sequential
    3. Dynamic
    4. Logical
Ans : b , page 186 Tenenbaum 2nd edition(2002)

31. Drawbacks of sequential storage in stacks
a. Fixed amount of storage remains allocated to the stack
b.No more than fixed amount of storage can be allocated to the stack
c. Both a) and b)
d.      None
            Ans : c, page 187 Tenenbaum 2nd edition(2002)

32.  what is the infix expression of the given prefix expression  : +A*BC
    1. A*B+C
    2. A+B*C
    3. (A+B)*C
    4. A*(B+C)
Ans : b, Page no 242.Tenenbaum 1994 edition
  1. what is the infix expression of the given prefix expression  : *+ABC
    1. A*B+C
    2. A+B*C
    3. (A+B)*C
    4. A*(B+C)
Ans : c, Page no 242.Tenenbaum 1994 edition


  1. what is the infix expression of the given prefix expression  :
            +A*-BC$D*EF
    1. ((A+B-C)*D)$(E*F)
    2. A+B-C*D$E*F
    3. A+(B-C)*D$(E*F)
    4. ((A+B)-C*D)$E*F
Ans : c, Page no 242.Tenenbaum 1994 edition

  1. what is the infix expression of the given prefix expression  :
            $+A*BC*+ABC
    1. (A*B+C)$(A+B)*C
    2. (A+B*C)$((A+B)*C)
    3. A+(B*C)$A+(B*C)
    4. (A+B)*C$A+(B*C)
Ans : b, Page no 242.Tenenbaum 1994 edition
  1. what is the postfix expression of the given prefix expression  : +A*BC
    1. ABC*+
    2. AB+C*
    3. AB*C+
    4. ABC+*
Ans : a, Page no 242.Tenenbaum 1994 edition
  1. what is the postfix expression of the given prefix expression  : *+ABC
    1. ABC*+
    2. AB+C*
    3. AB*C+
    4. ABC+*
Ans : b, Page no 242.Tenenbaum 1994 edition

  1. what is the postfix expression of the given prefix expression  :
            +A*-BC$D*EF
    1. ABCDEF-*$*+
    2. ABC-DE*F$*+
    3. AB-CDEF$**+
    4. ABC-DEF*$*+
Ans : d, Page no 242.Tenenbaum 1994 edition
  1. what is the postfix expression of the given prefix expression  :
            $+A*BC*+ABC
    1. ABCABC*++*$
    2. ABC+*AB+C*$
    3. ABC*+AB+C*$
    4. AB+C*AB+C*$
Ans : c, Page no 242.Tenenbaum 1994 edition
  1. what is the infix expression of the given postfix expression  : ABC*+
    1. A*B+C
    2. A+B*C
    3. (A+B)*C
    4. A*(B+C)
Ans : b, Page no 242.Tenenbaum 1994 edition
  1. what is the infix expression of the given Postfix expression  : AB+C*
    1. A*B+C
    2. A+B*C
    3. (A+B)*C
    4. A*(B+C)
Ans : c, Page no 242.Tenenbaum 1994 edition
  1. what is the infix expression of the given Postfix expression  :
          ABC-DEF*$*+
    1. ((A+B-C)*D)$(E*F)
    2. A+B-C*D$E*F
    3. A+(B-C)*D$(E*F)
    4. ((A+B)-C*D)$E*F
Ans : c, Page no 242.Tenenbaum 1994 edition
  1. what is the infix expression of the given Postfix expression  :
            ABC*+AB+C*$
    1. (A*B+C)$(A+B)*C
    2. (A+B*C)$((A+B)*C)
    3. A+(B*C)$A+(B*C)
    4. (A+B)*C$A+(B*C)
Ans : b, Page no 242.Tenenbaum 1994 edition
  1. what is the postfix expression of the given Infix expression  : A+B*C
    1. ABC*+
    2. AB+C*
    3. AB*C+
    4. ABC+*
Ans : a, Page no 242.Tenenbaum 1994 edition
  1. what is the postfix expression of the given Infix expression  : (A+B)*C
    1. ABC*+
    2. AB+C*
    3. AB*C+
    4. ABC+*
Ans : b, Page no 242.Tenenbaum 1994 edition
  1. what is the postfix expression of the given Infix expression  :
            A+(B-C)*D$(E*F)
    1. ABCDEF-*$*+
    2. ABC-DE*F$*+
    3. AB-CDEF$**+
    4. ABC-DEF*$*+
Ans : d, Page no 242.Tenenbaum 1994 edition
  1. what is the postfix expression of the given Infix expression  :
            (A+B*C)$((A+B)*C)
    1. ABCABC*++*$
    2. ABC+*AB+C*$
    3. ABC*+AB+C*$
    4. AB+C*AB+C*$
Ans : c, Page no 242.Tenenbaum 1994 edition
  1. what is the Prefix expression of the given postfix expression  : ABC*+
    1. +A*BC
    2. +AB*C
    3. +*ABC
    4. *+ABC
Ans : a, Page no 242.Tenenbaum 1994 edition
  1. what is the Prefix expression of the given Postfix expression  : AB+C*
    1. +A*BC
    2. +AB*C
    3. +*ABC
    4. *+ABC
Ans : d, Page no 242.Tenenbaum 1994 edition
  1. what is the Prefix expression of the given Postfix expression  :
            ABC-DEF*$*+
    1. +*-$*ABCDEF
    2. A+*-BCD$*EF
    3. +A*-BC$D*EF
    4. +*-ABC$*DEF
Ans : c, Page no 242.Tenenbaum 1994 edition
  1. what is the Prefix expression of the given Postfix expression  :
            ABC*+AB+C*$
    1. $+**+ABCABC
    2. $+A*BC*+ABC
    3. $+*ABC*+ABC
    4. +*ABC$*+ABC
Ans : b, Page no 242.Tenenbaum 1994 edition
  1. what is the Prefix expression of the given Infix expression  : A+B*C
    1. +AB*C
    2. +*ABC
    3. *+ABC
    4. +A*BC
Ans : d, Page no 242.Tenenbaum 1994 edition
  1. what is the Prefix expression of the given Infix expression  : (A+B)*C
    1. *+ABC
    2. +A*BC
    3. +AB*C
    4. +*ABC
Ans : a, Page no 242.Tenenbaum 1994 edition
  1. what is the Prefix expression of the given Infix expression  :
            A+(B-C)*D$(E*F)
    1. +*-$*ABCDEF
    2. A+*-BCD$*EF
    3. +*-ABC$*DEF
    4. +A*-BC$D*EF
Ans : d, Page no 242.Tenenbaum 1994 edition
  1. what is the Prefix expression of the given Infix expression  :
            (A+B*C)$((A+B)*C)
    1. $+**+ABCABC
    2. $+*ABC*+ABC
    3. $+A*BC*+ABC
    4. +*ABC$*+ABC
Ans : c, Page no 242.Tenenbaum 1994 edition
56) Consider the following statements.

(i) A stack is a list with the restriction that items are inserted or removed/deleted only at one position, namely the end of the list.
(ii) The general model is that one where there is some element that is at the top of the stack, and it is the only element that is visible.
(iii) A pop or top on an empty stack is generally considered an error in the stack ADT.
(iv) The fundamental operations on stacks are push and pop, where push is relevant to the removal of the most recently inserted element and pop is equivalent to an insertion.
(v) A stack is a list; insertion and deletion can be performed from both ends.

Which of the above statements is/are valid for stacks?
  1. (i), & (ii) only

  1. (i), (ii) & (iv) only

  1. (i), (ii), (iii) & (iv) only

  1. (i), (ii) & (iii) only

  1. (i), (ii) & (v) only

Ans)   D

57)  Consider the following algorithm.
(i) Make an empty stack.
(ii) Read characters until end of the file.
(iii) If the character is an opening symbol, push it into the stack.
(iv)If it is a closing symbol, then if the stack is empty, report an error.
(v)Otherwise, pop the stack. If the symbol popped is not the corresponding opening symbol, then, report an error.
(vi)At end of the file, if the stack is not empty, report an error.

Identify, what the above algorithm intends to do.

  1. Evaluating a mathematical expression

  1. Check for balancing of parentheses, brackets and braces and ignore any other character that appears

  1. Eliminating un-matched parentheses, brackets and braces and ignoring any other character that appears

  1. Checking compiler errors

  1. Determination of syntax errors

Ans) B

58)The following shows a series of stack operations.
  1. Push(5)
  2. Push(8)
  3. Isempty( )
  4. Pop( )
  5. Push(3)
  6. Pop( )
  7. Pop( )
  8. Pop( )
  9. Isfull( )
  10. Push(3)
If the above series of operations is performed, what would be the set returned values?
    1. {false, 8, 3, 5, error, false, 3}

    1. {5, 8, false, 8, 3, 5, error, false, 3}

    1. {false, 8, 3, 5, error, false}

    1. {false, 8,3, 5, false}

    1. {false, 8, 3, 5, error, true}

Ans) C


59) Consider the following operations and their definitions.

(i) Clear( ) :– Clear the stack.
(ii) Is_Empty( ) :– Remove all items from the stack.
(iii) Insert( x) :- Insert element x in to any location of the stack.
(iv) Delete(p) :- Delete the element from the position p.
(v) Top( ) :- Return and remove the topmost element from the stack.
Which of the above operations is/are valid in stacks according to the basic definitions?
  1. (i), (ii) and (v) only

  1. (i)and (v) only

  1. (i)only

  1. (i)and (ii) only

  1. (i), (ii), (iii), (iv) and (v)

Ans) C

60)  Consider the following infix expression.

((A+B)*C-(D-E))^(F+G)
Note: ^ denotes the power.

Equivalent postfix and prefix expressions are respectively

  1. AB+C*DE--FG+^, ^-*ABC-DE+FG

  1. AB+C*DE-FG+^, ^-*+ABC-DE+FG

  1. AB+C*DE--FG+^, ^-*+ABC-DE+FG

  1. AB+C*DE-FG+^, ^-*+ACB-DE+FG

  1. AB+C*DE--FG+^, ^-*+CBA-DE+FG

Ans) C