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

CS3301 - Data Structures

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

CS3301 - Data Structures

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

lOMoARcPSD|31565132

lOMoARcPSD|31565132

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING

CS3301– DATA STRUCTURES

Question Bank

II YEAR / BATCH : 2022 -26


lOMoARcPSD|31565132

Vision of Institution
To build Jeppiaar Engineering College as an Institution of Academic Excellence in Technical
education and Management education and to become a World Class University.
Mission of Institution

M1 To excel in teaching and learning, research and innovation by promoting the


principles of scientific analysis and creative thinking

M2 To participate in the production, development and dissemination of knowledge and


interact with national and international communities

M3 To equip students with values, ethics and life skills needed to enrich their lives and
enable them to meaningfully contribute to the progress of society

M4 To prepare students for higher studies and lifelong learning, enrich them with the
practical and entrepreneurial skills necessary to excel as future professionals and
contribute to Nation’s economy

Program Outcomes (POs)


Engineering Knowledge: Apply the Knowledge of mathematics, science,
PO1 engineering fundamentals, and an engineering specialization to the solution of
complex engineering problems.
Problem analysis: Identify, formulate, review research literature, and analyze
PO2 complex engineering problems reaching substantiated conclusions using first
principles of mathematics, natural sciences, and engineering sciences.
Design/development of solutions: Design solutions for complex engineering
problems and design system components or processes that meet the specified
PO3
needs with appropriate consideration for the public health and safety, and the
cultural, societal, and environmental considerations
Conduct investigations of complex problems: Use research-based Knowledge
PO4 and research methods including design of experiments, analysis and interpretation
of data, and synthesis of the information to provide valid conclusions.
Modern tool usage: Create, select, and apply appropriate techniques, resources,
PO5 and modern engineering and IT tools including prediction and modeling to
complex engineering activities with an understanding of the limitations.
The engineer and society: Apply reasoning informed by the contextual
PO6 Knowledge to assess societal, health, safety, legal and cultural issues and the
consequent responsibilities relevant to the professional engineering practice.
Environment and sustainability: Understand the impact of the professional
PO7 engineering solutions in societal and environmental contexts, and demonstrate
the Knowledge of, and need for sustainable development.
Ethics: Apply ethical principles and commit to professional ethics
PO8
and responsibilities and norms of the engineering practice.
Individual and team work: Function effectively as an individual, and as a
PO9
member or leader in diverse teams, and in multidisciplinary settings.
lOMoARcPSD|31565132

Communication: Communicate effectively on complex engineering activities


with the engineering community and with society at large, such as, being able to
PO10
comprehend and write effective reports and design documentation, make effective
presentations, and give and receive clear instructions.
Project management and finance: Demonstrate Knowledge and understanding
of the engineering and management principles and apply these to one’s own work,
PO11
as a member and leader in a team, to manage projects and in multidisciplinary
environments.
Life-long learning: Recognize the need for, and have the preparation and ability
PO12 to engage in independent and life-long learning in the broadest context of
technological change.
Vision of Department
To emerge as a globally prominent department, developing ethical computer professionals,
innovators and entrepreneurs with academic excellence through quality education and research.
Mission of Department

M1 To create computer professionals with an ability to identify and formulate the


engineering problems and also to provide innovative solutions through effective teaching
learning process.

M2 To strengthen the core-competence in computer science and engineering and to create


an ability to interact effectively with industries.

M3 To produce engineers with good professional sKills, ethical values and life skills for the
betterment of the society.

M4 To encourage students towards continuous and higher level learning on technological


advancements and provide a platform for employment and self-employment.

Program Educational Objectives (PEOs)


PEO1 To address the real time complex engineering problems using innovative
approach with strong core computing skills.

PEO2 To apply core-analytical Knowledge and appropriate techniques and provide


solutions to real time challenges of national and global society

PEO3 Apply ethical Knowledge for professional excellence and leadership for the
betterment of the society.

PEO4 Develop life-long learning skills needed for better employment and
entrepreneurship
lOMoARcPSD|31565132

SYLLABUS

UNIT I LISTS 9
Abstract Data Types (ADTs) – List ADT – Array-based implementation – Linked list
implementation – Singly linked lists – Circularly linked lists – Doubly-linked lists – Applications
of lists – Polynomial ADT – Radix Sort – Multilists.

UNIT II STACKS AND QUEUES 9


Stack ADT – Operations – Applications – Balancing Symbols – Evaluating arithmetic expressions-
Infix to Postfix conversion – Function Calls – Queue ADT – Operations – Circular Queue –
DeQueue – Applications of Queues.

UNIT III TREES 9


Tree ADT – Tree Traversals - Binary Tree ADT – Expression trees – Binary Search Tree ADT –
AVL Trees – Priority Queue (Heaps) – Binary Heap.

UNIT IV MULTIWAY SEARCH TREES AND GRAPHS 9


B-Tree – B+ Tree – Graph Definition – Representation of Graphs – Types of Graph - Breadth-
first traversal – Depth-first traversal –– Bi-connectivity – Euler circuits – Topological Sort –
Dijkstra's algorithm – Minimum Spanning Tree – Prim's algorithm – Kruskal's algorithm

UNIT V SEARCHING, SORTING AND HASHING TECHNIQUES 9


Searching – Linear Search – Binary Search. Sorting – Bubble sort – Selection sort – Insertion sort
– Shell sort –. Merge Sort – Hashing – Hash Functions – Separate Chaining – Open Addressing –
Rehashing – Extendible Hashing.

TEXT BOOKS:
1. Mark Allen Weiss, “Data Structures and Algorithm Analysis in C”, 2nd Edition, Pearson
Education,2005.
2. Kamthane, Introduction to Data Structures in C, 1st Edition, Pearson Education, 2007

REFERENCES:

1. Langsam, Augenstein and Tanenbaum, Data Structures Using C and C++, 2nd Edition,
Pearson Education, 2015.
2. Thomas H. Cormen, Charles E. Leiserson, Ronald L.Rivest, Clifford Stein, Introduction to
Algorithms", Fourth Edition, Mcgraw Hill/ MIT Press, 2022.
3. Alfred V. Aho, Jeffrey D. Ullman,John E. Hopcroft ,Data Structures and Algorithms, 1st
edition, Pearson, 2002.
4. Kruse, Data Structures and Program Design in C, 2nd Edition, Pearson Education, 2006.
lOMoARcPSD|31565132

Course Outcomes (COs)


C311.1 1. Implement abstract data type for List linear data structure and apply them to problem
solutions
C311.2 2. Implement abstract data type for Stack and Queue data structure and apply them to problem
solutions
C311.3 3. Implement abstract data type for Tree non list linear data structure and apply them to
problem solutions
C311.4 4. Implement abstract data type for Graph non list linear data structure and apply them to
problem solutions
C311.5 Analyze the various sorting and searching algorithms and hashing techniques

BLOOM TAXANOMY LEVELS


BTL 6: Creating
BTL 5: Evaluating
BTL 4: Analyzing
BTL 3: Applying
BTL 2: Understanding
BTL 1: Remembering

INDEX

UNIT NO TEXT/ REFERENCE BOOK PAGE


NO
UNIT -I 1. Mark Allen Weiss, “Data Structures and Algorithm Analysis in
C”, 2nd Edition, Pearson Education,1997.
2. Reema Thareja, “Data Structures Using C”, Second Edition ,
Oxford University Press, 2011

