Anda di halaman 1dari 7

Viva Questions

Introduction
 What is data structure?
 What Is Algorithm?
 Why We Need To Do Algorithm Analysis?
 What Are The Criteria Of Algorithm Analysis? (Time and Space)
 Types of data Structures? (Primitive .... int float double char etc. Non-Primitive..... Linear (stack array queue link list) Non-
Linear(tree graph))
 What does run time of algorithm depends on? (input size and nature of input)
 How do we analyze an algorithm theoretically(Big O etc analysis) and practically(using time functions of programming
languages)
 How many functions are considered for algorithmic analysis? (Seven....
constant,logrithmic,linear,nlogn,quadratic,cubic,exponential)
 What is recursion or recursive functions?
 General form of recursion? (Start with stopping condition and return stopping value then recursive call)
 What do you mean by: Syntax Error, Logical Error, Run time Error?

ADTs Arrays and Linked Lists


 What is an ADT? (Set of objects+ Set of operations)
 Basic operations that can be performed on ADTs?(insert,delete,search etc)
 Why do we call abstract? (no specific implementation )
 What is an array?
 Define a 2D array
 What is a link list?
 Compare arrays and link lists
 Types of link lists?
 What is a node?
 Whether Linked List is linear or Non-linear data structure?(According to Access strategies Linked list is a linear one.
According to Storage Linked List is a Non-linear one)
 How do you search for a target key in a linked list? To find the target key in a linked list, you have to apply sequential search.
Each node is traversed and compared with the target key, and if it is different, then it follows the link to the next node. This
traversal continues until either the target key is found or if the last node is reached.
 What are the limitations of arrays?
i)Arrays are of fixed size.
ii)Data elements are stored in continuous memory locations which may not be available always.
iii)Adding and removing of elements is problematic because of shifting the locations.

 How can you overcome the limitations of arrays?


Limitations of arrays can be solved by using the linked list.
 What is the basic problem with singly link list? (cannot traverse backwards… use doubly link list)

 How can you reverse the elements in single link list?

 How can you reverse the elements of doubly link list?

 How can you delete the middle element of a link list?

 How can you move last element in singly link list to first? How about doubly link list?

 How can you check if a link list is circular or not?

 How can you convert a singly link list to a circular link list?

Stacks and Queues


 What is a stack?
 Applications of stack?
 What is LIFO and FIFO?
 Stack works on what principle? (LIFO)
 What is a queue?
 Queue works on what principle? (FIFO)
 Basic stack operations? (push, pop, top)
 What does the stack contain if I run following statements in main method? (7,9,6)
Push(5), push(3), pop(), pop(), pop(),push(7), push(9), top(), push(4), pop(),push(6), push(8), pop()

 Which data structures used to perform recursion?


Stack. Because of its LIFO (Last In First Out) property it remembers its 'caller' so knows whom to
return when the function has to return. Recursion makes use of system stack for storing the return
addresses of the function calls.
Every recursive function has its equivalent iterative (non-recursive) function. Even when such
equivalent iterative procedures are written, explicit stack is to be used.
 What are the notations used in Evaluation of Arithmetic Expressions using prefix and postfix forms? (Polish and Reverse
Polish notations)
 What is the difference between a stack and a Queue?
 The result evaluating the postfix expression 10 5 + 60 6 / * 8 – is? (142)
 The best data structure to check whether an arithmetic expression has balanced parenthesis is a stack or a queue? (stack)
 If the sequence of operations - push (1), push (2), pop, push (1), push (2), pop, pop, pop, push (2), pop are performed on a stack,
the sequence of popped out values? (2,2,1,1,2)
 The five items: A, B, C, D, and E are pushed in a stack, one after other starting from A. The stack is popped four items and each
element is inserted in a queue. The two elements are deleted from the queue and pushed back on the stack. Now one item is
popped from the stack. The popped item is? (D)
 Convert to postfix? (ABC*DE/F-G*-H*+)

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

 Convert to prefix and postfix form?


A*B+C/D
Prefix: + * A B / C D
Postfix: A B * C D / +

A * (B + C) / D
Prefix: / * A + B C D
Postfix: A B C + * D /

A * (B + C / D)
Prefix: * A + B / C D
Postfix: A B C D / + *

 Basic queue operations? (enqueue and dequeue)


 What is the status of queue after following statements are executed using main method?(7,9,4)
Enqueue(5), enqueue(3),dequeue(), dequeue(),dequeue(), enqueue(7), enqueue(9), enqueue(4)

Binary Trees and Binary Search Trees


 What is a tree?
 What is a root?
 What is a leaf?
 What is a node?
 What is an internal node?
 What are siblings?
 What are edges?
 What is depth of a node? (num of edges from root to n)
 What is depth of tree? (num of edges from root to longest leaf)
 What is the height of node? (length of longest path from node n to leaf)
 What is height of a tree? (height of root node)
 What are tree traversals?
Inorder (Left, Root, Right) : (b) Preorder (Root, Left, Right) :
(c) Postorder (Left, Right, Root)
 What is a binary tree?
 What is an expression tree?
 How can you create an expression tree? (from postfix expression and a stack)
 In tree construction which is the suitable efficient data structure? (Array, Linked list,
Stack, Queue) Linked list is the suitable efficient data structure
 How do you insert a new item in a binary search tree?
 How can you search for an item in binary search tree?
 What is a complete binary tree? (if all levels except last is completely filled from left to right)
 How can you find min and max element in binary search tree?
 What is a full binary tree?( Each node has exactly zero or two children)

