0% found this document useful (0 votes)
9 views

Data Structure

Uploaded by

Lalitha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Data Structure

Uploaded by

Lalitha
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Which one of the below mentioned is linear data structure?

(A) Queue
(B) Stack
(C) Arrays
(D) All of these

Time complexity: It is a way of representing the amount of time needed by a program to run to
the completion.
Space complexity: It is the amount of memory space required by an algorithm, during a course of
its execution. Space complexity is required in situations when limited memory is available and for the
multi user system.

Each algorithm must have:


Specification: Description of the computational procedure.
Pre-conditions: The condition(s) on input.
Body of the Algorithm: A sequence of clear and unambiguous instructions.
Post-conditions: The condition(s) on output.

Characteristics of an Algorithm
An algorithm must follow the mentioned below characteristics:

Input: An algorithm must have 0 or well defined inputs.

Output: An algorithm must have 1 or well defined outputs, and should match with the desired output.

Feasibility: An algorithm must be terminated after the finite number of steps.

Independent: An algorithm must have step-by-step directions which is independent of any

programming code.

Unambiguous: An algorithm must be unambiguous and clear. Each of their steps and

input/outputs must be clear and lead to only one meaning.

Index of arrays in C programming language starts from.............


(A) 0
(B) 1
(C) either 0 or 1
(D) Undefined

The first element of the array is exactly contained in the memory location that array refers (0 elements
away), so it should be denoted as array[0] . Most programming languages have been designed this
way, so indexing from 0 is pretty much inherent to the language

In the worst case, the number of comparisons needed to search a singly linked list of length n for a
given element is ............
(A) log2 n
(B) n/2
(C) log2 n-1

1
(D) N

A & C are not correct as we can not do binary search in Linked list.

B seems like average case, be we are asked for worst case.

Worst case is we do not find the element in list. We might end up searching entire list & comparing
with each element.

In doubly linked lists:


(A) a pointer is maintained to store both next and previous nodes.
(B) two pointers are maintained to store next and previous nodes.
(C) a pointer to self is maintained for each node.
(D) none of these

Which of the following data structure is used to implement recursion ?


Arrays
Stacks
Queues
Linked lists
When a function is called, activation is record is pushed onto stack.

For every 'return', activation record at top of stack is popped.

Applications of Queue
 Due to the fact that queue performs actions on first in first out basis which is quite fair for the
ordering of actions. There are various applications of queues discussed as below.
 Queues are widely used as waiting lists for a single shared resource like printer, disk, CPU.
 Queues are used in asynchronous transfer of data (where data is not being transferred at the
same rate between two processes) for eg. pipes, file IO, sockets.
 Queues are used like MP3 media player, CD player, etc. as buffers in most of the applications
 Queue are used to maintain the play list in media players in order to add and remove the songs
from the play-list.
 Queues are used in operating systems for handling interrupts.

Which data structure allows deleting data elements from the front and adding at the back?
 (A) Stack
 (B) Queue
 (C) Binary-search tree
 (D) Map

For implementing recursive function the data structure used is:


 (A) Stack
 (B) Queue
 (C) Linked List
(D) Tree\
Which of the following is a true about Binary Trees
(A) Every binary tree is either complete or full.
(B) Every complete binary tree is also a full binary tree.
(C) Every full binary tree is also a complete binary tree.
(D) No binary tree is both complete and full.
(e) None of the above

2
Explanation:
A full binary tree (sometimes proper binary tree or 2-tree or strictly binary tree) is a tree in which
every node other than the leaves has two children.

A complete binary tree is a binary tree in which every level, except possibly the last, is
completely filled, and all nodes are as far left as possible

B) is incorrect. The following binary tree is complete but not full

Queue data structure works on ..............


(A) LIFO
(B) FIFO
(C) FILO
(D) None of these
AVL Tree

3
AVL Tree is invented by GM Adelson - Velsky and EM Landis in 1962. The tree is named AVL in
honour of its inventors.

AVL Tree can be defined as height balanced binary search tree in which each node is associated
with a balance factor which is calculated by subtracting the height of its right sub-tree from that
of its left sub-tree.
Tree is said to be balanced if balance factor of each node is in between -1 to 1, otherwise, the tree will
be unbalanced and need to be balanced.

Balance Factor (k) = height (left(k)) - height (right(k))

A tree in which, for every node, the difference between the height of its left subtree and right subtree
is not more than one is
(A) AVL Tree
(B) Complete Binary Tree
(C) B – Tree
(D) B+ Tree

Algorithm Average case Worst case

Space o(n) o(n)

Search o(log n) o(log n)

Insert o(log n) o(log n)

Delete o(log n) o(log n)

4
SN B Tree B+ Tree

1 Search keys can not be repeatedly stored. Redundant search keys can be present.

2 Data can be stored in leaf nodes as well Data can only be stored on the leaf nodes.
as internal nodes

3 Searching for some data is a slower Searching is comparatively faster as data can
process since data can be found on only be found on the leaf nodes.
internal nodes as well as on the leaf
nodes.