UNIT -II 1. Mark Allen Weiss, “Data Structures and Algorithm Analysis in
C”, 2nd Edition, Pearson Education,1997.
2. Reema Thareja, “Data Structures Using C”, Second Edition , Oxford
University Press, 2011
UNIT -III 1. Mark Allen Weiss, “Data Structures and Algorithm Analysis in
C”, 2nd Edition, Pearson Education,1997.
2. Reema Thareja, “Data Structures Using C”, Second Edition ,
Oxford University Press, 2011
UNIT -IV 1. Mark Allen Weiss, “Data Structures and Algorithm Analysis in
C”, 2nd Edition, Pearson Education,1997.
2. Reema Thareja, “Data Structures Using C”, Second Edition ,
Oxford University Press, 2011
UNIT -V 1. Mark Allen Weiss, “Data Structures and Algorithm Analysis in
C”, 2nd Edition, Pearson Education,1997.
2. Reema Thareja, “Data Structures Using C”, Second Edition , Oxford
University Press, 2011
lOMoARcPSD|31565132

UNIT I

Topics Text / Reference book Page No.

Abstract Data Types (ADTs) 57

List ADT – array-based implementation 58-59

linked list implementation 1. Mark Allen Weiss, “Data 59


Structures and Algorithm
singly linked lists Analysis in C”, 2nd Edition, 60
Pearson Education,1997.
circularly linked lists 68

doubly-linked lists 67

applications of lists –Polynomial 73


Manipulation
All operations (Insertion, Deletion, 73
Merge, Traversal).

S. Question
No
.
1 What is a data structure?
• A data structure is a method for organizing and storingdata which would allow
efficient
data retrieval and usage.
• A data structure is a way of organizing data thatconsiders not only the
items stored, but
also their relationships to each other.

2 Why do we need data structures?


• Data structures allow us to achieve an importantgoal: component reuse.
• Once data structure has been implemented, it can be used again and again in
various applications.

3 List some common data structures.


• Stacks
• Queues
• Lists
• Trees
• Graphs
• Tables
lOMoARcPSD|31565132

4 How data structures are classified?


Data structures are classified into two categories based on how the data items are
operated:
i. Primitive data structure
ii. Non-Primitive data structure
a. Linear data structure
b. Non-linear data structure

5 Differentiate linear and non-linear data structure.


Linear data structure Non-linear data structure
Data are arranged in linear orsequential Data are not arranged in linearmanner
manner

Every items is related to its previous Every item is attached withmany other
and next item items

Data items can be traversed in a Data items cannot betraversed in


single run. a
single run.

Implementation is easy Implementation is difficult.


Example: array, stack, queue,linked Example: tree, graph
list

6 Define ADT (Abstract Data Type)


An abstract data type (ADT) is a set of operations and mathematical abstractions ,
which
can be viewed as how the set of operations is implemented.Objects like lists, sets and
graphs, along with their operation, can be viewed as abstract data types, just as integers, real
numbers and Booleans.

7 Mention the features of ADT.


a. Modularity
i. Divide program into small functions
ii. Easy to debug and maintain
iii. Easy to modify
b. Reuse
i. Define some operations only once and reuse them in future
c. Easy to change the implementation

8 Define List ADT


A list is a sequence of zero or more elements of a giventype. The list is
represented as
sequence of elements separated by comma.A1, A2, A3…..AN
Where N>0 and A is of type element
lOMoARcPSD|31565132

9 What are the ways of implementing linked list?


The list can be implemented in the following ways:
i. Array implementation
ii. Linked-list implementation
iii. Cursor implementation

10 What are the types of linked lists?


There are three types
i. Singly linked list
ii. Doubly linked list
iii. Circularly linked list
11 How the singly linked lists can be represented?

Each node has two elements


i. Data
ii. Next

12 How the doubly linked list can be represented?

Doubly linked list is a collection of nodes where nodesare connected by


forwarded and
backward link.
Each node has three fields:
1. Address of previous node
2. Data
3. Address of next node.

13 What are benefits of ADT?


a. Code is easier to understand
b. Implementation of ADT can be changed without requiringchanges to the program
that uses the ADT

14 When singly linked list can be represented as circular linkedlist?


In a singly linked list, all the nodes are connected withforward links to the next
nodes in
the list. The last node has a next field, NULL. In order toimplement the circularly
linked
lOMoARcPSD|31565132

lists from singly linked lists, the last node’s next field is connected to the first
node.

15 When doubly linked list can be represented as circular linkedlist?


In a doubly linked list, all nodes are connected withforward and
backward links to the
next and previous nodes respectively. In order to implementcircular linked lists
from
doubly linked lists, the first node’s previous field is connected tothe last node and the
last node’s next field is connected to the first node.

16 Where cursor implementation can be used?


The cursor implementation of lists is used by manylanguages such as
BASIC and
FORTRAN that do not support pointers. The two importantfeatures of the cursor
implementation of linked are as follows:
• The data are stored in a collection of structures. Eachstructure contains
data and a
index to the next structure.
• A new structure can be obtained from the system’s globalmemory by a call to
cursorSpace array.

17 List down the applications of List.


a. Representation of polynomial ADT
b. Used in radix and bubble sorting
c. In a FAT file system, the metadata of a large file is organizedas a linked list of
FAT entries.
d. Simple memory allocators use a free list of unused memoryregions, basically a
linked list with the list pointer inside the free memory itself.

18 What are the advantages of linked list?(apr/may 2019)


a. Save memory space and easy to maintain
b. It is possible to retrieve the element at a particular index
c. It is possible to traverse the list in the order of increasing index.
d. It is possible to change the element at a particular index to adifferent
value,without affecting any other elements.
lOMoARcPSD|31565132

19 Mention the demerits of linked list


a. It is not possible to go backwards through the list
b. Unable to jump to the beginning of list from the end.

20 The polynomial equation can be represented with linked listas follows:

Coefficient Exponent Next node link

struct polynomial
{
int coefficient;int exponent;
struct polynomial *next;
};

21 What are the operations performed in list?


The following operations can be performed on a list
i. Insertion
a. Insert at beginning
b. Insert at end
c. Insert after specific node
d. Insert before specific node
ii. Deletion
a. Delete at beginning
b. Delete at end
c. Delete after specific node
d. Delete before specific node
iii. Merging
iv. Traversal

22 What are the merits and demerits of array implementation oflists?


Merits
• Fast, random access of elements
• Memory efficient – very less amount of memory is required
Demerits
• Insertion and deletion operations are very slow since theelements should be
moved.
• Redundant memory space – difficult to estimate the sizeof array.

23 What is a circular linked list?


A circular linked list is a special type of linked list thatsupports traversing from
the end
of the list to the beginning by making the last node point back tothe head of the list.
lOMoARcPSD|31565132

24 What are the advantages in the array implementation of list?


a. Print list operation can be carried out at the linear time
b. Find Kth operation takes a constant time

25 What is the need for the header?


Header of the linked list is the first element in the list andit stores the number of
elements in the list. It points to the first data element of the list.

26 List three examples that uses linked list?


a. Polynomial ADTb.Radix sort c.Multi lists

27 List out the different ways to implement the list?


1. Array Based Implementation
2. Linked list Implementation
i. Singly linked list
ii. Doubly linked list
iii. Cursor based linked list

28 Write the routine for insertion operation of singly linked list.