Hashing
 What is hashing?
 Why do we prefer hashing?
 What is a hash function?
 How is hashing done?
 What are components of hashing? (hash table and hash function)
 What is collision?
 How to resolve collisions?
 What should be table size? (a prime)
 What is separate chaining?
 What is load factor? (λ = N / T )
 What is disadvantage of using separate chaining? (link list)
 What is open addressing? Types? (Linear probing quadratic probing, double hashing)
 What is linear probing?
 Solve using linear probing: 81, 70, 97, 60, 51, 38, 89, 68, 24

 How to search for an item using linear probing?


 How to remove an item using linear probing?
 Delete 89 from above table and result is?

 What is primary clustering?


 How can you remove primary clustering in linear probing?
 What is quadratic probing?
 How do u insert elements using quadratic probing?
 What is main problem involved with quadratic probing? (no guarantee that all bins will be used)
 How to delete using quadratic probing?(empty , occupied, deleted)
 What is secondary clustering? (quadratic probing)
 Solution to secondary clustering? (double hashing)
 Insert the 6 elements
14, 107, 31, 118, 34, 112 into an initially empty hash table of size 11 using quadratic hashing
 What is double hashing?
 How do u search or delete an item using double hashing?
 What is problem with double hashing? (multiple deletions may cause most cells to be empty)
 What is solution to double hashing problem? (rehashing)
 What is rehashing?
 Which one is superior/optimal for distributing entries evenly linear or quadratic or double? (double)
 For separate chaining hashing, λ should be close to? 1
 For open addressing hashing, λ should not exceed? 0.5
 Consider a 13 element hash table for which f(key)=key mod 13 is used with integer keys. Assuming linear probing is used for
collision resolution, at which location would the key 103 be inserted, if the keys 661, 182, 24 and 103 are inserted in that order?
(1)

Priority Queues (Heaps)


 What is a priority queue?(insert, deletemin)
 What is degree of a node?
 What is degree of a tree?
 What is a heap?
 What are two basic properties of heaps? (heap order and structure)
 What is structure property? (tree is complete)
 How can we find parent in a array? (i/2)
 How can we find child? (2i and 2i+1)
 What is heap order?
For every node X, the key in the parent of X is smaller than (or equal to) the key in X, except for the root which has no
parent
 How to insert in a heap?(percolate up)
To insert an element X into the heap, we create a hole in the next available location
If X can be placed in the hole without violating the heap order, then we do so and are done
Otherwise we slide the element that is in the hole’s parent node into the hole, thus bubbling the hole up toward the root
We continue this process until X can be placed in the hole
 What is percolate up?
 How is a min element deleted in a heap?
o Delete the root
o Can the last element X be placed in the hole?
o Slide the smaller of the hole’s children into the hole, thus pushing the hole down one level
o Repeat this until X can be placed in a hole
 What is a decrease key operation for min heap?
 What is increase key for min heap?
 How can we delete an element from a heap? (First DecreaseKey(P, ∞ , H) , and then DeleteMin(H))
 What is buildheap operation?
Takes as input N keys and places them into an empty heap
N successive Inserts
Place N keys into the tree in any order but maintain complete tree structure
Starting from N/2 to the root, percolate down
 Applications of priority queues?
 Given following heap
Draw the binary heap created by the following code:
t−>insert (71); t−>delete (19); t−>delete (1); t−>delete (7); t−>insert (77); t−>insert (78); t−>insert (79); t−>insert (80);
o What is the difference between a priority queue and a queue?

Sorting
o How to sort using insertion sort?

o How do u sort using shellsort?


o 54, 26, 93, 17, 77, 31, 44, 55, 20
Use Shellsort with a gap size of 3
o How do u sort using heap sort?

o create max heap

Sort using heap sort


o What is merge sort?
o Sort using mergesort above?
o What is quick sort?
o What is pivot?
o How do u select pivot?
o How do u separate elements after selecting pivot?

Graphs
o What is a graph?
o What are edges?
o What is a vertex?
o What are different types of edges? (directed undirected, loop multiple edges)
o What are different graph types? (simple directed multigraph directed multigraph pseudograph)
o Directed multigraph contains loops and multi edges while pseudograph is undirected with loop
o What is a loop?
o What is degree of vertex?
o What is pendant vertex? (with only one edge)
o What is isolated vertecx?
o What is in degree and out degree of a directed graph?
o What is a complete graph?
o What is a cycle?
o What is a wheel?
o What is a bipartite graph?
o How can you represent graphs? (edge list, adjax=cency list, adjacency matrix, incidence matrix)
o What is an edge list?
o What is incidence matrix?

o Incidence matrix of

o What is adjacency matrix?

o Adjacency matrix of

o
o

o What is adjacency list?

o What is a connected graph?

o What is strongly conncted and weakly connected graph?

o What is traversability?

o How can you tell if a graph or shape is traversable? (all vertices are of even degree
or
Exactly two vertices are of odd order and rest are even
)
o What is an eulierian path? (An Eulerian path (Eulerian trail, Euler walk) in a graph is a path that uses each edge precisely
once. If such a path exists, the graph is called traversable)
o What is Hamiltonian path?( Hamiltonian path (also called traceable path) is a path that visits each vertex exactly once.)
o What algorithms can you run to find shortest path ? BFS DFS Dijkstras
o What is BFS?
o What is DFS?
o What is Dijkstras algorithm?
o Starting with node S, Perform BFS on the following graph

o
o BFS: S,A,C,G,B,D,E,F,H
o
o DFS: S,A,B,C,D,E,H,G,F

Anda mungkin juga menyukai