4 Deletion of internal nodes are so Deletion will never be a complexed process


complicated and time consuming. since element will always be deleted from the
leaf nodes.

5 Leaf nodes can not be linked together. Leaf nodes are linked together to make the
search operations more efficient.

Consider a B+-tree in which the maximum number of keys in a node is 5. What is the minimum
number of keys in any non-root node?
1
2
3
4

Infix to Post Fix

Infix Expression Prefix Expression Postfix Expression

A+B +AB AB+

A+B*C +A*BC ABC*+

Infix Expression Prefix Expression Postfix Expression

(A + B) * C *+ABC AB+C*

Infix Expression Prefix Expression Postfix Expression

A+B*C+D ++A*BCD ABC*+D+

(A + B) * (C + D) *+AB+CD AB+CD+*

A*B+C*D +*AB*CD AB*CD*+

A+B+C+D +++ABCD AB+C+D+

5
Graphs are represented using ............
(A) Adjacency tree
(B) Adjacency linked lisT
(C) Adjacency graph.
(D) Adjacency queue

A procedure that calls itself is called ...............


(A) illegal call
(B) reverse polish
(C) recursive
(D) None of these

A recursive call is one where procedure A calls itself or calls procedure B which then calls
procedure A again. ..

The prefix of (A+B)*(C-D)/E*F is:


(A) /+-AB*CD
(B) /*+-ABCD*EF
(C) */*+AB-CDEF
(D) **AB+CD/EF

Explanation:
Prefix of (A+B) * (C - D) / E*F
(+AB) * (-CD) / E*F
*+AB-CD /E*F
*/*+AB-CDEF

n elements of a Queue are to be reversed using another queue. The number of “ADD” and
“REMOVE” operations required to do so is:
(A) 2*n
(B) 4*n
(C) n
(D) The task cannot be accomplished

To reverse the content of queue, we need a stack. It can not be done by using a Queue.

Which of the following statements about stacks is incorrect?


(A) Stacks can be implemented using linked lists.
(B) Stacks are first-in, first-out (FIFO) data structures.
(C) New nodes can only be added to the top of the stack.
(D) The last node (at the bottom) of a stack has a null (0) link.

: Linear search is highly inefficient compared to binary search when dealing with:

6
a. Small, unsorted arrays.
b. Small, sorted arrays.
c. Large, unsorted arrays.
d. Large, sorted arrays.

A random access file is organized most like a(n):


a. Array.
b. Object.
c. Class.
d. Pointer.

If a node in a BST has two children, then its in-order predecessor has .............
(A) no left child
(B) no right child
(C) two children
(D) no child

If a node in a BST has two children, then its in-order Successor has .............
(A) no left child
(B) no right child
(C) two children
(D) no child

INORDER OF THIS EXAMPLE IS 3 4 5 6 7 9 17 20 22


TAKE NODE 9....
TS INORDER PREDECESSOR IS 7...
7 HAS NO RIGHT CHILD.

7
The postfix form of the expression (A+ B)*(C*D− E)*F / G is:
(A) AB+ CD*E − FG /**
(B) AB + CD* E − F **G /
(C) AB + CD* E − *F *G /
(D) AB + CDE * − * F *G /

(A+ B)*(C*D− E)*F / G


(AB+)* (CD*E-)*FG/
AB+CD*E-*FG/*
AB+CD*E-FG/**

The prefix form of an infix expression A+B-C*D is


(A) +AB-*CD
(B) -+A B C * D
(C) -+A B * C D.
(D) - + *ABCD

Consider a set A = {1, 2, 3, …….., 1000}. How many members of A shall be divisible by
3 or by 5 or by both 3 and 5 ?
(A) 533 (B) 599
(C) 467 (D) 66

A U B ) = (A) + (B) - (A ∩ B)

A=1000/3 = 333 [No's divisible by 3]

B=1000/5=200 [No's divisible by 5]

A ∩ B= 1000/15=66 [No's divisible by both 3 and 5]

A U B = 333+200-66=533-66=467

8
Which of the following is true for computation time in insertion, deletion and finding maximum and
minimum element in a sorted array ?
(A) Insertion – 0(1), Deletion – 0(1), Maximum – 0(1), Minimum – 0(l)
(B) Insertion – 0(1), Deletion – 0(1), Maximum – 0(n), Minimum – 0(n)
(C) Insertion – 0(n), Deletion – 0(n), Maximum – 0(1), Minimum – 0(1)
(D) Insertion – 0(n), Deletion – 0(n), Maximum – 0(n), Minimum – 0(n)

In a sorted array, if we want to insert or delete then we have to traverse whole array and check where
is the suitable position, so it will take
O(n).
If array is sorted then end position will tell the maximum or minimum, so finding maximum or
minimum will take O(1).

Which of the following algorithm does not divide the list?


(A) merge sort
(B) binary search
(C) linear search
(D) quick sort

he average case of quick sort has order


(A) O(n2)
(B) O(n)
(C) O(n log n).
(D) O(log n)

You might also like