Void Insert (ElementType X, List L, Position P)
{Position TmpCell; TmpCell=malloc(sizeof(struct Node));
if(TmpCell==NULL)
FatalError(“Out of space!!!”);
TmpCell->Element =X; TmpCell->Next=P->Next;P->Next=TmpCell;
}

29 Advantages of Array over Linked List.


1. Array has a specific address for each element stored in it and thus we can access any
memory directly.
2. As we know the position of the middle element and otherelements are easily accessible
too, we can easily performBINARY SEARCH in array.

30 Disadvantages of Array over Linked List.


1. Total number of elements need to be mentioned or thememory allocation needs to
be done at the time of array creation
2. The size of array, once mentioned, cannot be increasedin the program. If number of
elements entered exceeds the
lOMoARcPSD|31565132

size of the array ARRAY OVERFLOW EXCEPTION occurs.

31 Advantages of Linked List over Array.


1. Size of the list doesn't need to be mentioned atthe beginning of the
program.
2. As the linked list doesn't have a size limit, we can go onadding new nodes
(elements) and increasing the size of the list to any extent.

32 Disadvantages of Linked List over Array.


1. Nodes do not have their own address. Only the address of the first node is stored
and in order to reach any node, weneed to traverse the whole list from
beginning to the desired node.
2. As all Nodes don't have their particular address, BINARY SEARCH
cannot be performed

33 Difference between linear linked list and circular linked list(apr/may 2019)
Linked list are used to create trees and graphs. Circular linked list : In circular linked list
the last node address part holds the address of the first node hence forming a circular chain
like structure ...............................................................................Linked
list is a linear data structure which consists of group of nodes in a sequence

34 Enlist the various operations that can be performed on datastructure.


Various operations that can be performed on the data structure are •Create • Insertion of
element • Deletion of element • Searching for the
desired element • Sorting the elements in the data structure • Reversing the list of elements.

35 What are all not concerned in an ADT?


The abstract data type is a triple of D i.e. set of axioms, F-set offunctions and A-Axioms
in which only what is to be done is mentioned
but how is to be done is not mentioned. Thus ADT is not concernedwith implementation
details
37 List out the areas in which data structures are applied extensively.

Following are the areas in which data structures are appliedextensively


Operating system- the data structures like priority queues are used forscheduling the jobs in the
operating system.
• Compiler design- the tree data structure is used in parsing the source program. Stack data
structure is used in handling recursive calls.
• Database management system- The file data structure is used in database management
systems. Sorting and searching techniques canbe applied on these data in the file.
• Numerical analysis package- the array is used to perform the numerical analysis on
the given set of data.
• Graphics- the array and the linked list are useful ingraphics applications.
• Artificial intelligence- the graph and trees are used for theapplications like
building expression trees, game playing.
lOMoARcPSD|31565132

38 What are the pitfall encountered in singly linked list?


Following are the pitfall encountered in singly linked list • The singly linked list has only
forward pointer and no backward link is provided. Hence the traversing of the list is possible
only in one direction. Backward traversing is not possible. • Insertion and deletion operations
are less efficient because for inserting the element at desired
position the list needs to be traversed. Similarly, traversing of the list is required for locating the
element which needs to be deleted.

40 Write down the steps to modify a node in linked lists.


➢ Enter the position of the node which is to be modified.
➢ Enter the new value for the node to be modified.
➢ Search the corresponding node in the linked list.
➢ Replace the original value of that node by a new value
. ➢ Display the messages as “ the node is modified”.

41 State the properties of LIST abstract data type with suitableexample.


Various properties of LIST abstract data type are
(i) It is linear data structure in which the elements arearranged adjacent to
each other.
(ii) )It allows to store single variable polynomial
(iii) (iii)If the LIST is implemented using dynamic memory then it
is called linked list. Example of LIST are- stacks, queues,linked list

42 Why is the linked list used for polynomial arithmetic?


We can have separate coefficient and exponent fields for representing
each term of polynomial. Hence there is no limit for exponent. We canhave any number as an
exponent.
43 What is the basic purpose of header of the linked list?

The header node is the very first node of the linked list. Sometimes a
dummy value such - 999 is stored in the data field of header node. This node is useful for
getting the starting address of the linked list.
44 What is static linked list? State any two applications of it.
➢ The linked list structure which can be represented using arrays iscalled static linked list.
➢ It is easy to implement, hence for creation of small databases, itis useful
.➢ The searching of any record is efficient, hence the applications in which the record need to
be searched quickly, the static linked list areused.
lOMoARcPSD|31565132

PART-B

1 Explain the various operations of the list ADT with examples C311.1
BTL 2
2 Write the program for array implementation of lists C311.1 BTL 5

3 Write a C program for linked list implementation of list. C311.1 BTL 5

4 Explain the operations of singly linked lists C311.1 BTL 2

5 Explain the operations of doubly linked lists C311.1 BTL 2

6 Explain the operations of circularly linked lists C311.1 BTL 2

7 How polynomial manipulations are performed with lists? C311.1 BTL 1


Explain the operations
8 Explain the steps involved in insertion and deletion into a C311.1 BTL2
singly and doubly linked list.
lOMoARcPSD|31565132

UNIT II

Topics Text / Reference book Page No.

Stack ADT 78

Operations 79

Applications – Evaluating arithmetic 1. Mark Allen Weiss, 87


expressions- Conversion of Infix to “Data Structures and
postfix expression Algorithm Analysis in
C”, 2nd Edition,
Queue ADT Pearson 95
Education,1997.
Operations 95

Circular Queue 95

Priority Queue - deQueue 98

applications of queues 100

S. Question
No.

1 Define Stack.
A stack is an ordered list in which all insertions and deletions are made at one
end, called
the top. It is an abstract data type and based on the principle of LIFO (Last In First Out).

2 What are the operations of the stack?


a. CreateStack/ InitStack(Stack) – creates an empty stack
b. Push(Item) – pushes an item on the top of the stack
c. Pop(Item) – removes the top most element from the stack
lOMoARcPSD|31565132

d. Top(Stack) – returns the first element from the stack


e. IsEmpty(Stack) – returns true if the stack is empty

3 Write the routine to push a element into a stack.


Push(Element X, Stack S)
{
if(IsFull(S)
{
Error(“Full Stack”);
}
else S→Array[+
+S→TopOfStack]=X;
}

4 How the operations performed on linked listimplementation of


stack?
a. Push and pop operations at the head of the list.
b. New nodes should be inserted at the front of the list, so thatthey become the top
of the stack.
c. Nodes are removed from the front(top) of the stack.

5 What are the applications of stack?


The following are the applications of stacks
• Evaluating arithmetic expressions
• Balancing the parenthesis
• Towers of Hanoi
• Function callsTree traversal

6 What are the methods to implement stack in C?


The methods to implement stacks are:
• Array based
• Linked list based

7 How the stack is implemented by linked list?


It involves dynamically allocating memory space at runtime while
performing stack
operations.
Since it consumes only that much amount of space is requiredfor holding its data
elements , it prevents wastage of memory space.struct stack
{
int element;
struct stack *next;
}*top;

8 Write the routine to pop a element from a stack.


int pop()
{
if(top==NULL)
lOMoARcPSD|31565132

{
printf(“\n Stack is empty.\n”);getch();
exit(1);
}
else
{
int temp;
temp=top→element; /* retreiving the top element*/top=top→next; /*
Updating the stack pointer */ return temp; /* returning the popped value
*/
}
}

9 Define queue.
It is a linear data structure that maintains a list ofelements such that
insertion happens at
rear end and deletion happens at front end. FIFO – First In First
Out principle

10 What are the operations of a queue?


The operations of a queue are
• isEmpty()
• isFull()
• insert()
• delete()
• display()

11 Write the routine to insert a element onto a queue.


void insert(int element)
{
if(front==-1 )
{
front = rear = front +1; queue[front] =
element;return;
}
if(rear==99)
{
printf(“Queue is full”);getch();
return;
}
rear = rear +1; queue[rear]=element;
}

12 What are the types of queue?


The following are the types of queue:
lOMoARcPSD|31565132

• Double ended queue


• Circular queue
• Priority queue

13 Define double ended queue


• It is a special type of queue that allows insertion anddeletion of elements
at both
Ends.
• It is also termed as DEQUE.

14 What are the methods to implement queue in C?


The methods to implement queues are:
• Array based
• Linked list based

15 How the queue is implemented by linked list?


• It is based on the dynamic memory management techniques which allow
allocation and
De-allocation of memory space at runtime.
Insert operation
It involves the following subtasks:
1. Reserving memory space of the size of a queue elementin memory
2. Storing the added value at the new location
3. Linking the new element with existing queue
4. Updating the rear pointer
Delete operation
It involves the following subtasks:
1. Checking whether queue is empty
2. Retrieving the front most element of the queue
3. Updating the front pointer
4. Returning the retrieved value

16 Write the routine to delete a element from a queue


int del()
{
int i;
if(front == NULL) /*checking whether the queue is empty*/
{
return(-9999);
}
else
{
i = front→element;
lOMoARcPSD|31565132

front = front→next;return i;
}
}

17 What are the applications of queue?


The following are the areas in which queues are applicable
a. Simulation
b. Batch processing in an operating systems
c. Multiprogramming platform systems
d. Queuing theory
e. Printer server routines
f. Scheduling algorithms like disk scheduling , CPU scheduling
g. I/O buffer requests

18 Define circular queue


A Circular queue is a queue whose start and end locations are logically connected
with
each other. That means the start location comes after the end location.

19 What are push and pop operations?


• Push – adding an element to the top of stack
• Pop – removing or deleting an element from the top of stack

20 What are enqueue and dequeue operations?


• Enqueue - adding an element to the queue at the rear end
If the queue is not full, this function adds an element tothe back of the
queue, else it prints “OverFlow”.
void enqueue(int queue[], int element, int& rear, int arraySize)
{
if(rear == arraySize) // Queue is full
printf(“OverFlow\n”);
else{
queue[rear] = element; // Add the element to the back rear++;
}
}

• Dequeue – removing or deleting an element from the queueat the front end
lOMoARcPSD|31565132

If the queue is not empty, this function removes theelement from the
front of the queue, else it prints “UnderFlow”.
void dequeue(int queue[], int& front, int rear)
{ if(front == rear) // Queue is empty
printf(“UnderFlow\n”);
else {
queue[front] = 0; // Delete the front elementfront++;
}
}

21 Distinguish between stack and queue.

STACK QUEUE

Insertion and deletion aremade at one Insertion at one end rearand deletion
end. at other endfront.

The element inserted last would be The element inserted first would be
removed first. SoLIFO structure. removed first. SoFIFO structure.

Full stack condition: Full stack condition:

If(top==Maxsize) If(rear = = Maxsize)

Physically and Logically fullstack Logically full. Physicallymay or


may not be full.

22 Convert the infix (a+b)*(c+d)/f into postfix & prefixexpression

Postfix :ab+cd+*f/

Prefix :/*+ab+cdf

23 Write postfix from of the expression –A+B-C+D?

A-B+C-D+

24 How do you test for an empty queue?


To test for an empty queue, we have to check whether READ=HEAD where
REAR is a pointer pointing to the last node in a queue and HEAD is a pointer that
pointer to the dummy header. In the case of array implementation of queue,
lOMoARcPSD|31565132

the condition to be checked for an empty queueis READ<FRONT.

25 What are the postfix and prefix forms of the expression?


A+B*(C-D)/(P-R)
Postfix form: ABCD-*PR-/+Prefix form: +A/*B-
CD-PR

26 Explain the usage of stack in recursive algorithmimplementation?


In recursive algorithms, stack data structures is used to store the return address
when a recursive call is encountered and also to store the values of all the parameters
essential to thecurrent state of the procedure.

27 Define priority queue with diagram and give the operations.


Priority queue is a data structure that allows at least thefollowing two
operations.
1. Insert-inserts an element at the end of the list called the rear.
2. DeleteMin-Finds, returns and removes the minimum element in the priority
Queue.

Operations: Insert, DeleteMin

28 Give the applications of priority queues.


There are three applications of priority queues
1. External sorting.
2. Greedy algorithm implementation.
3. Discrete even simulation.
4. Operating systems.

29 How do you test for an empty stack?


To check if the stack is empty, we only need to check whether top and
bottom are the same number.
bool stack_empty(stack S) //@requires is_stack(S);
{ return S->top == S->bottom; }

30 What are the features of stacks?


• Dynamic data structures
• Do not have a fixed size
• Do not consume a fixed amount of memory
• Size of stack changes with
each push() and pop() operation.
lOMoARcPSD|31565132

Each push() and pop() operation increases and decreases the size of the stack
by 1, respectively.

31 Write a routine for IsEmpty condition of queue.


If a queue is empty, this function returns 'true', else it returns 'false'.
bool isEmpty(int front, int rear)
{ return (front == rear);
}

32 How do you test for an empty stack?


The condition for testing an empty stack is top =-1, where top isthe pointer pointing
to the topmost element of the stack, in the array implementation of stack. In linked
list implementation of
stack the condition for an empty stack is the header node link field is NULL.

33 Define a suffix expression.


The notation used to write the operator at the end of the operands is called suffix notation.
Suffix notation format : operand operand
operator Example: ab+, where a & b are operands and ‘+’ is additionoperator

34 What do you meant by fully parenthesized expression? Give example. A pair of


parentheses has the same parenthetical level as
that of the operator to which it corresponds. Such an expression iscalled fully
parenthesized expression. Ex: (a+((b*c) + (d * e))
35 Write the postfix form for the expression -A+B-C+D?
A-B+C-D+
36 What are the postfix and prefix forms of the expression?
A+B*(C-D)/(P-R)
Postfix form: ABCD-*PR-/+Prefix form: +A/*B-
CD-PR
37 Explain the usage of stack in recursive algorithmimplementation?

In recursive algorithms, stack data structures is used to store the return address when a
recursive call is encountered and also to store
the values of all the parameters essential to the current state of the function.

38 Write down the function to insert an element into a queue, inwhich the queue is
implemented as an array
Q – Queue X – element to added to the queue Q IsFull(Q) – Checks and true if Queue Q is
full Q->Size - Number of elements in the queue Q Q->Rear – Points to last element of the
queue Q Q->Array –array used to store queue elements void enqueue (int X, Queue Q) {
if(IsFull(Q)) Error (“Full queue”); else { Q->Size++; Q->Rear = Q-
>Rear+1; Q->Array[ Q->Rear ]=X; } }

PART-B
1 Explain Stack ADT and its operations C311.2 BTL5
2 Explain array based implementation of stacks C311.2 BTL5

Explain linked list implementation of stacks C311.2 BTL2


3
lOMoARcPSD|31565132

4 Explain the applications of Stacks C311.2 BTL5

5 Explain how to evaluate arithmetic expressions using stacks C311.2 BTL5

6 Explain queue ADT C311.2 BTL2


7 Explain array based implementation of queues C311.2 BTL2

8 Explain linked list implementation of queues C311.2 BTL2

9 Explain the applications of queues C311.2 BTL5

10 Explain circular queue and its implementation C311.2 BTL2

11 Explain double ended queue and its operations C311.2 BTL2

12 Explain priority queue and its operations C311.2 BTL5


lOMoARcPSD|31565132

UNIT III

Topics Text / Reference book Page No.

Tree ADT– tree traversals 106

Binary Tree ADT 111


1. Mark Allen Weiss,
expression trees – applications of trees “Data Structures and 113
Algorithm Analysis in
binary search tree ADT–Threaded C”, 2nd Edition, 116
Binary Trees Pearson
AVL Trees Education,1997. 126

B-Tree 149

B+ Tree 154

Heap - Applications of heap. 208


lOMoARcPSD|31565132

S. Question
No.

1 Define non-linear data structure


Data structure which is capable of expressing more complex relationship
than that of physical adjacency is callednon-linear data structure.

2 Define tree?
A tree is a data structure, which represents hierarchicalrelationship between
individual data items.

3 Define leaf?
In a directed tree any node which has out degree o is called a terminal
node or a leaf.

4 Explain the representations of priority queue.


Using Heap structure, Using Linked List

5 List out the steps involved in deleting a node from a binary search tree.
1. t has no right hand child node t->r == z
2. t has a right hand child but its right hand child node hasno left sub tree
t->r->l == z
3.t has a right hand child node and the right hand child node has a left hand
child node t->r-
>l != z

6 Convert the infix expression (A-B/C)*(D/E-F) into a postfix.


Postfix: ABC/-DE/F-*

7 What are the steps to convert a general tree into binary tree?
* use the root of the general tree as the root of the binary tree
* determine the first child of the root. This is the leftmost nodein the general tree at
the next
level
* insert this node. The child reference of the parent node refersto this node
* continue finding the first child of each parent node and insertit below the parent
node with the
child reference of the parent to this node.
* when no more first children exist in the path just used, moveback to the parent of
the last node
entered and repeat the above process. In other words,determine the first
sibling of the last
node entered.
* complete the tree for all nodes. In order to locate where thenode fits you must
search for the
lOMoARcPSD|31565132

first child at that level and then follow the sibling references to a nil where the
next sibling can
be inserted. The children of any sibling node can be insertedby locating the parent
and then
inserting the first child. Then the above process is repeated.

What is meant by directed tree?


8 Directed tree is an acyclic diagraph which has one node called its root with in
degree o while all other nodes have in degree I.

9 What is a ordered tree?


In a directed tree if the ordering of the nodes at each level is prescribed then such
a tree is called ordered tree.

10 What are the applications of binary tree?


1. Binary tree is used in data processing.
2. File index schemes
3. Hierarchical database management system

11 What is meant by traversing?


Traversing a tree means processing it in such a way, thateach node is
visited only once.

12 What are the different types of traversing?


The different types of traversing are
a. Pre-order traversal-yields prefix form of expression.
b. In-order traversal-yields infix form of expression.
c. Post-order traversal-yields postfix form of expression.
13 What are the two methods of binary tree implementation?

Two methods to implement a binary tree are


a. Linear representation.
b. Linked representation

14 What is a balance factor in AVL trees?


Balance factor of a node is defined to be the differencebetween the height of the
node's left subtree and the height ofthe node's right subtree.

15 What is meant by pivot node?


The node to be inserted travel down the appropriate branch track along the way of the
deepest level node on the branch that has a balance factor of +1 or -1 is called pivot
node.

16 What is the length of the path in a tree?


lOMoARcPSD|31565132

The length of the path is the number of edges on the path. In a treethere is exactly
one path form the root to each node.

17 Define expression trees?


The leaves of an expression tree are operands such as constants or variable names
and the other nodes contain operators.

18 What is a threaded binary tree?


A threaded binary tree may be defined as follows: "A binary tree is threaded by
making all right child pointers that would normally be null point to the inorder
successor of the node, and all left child pointers that would normally be null point
to the inorder predecessor of the node

19 What is meant by binary search tree?


Binary Search tree is a binary tree in which each internal node x stores an
element such that the element stored in the left sub tree of x are less than or equal
to x and elements stored inthe right sub tree of x are greater than or equal to x.

20 Write the advantages of threaded binary tree.


The difference between a binary tree and the threaded binarytree is that in the
binary trees the nodes are null if there is no child associated with it and so there is
no way to traverse back. But in a threaded binary tree we have threads associated
with the nodes i.e they either are linked to the predecessor or successor in the in
order traversal of the nodes.
This helps us to traverse further or backward in the in order traversal fashion.
There can be two types of threaded binary tree :-
1) Single Threaded: - i.e. nodes are threaded either towards its in order
predecessor or successor.
2) Double threaded: - i.e. nodes are threaded towards both the in order
predecessor and successor.

21 What is the various representation of a binary tree?


Tree Representation Array representation
Linked list representation

22 List the application of tree.


(i) Electrical Circuit
ii) Folder structure
a. Binary tree is used in data processing.
b. File index schemes
c. Hierarchical database management system

23 Define binary tree and give the binary tree node structure.
lOMoARcPSD|31565132

24 What are the different ways of representing a Binary Tree?


• Linear Representation using Arrays.
• Linked Representation using Pointers.

25 Give the pre & postfix form of the expression (a + ((b*(c-e))/f).

26 Define a heap. How can it be used to represent a priorityqueue?


A priority queue is a different kind of queue, in which the next element to be removed
is defined by (possibly) some othercriterion. The most common way to implement a
priority queue is to use a different kind of binary tree, called a heap. A heap avoids the
long paths that can arise with binary search trees.

27 What is binary heap?


It is a complete binary tree of height h has between 2h and 2h+1 -1 node. The value of
the root node is higher than their child nodes

28 Define Strictly binary tree?


If every nonleaf node in a binary tree has nonempty left and right subtrees ,the tree
is termed
as a strictly binary tree.

29 Define complete binary tree?


A complete binary tree of depth d is the strictly binary tree all ofwhose are at level d.

30 What is an almost complete binary tree?


A binary tree of depth d is an almost complete binary tree if :
_ Each leaf in the tree is either at level d or at level d-1
_ For any node nd in the tree with a right descendant at level d,all the left
descendants of
nd that are leaves are at level d.
lOMoARcPSD|31565132

31 Define AVL Tree.


A AVL tree is a binary search tree except that for every node inthe tree,the height of
the
left and right subtrees can differ by atmost 1.

32 What is the length of the path in a tree?


The length of the path is the number of edges on the path. In a tree there is exactly one path
form the root to each node.

33 Define sibling?
Nodes with the same parent are called siblings. The nodes withcommon parents are called
siblings.
34 What are the two methods of binary tree implementation?
Two methods to implement a binary tree are, a. Linear representation.
b. Linked representation
35 List out few of the Application of tree data-structure?
Ø The manipulation of Arithmetic expressionØ Used for Searching
Operation
Ø Used to implement the file system of several popular operatingsystems
Ø Symbol Table constructionØ Syntax analysis

36 Define tree traversal and mention the type of traversals?


Visiting of each and every node in the tree exactly is called as tree traversal. Three types of tree
traversal 1. Inorder traversal 2. Preoder traversal 3. Postorder traversal.

37 What are the types of threaded binary tree?


i. Right-in threaded binary tree
ii. . Left-in threaded binary tree
iii. . Fully-in threaded binary tree
38 List out the steps involved in deleting a node from a binary searchtree.
▪ Deleting a node is a leaf node (ie) No children
▪ Deleting a node with one child.
▪ Deleting a node with two Childs

39 What is B Tree
A B-tree is a tree data structure that keeps data sorted and allows searches, insertions, and
deletions in logarithmic amortized time. Unlike self-balancing binary search trees, it is
optimized for systems that read and write large blocks of data. It is most commonly used in
database and file systems.
Important properties of a B-tree: • B-tree nodes have many more than two children. • A B-tree
node may contain more than just a single element.

40 What is binomial heaps?


A binomial heap is a collection of binomial trees that satisfies the following binomial-heap
properties: 1. No two binomial trees in the collection have the same size. 2. Each node in each
tree has a key. 3.
lOMoARcPSD|31565132

Each binomial tree in the collection is heap-ordered in the sense that


each non-root has a key strictly less than the key of its parent
41 Define complete binary tree.
If all its levels, possible except the last, have maximum number of
nodes and if all the nodes in the last level appear as far left as possible.
PART-B
1 Define Tree. Explain the tree traversals with algorithms and C311.3 BTL5
examples.

2 Construct an expression tree for the expression (a + b C311.3 BTL5


* c) +((d * e + 1) * g). Give the outputs when you apply
preorder, inorder and postorder traversals.

3 Explain binary search tree ADT in detail. C311.3 BTL5

4 Explain AVL tree ADT in detail. C311.3 BTL5

5 Explain b tree and B+ tree ADT in detail. C311.3 BTL5

6 Explain Heap tree ADT in detail. C311.3 BTL5

7 Explain threaded binary tree ADT in detail. C311.3 BTL2


lOMoARcPSD|31565132

UNIT IV

Topics Text / Reference book Page No.

Definition – Representation of Graph 229


Types of graph 300
Breadth-first traversal
1. Mark Allen Weiss, 335
“Data Structures and
Depth-first Algorithm Analysis in 342
traversal C”, 2nd Edition,
Topological Sort Pearson
Education,1997. 302
Bi-connectivity 33+8
Cut vertex 342
Euler circuits 342
Applications of graphs
348
lOMoARcPSD|31565132

S.N
o.
PART-A

1 Define Graph?
A graph G consist of a nonempty set V which is a set of nodes of the graph, a set
E which is the set of edges of the graph, and a mapping from the set for edge E to a set
of pairs of elements of V. It can also be represented as G= (V, E).

2 Explain the topological sort.


It is an Ordering of vertices in a directed acyclic graph such that if there is a path
from vi to vj, then vj appears after vi in the ordering.

3 Define NP
NP is the class of decision problems for which a given proposed solution for a
given input can be checked quickly to see if it is really a solution.

4 Define biconnected graph.


A connected undirected graph is biconnected if there areno vertices
whose removal disconnects the rest of the graph.

5 Define shortest path problem?


For a given graph G=(V, E), with weights assigned to the edges of G, we have to
find the shortest path (path length is defined as sum of theweights of the edges) from
any given source vertex to all the remaining vertices of G.

6 Mention any two decision problems which are NP-Complete.


NP is the class of decision problems for which a given proposedsolution for a given
input can be checked quickly to see if it is really a solution

7 Define adjacent nodes?


Any two nodes which are connected by an edge in a graph are called adjacent nodes. For E is
associated with a pair of nodes∈example, if and edge x (u,v) where u, v V, then we say that
the edge x connects the nodes u
and v. ∈
8 What is a directed graph?
A graph in which every edge is directed is called a directed graph.

9 What is a undirected graph?


A graph in which every edge is undirected is called a directed graph.
lOMoARcPSD|31565132

10 What is a loop?
An edge of a graph which connects to itself is called a loop or
sling.

11 What is a simple graph?


A simple graph is a graph, which has not more than one edge between a pair of nodes than such a
graph is called a simple graph.

12 What is a weighted graph?


A graph in which weights are assigned to every edge is called a weighted graph.

13 Define out degree of a graph?


In a directed graph, for any node v, the number of edges which have v as their initial node is
called the out degree of the node v.

14 Define indegree of a graph?


In a directed graph, for any node v, the number of edges which have v as their terminal node is called
the indegree of the node v.

15 Define path in a graph?


The path in a graph is the route taken to reach terminal node froma starting node.

16 What is a simple path?


A path in a diagram in which the edges are distinct is called a simple path.It is
also called as edge simple.

17 What is a cycle or a circuit?


A path which originates and ends in the same node is called acycle or circuit.

18 What is an acyclic graph?


A simple diagram which does not have any cycles is calledan acyclic graph.

19 What is meant by strongly connected in a graph?


An undirected graph is connected, if there is a path from every vertex to every
other vertex. A directed graph with this property is called strongly
connected.

20 When is a graph said to be weakly connected?


When a directed graph is not strongly connected but the underlying graph is
connected, then the graph is said to be weakly connected.

21 Name the different ways of representing a graph?


a. Adjacency matrix
b. Adjacency list
lOMoARcPSD|31565132

22 What is an undirected acyclic graph?


When every edge in an acyclic graph is undirected, it is called an undirected
acyclic graph. It is also called as undirected forest.

23 What are the two traversal strategies used in traversing a graph?


a. Breadth first search
b. Depth first search
24 What is a minimum spanning tree?
A minimum spanning tree of an undirected graph G is a tree formed from graph
edges that connects all the vertices of G at the lowest total cost.

25 Define topological sort?


A topological sort is an ordering of vertices in a directed acyclic graph, such that
if there is a path from vi to vj appears after vi in the ordering.

26 What is the use of Kruskal’s algorithm and who discovered it?


Kruskal’s algorithm is one of the greedy techniques to solve the minimum spanning tree
problem. It was discovered by Joseph Kruskal when he was a second-year graduate student.

27 What is the use of Dijksra’s algorithm?


Dijkstra’s algorithm is used to solve the single-source shortest- paths problem: for a
given vertex called the source in a weighted connected graph, find the shortest path to all its
other vertices. The single- source shortest-paths problem asks for a family of paths, each
leading from the source to a different vertex in the graph, though some paths may have edges
in common.

28 Prove that the maximum number of edges that a graph with n Vertices is n*(n-
1)/2.
Choose a vertex and draw edges from this vertex to the remaining n-1 vertices.
Then, from these n-1 vertices, choose a vertex and draw edges to the rest of the n-2
Vertices. Continue this process till it ends witha single Vertex. Hence, the total number of
edges added in graph is
(n-1)+(n-2)+(n-3)+…+1 =n*(n-1)/2.

29 Define minimum cost spanning tree?


A spanning tree of a connected graph G, is a tree consisting of edges and all the vertices
of G. In minimum spanning tree T, for a given graph G, the total weights of the edges of the
spanning tree must be minimum compared to all other spanning trees generated from G. -
Prim’s and Kruskal is the algorithm for finding Minimum Cost Spanning Tree.

30 Define Adjacency in graph.


Two node or vertices are adjacent if they are connected to each other through an
edge. In the following example, B is adjacent to A, C isadjacent to B, and so on.
lOMoARcPSD|31565132

31 Define Basic Operations of Graph.


Following are basic primary operations of a Graph
• Add Vertex − Adds a vertex to the graph.
• Add Edge − Adds an edge between the two vertices of the graph.
• Display Vertex − Displays a vertex of the graph.

32 What is Levels in graph?


Level of a node represents the generation of a node. If the root node is at level 0, then
its next child node is at level 1, its grandchild is atlevel 2, and so on.

33 What is visiting and traversing in graph.


• Visiting refers to checking the value of a node when control is onthe node.
• Traversing means passing through nodes in a specific order.

34 Write the definition of weighted graph?


A graph in which weights are assigned to every edge is called a weighted graph.
35 Define adjacency matrix?
Adjacency matrix is an n x n matrix A whose elements aij are given by aij = 1 if (vi, vj)
Exists =0 otherwise
36 Define adjacent nodes?
Any two nodes, which are connected by an edge in a graph, are called
adjacent nodes. For example, if an edge x E is associated with a pair of nodes(u,v) where u, v V,
then we say that the edge x connects the nodes u and v.
37 What is topological sort?
It is an ordering of the vertices in a directed acyclic graph, such that: If there is a path from u to v,
then v appears after u in the ordering.
38 Write BFS algorithm
1. Initialize the first node’s dist number and place in queue
2. Repeat until all nodes have been examined
3. Remove current node to be examined from queue
4. Find all unlabeled nodes adjacent to current node
5. If this is an unvisited node label it and add it to the queue
6. Finished.

39 What are the two traversal strategies used in traversing a graph?


a. Breadth first search
b. Depth first search
40
What is articulation point
Articulation Points (or Cut Vertices) in a Graph A vertex in an undirected connected graph is an
articulation point (or cut vertex) if removing it (and edgesthrough it) disconnects the graph.
Articulation points represent vulnerabilities in a connected network – single points whose failure
would split the network into 2
or more disconnected components. They are useful for designing reliable network
lOMoARcPSD|31565132

PART-B

1 Explain the various representation of graph with example in detail? C311.4 BTL5
2 Define topological sort? Explain with an example? C311.4 BTL5

3 Explain Dijkstra's algorithm with an example? C311.4 BTL5

4 Explain Prim's algorithm with an example? C311.4 BTL5

5 Explain Krushal's algorithm with an example? C311.4 BTL2

6 Write and explain the prim’s algorithm and depth C311.4 BTL5
firstsearch algorithm.

7 For the graph given below, construct Prims algorithm C311.4 BTL5
2
4 1 2 1 7
8 4 5
3 5 1 4 6
1 2
6 7
8 Explain the breadth first search algorithm C311.4 BTL5
9 Write the algorithm to compute lengths of shortest path C311.4 BTL5

10 Explain the depth first search algorithm. C311.4 BTL2


lOMoARcPSD|31565132

UNIT V

Topics Text / Reference book Page No.

Searching- Linear Search 235

Binary Search 1. Mark Allen Weiss, 236


“Data Structures and
Algorithm Analysis in
Sorting – Bubble sort 237
C”, 2nd Edition,
Pearson
Selection sort – Insertion sort Education,1997. 235

Shell sort – Radix sort 238

Hashing- Hash Functions 165

Separate Chaining 168

Open Addressing 173

Rehashing – Extendible Hashing 181


lOMoARcPSD|31565132

S.
No. PART-B

1 Define sorting
Sorting arranges the numerical and alphabetical data present in a list in a specific
order or sequence. There are a number of sorting techniques available. The algorithms
can be chosen based on the following factors
• Size of the data structure
• Algorithm efficiency
Programmer’s knowledge of the technique

2 Mention the types of sorting


• Internal sorting
• External sorting

3 What do you mean by internal and external sorting?


An internal sort is any data sorting process that takes place entirely within the
main memory of a computer. This is possible whenever the data to be sorted is small
enough to all be held in the main memory.
External sorting is a term for a class of sorting algorithms that can handle massive
amounts of data. External sorting is required when the data being sorted do not fit into the
main memory of a computing device (usually RAM) and instead they must reside in the
slower external memory (usually a hard drive).

4 How the insertion sort is done with the array?


It sorts a list of elements by inserting each successive element in thepreviously sorted
Sub list.
Consider an array to be sorted A[1],A[2],….A[n]
a. Pass 1: A[2] is compared with A[1] and placed them in sortedorder.
b. Pass 2: A[3] is compared with both A[1] and A[2] and inserted atan appropriate
place. This makes A[1], A[2],A[3] as a sorted sub array.
c. Pass n-1: A[n] is compared with each element in the sub array A [1], A [2]
…A [n-1] and inserted at an appropriateposition.

5 Define hashing.
Hash function takes an identifier and computes the address of that identifier in
the hash table using some function
lOMoARcPSD|31565132

6 What is the need for hashing?


Hashing is used to perform insertions, deletions and find in constantaverage time.

7 Define hash function?


Hash function takes an identifier and computes the address of thatidentifier in
the hash table using some function.

8 List out the different types of hashing functions?


The different types of hashing functions are,
a. The division method
b. The mind square method
c. The folding method
d. Multiplicative hashing
e. Digit analysis

9 What are the problems in hashing?


a. Collision
b. Overflow

10 What are the problems in hashing?


When two keys compute in to the same location or address in thehash table
through any of the hashing function then it is termed collision.

11 what is insertion sort? How many passes are required for the elements to be
sorted ?
one of the simplest sorting algorithms is the insertion sort. Insertion sort consist of N-1
passes . For pass P=1 through N-1 , insertion sortensures that the elements in positions
0 through P-1 are in sorted order .It makes use of the fact that elements in position 0
through P-1 are already known to be in sorted order .

12 Write the function in C for insertion sort ?


void insertionsort(elementtype A[ ] , int N)
{
int j, p; elementtype tmp;
for(p=1 ; p <N ;p++ )
{
tmp = a[ p] ;
for ( j=p ; j>0 && a [ j -1 ] >tmp ;j--)a [ j ]=a [j-1 ] ;
a [ j ] = tmp ;
}}
lOMoARcPSD|31565132

13 Who invented shellsort ? define it ? Shellsort was


invented by Donald Shell . It works by comparing element that are distant . The distance
between the comparisons decreases as the algorithm runs until the last phase in which
adjacentelements are compared . Hence it is referred as diminishing increment
sort.

14 write the function in c for shellsort?


Void Shellsort(Elementtype A[ ],int N)
{
int i , j , increment ;elementtype tmp ;
for(elementtype=N / 2;increment > 0;increment / = 2)For( i= increment ;
i <N ; i ++)
{
tmp=A[ ];
for( j=I; j>=increment; j - =increment)if(tmp< A[ ]=A[j –
increment];
A[ j ]=A[ j –
increment]; ElseBreak;
A[ j ]=tmp;
}}

15 Differentiate between merge sort and quick sort?Mergesort


quick sort
1. Divide and conquer strategy Divide and conquer strategy
2. Partition by position Partition by value

16 Mention some methods for choosing the pivot element in quicksort?


1. Choosing first element
2. Generate random number
3. Median of three

17 What are the three cases that arise during the left to right scan in quick sort?
1. I and j cross each other
2. I and j do not cross each other
3. I and j points the same position

18 What is the need of external sorting?


External sorting is required where the input is too large to fit into memory. So
external sorting Is necessary where the program is toolarge

19 What is sorting?
Sorting is the process of arranging the given items in a logical order. Sorting is an
example where the analysis can be precisely performed.
lOMoARcPSD|31565132

20 What is mergesort?
The mergesort algorithm is a classic divide conquer strategy. The problem is divided
into two arrays and merged into single array

21 Compare the various hashing techniques.


Technique Load Factor
Separate chaining - close to 1
Open Addressing - should not exceed 0.5
Rehashing - reasonable load factor

22 Define collision in hashing.


When two different keys or identifiers compute into the same location or address
in the hash table through any of the hashing functions, then it is termed Collision.

23 Define Double Hashing.


Double Hashing is a collision-resolution technique used in open addressing
category. In double hashing, we apply a second hash function to x and probe at a
distance of hash2 (x),
2hash2 (x) ............... , and so on.

24 What are applications of hashing?


The applications of hashing are,
• Compliers use hash table to keep track of declaredvariables on source
code.
• Hash table is useful for any graph theory problem, wherethe nodes have real
names instead of numbers.
• Hash tables are used in programs that play games.
• Online spelling checkers use hashing.

25 What does internal sorting mean?


Internal sorting is a process of sorting the data in the main memory

26 What are the various factors to be considered in deciding asorting


algorithm?
Factors to be considered in deciding a sorting algorithm are,
1. Programming time
2. Executing time for program
3. Memory or auxiliary space needed for theprograms
environment.

27 How does the bubble sort get its name?


The bubble sort derives its name from the fact thatthe smallest data
item bubbles up to the top of the sorted array.

28 What is the main idea behind the selection sort?


lOMoARcPSD|31565132

The main idea behind the selection sort is to find the smallest entryamong in
a(j),a(j+1),… ..................... a(n) and then interchange it with a(j).
This process is then repeated for each value of j.

29 Is the heap sort always better than the quick sort?


No, the heap sort does not perform better than the quick sort.
Only when array is nearly sorted to begin with the heap sort algorithm gains an
advantage. In such a case, the quick deteriorates to its worst performance of O (n2).

30 Name some of the external sorting methods.


Some of the external sorting methods are,
1. Polyphase sorting
2. Oscillation sorting
3. Merge sorting

31 Define radix sort


Radix Sort is a clever and intuitive little sorting algorithm. Radix sort is a on
comparative integer sorting algorithm that sorts data with integer keys by grouping keys
by the individual digits which share the same significant position and

32 Define searching
Searching refers to determining whether an element is present in a given list of
elements
or not. If the element is present, the search is considered as successful, otherwise it is
considered as an unsuccessful search. The choice of a searching technique is based on the
following factors
a. Order of elements in the list i.e., random or sorted
b. Size of the list

33 Mention the types of searching


The types are
• Linear search
• Binary search

34 What is meant by linear search?


Linear search or sequential search is a method for finding aparticular value in
a list
that consists of checking every one of its elements, one at a time andin sequence, until
the desired one is found.

35 What is binary search?


For binary search, the array should be arranged in ascending ordescending order.
In each step, the algorithm compares the search key value with themiddle element of
the
lOMoARcPSD|31565132

array. If the key match, then a matching element has been found andits index, or
Position, is returned.
Otherwise, if the search key is less than the middle element, then thealgorithm repeats its
action on the sub-array to the left of the middle element or, if thesearch key is
greater, on
the sub-array to the right.

36 What are the collision resolution methods?


The following are the collision resolution methods
• Separate chaining
• Open addressing
• Multiple hashing

37 Define separate chaining


It is an open hashing technique. A pointer field is added to each record location,
when an
overflow occurs; this pointer is set to point to overflow blocks making a linked list. In
this method, the table can never overflow, since the linked lists are only extended upon
the arrival of new keys.

38 What is open addressing?


Open addressing is also called closed hashing, which is analternative to
resolve the
Collisions with linked lists. In this hashing system, if a collisionoccurs, alternative
cells
are tired until an empty cell is found.
There are three strategies in open addressing:
• Linear probing
• Quadratic probing
• Double hashing

39 What is Rehashing?
If the table is close to full, the search time grows and maybecome equal to
the table size.
When the load factor exceeds a certain value (e.g. greater than 0.5) we do
Rehashing: Build a second table twice as large as the originaland rehash there all
the keys of the original table.
Rehashing is expensive operation, with running time O(N)However, once
done, the new hash table will have good performance.

40 What is Extendible Hashing?


Used when the amount of data is too large to fit in main memory and external storage is
used.
N records in total to store, M records in one disk block
lOMoARcPSD|31565132

The problem: in ordinary hashing several disk blocks may be examined to find
an element -a time consuming process.
Extendible hashing: no more than two blocks are examined.

41 List the different sorting algorithms.


• Bubble sort
• Selection sort
• Insertion sort
• Shell sort
• Quick sort
• Radix sort
• Heap sort
• Merge sort
42 Why bubble sort is called so?
The bubble sort gets its name because as array elements are sorted they
gradually “bubble” to their proper positions, like bubbles rising in a glass of soda.

43 State the logic of bubble sort algorithm.


The bubble sort repeatedly compares adjacent elements of an array. The first and second elements
are compared and swapped if out of order. Then the second and third elements are compared and
swapped if out of order.
This sorting process continues until the last two elements of the array are compared and swapped
if out of order.
44 What number is always sorted to the top of the list by each pass of the Bubble sort
algorithm?
Each pass through the list places the next largest value in its proper place. In essence, each item
“bubbles” up to the location where it belongs.
45 When does the Bubble Sort Algorithm stop?
The bubble sort stops when it examines the entire array and finds that no
"swaps" are needed. The bubble sort keeps track of the occurring swaps bythe use of a flag.

46 What is the output of selection sort after the 2nd iteration given thefollowing sequence?
16 3 46 9 28 14
Ans: 3 9 46 16 28 14
47 How does insertion sort algorithm work?
In every iteration an element is compared with all the elements before it. While comparing if it is
found that the element can be inserted at a suitable position, then space is created for it by shifting
the other elements one position up and inserts the desired element at the suitable position. This
procedure is repeated for all the elements in the list until we get the sorted elements.

48 What operation does the insertion sort use to move numbers from theunsorted section to
the sorted section of the list?
The Insertion Sort uses the swap operation since it is ordering numberswithin a single list.

49 How many key comparisons and assignments an insertion sort makes in its worst case?
The worst case performance in insertion sort occurs when the elements of the input array are in
descending order. In that case, the first pass requires one comparison, the second pass requires two
comparisons, third pass three
comparisons,….kth pass requires (k-1), and finally the last pass requires (n-
lOMoARcPSD|31565132

PART -B
1 Explain the sorting algorithms C311.5 BTL2

2 Explain the searching algorithms C311.5 BTL5


3 Explain hashing C311.5 BTL5
4 Explain open addressing C311.5 BTL5
5 Write a C program to sort the elements using bubble sort, C311.5 BTL5
insertion sort and radix sort.
6 Write a C program to perform searching operations using linear C311.5 BTL5
and binary search.

7 Explain in detail about separate chaining. C311.5 BTL2


8 Explain Rehashing in detail. C311.5 BTL5

9 Explain Extendible hashing in detail. C311.5 BTL5

You might also like