0% found this document useful (0 votes)
4 views10 pages

Dsa Viva

The document provides a comprehensive overview of programming concepts in C, including structures, dynamic memory allocation, and file handling. It also covers data structures such as singly linked lists, doubly linked lists, stacks, and queues, along with their implementations and operations. Each section includes possible viva questions and answers to aid in understanding and revision.

Uploaded by

Anas Yusuf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views10 pages

Dsa Viva

The document provides a comprehensive overview of programming concepts in C, including structures, dynamic memory allocation, and file handling. It also covers data structures such as singly linked lists, doubly linked lists, stacks, and queues, along with their implementations and operations. Each section includes possible viva questions and answers to aid in understanding and revision.

Uploaded by

Anas Yusuf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Lab 1: Revision of Programming Concepts in C

Possible Viva Questions & Answers

1. What is a structure in C? How is it declared?

o A structure is a user-defined data type that groups related variables of different


types.

2. How does dynamic memory allocation work in C?

o It allocates memory at runtime using malloc(), calloc(), realloc(), and free().

3. What is the difference between fwrite() and fprintf()?

o fwrite() writes data in binary format, whereas fprintf() writes in text format.

4. What is the purpose of clearing input buffers?

o To avoid unwanted characters interfering with scanf(). Use:

5. How can you store and retrieve data from a binary file?

6. What are pointers, and why are they important in C?

o Pointers store memory addresses and enable dynamic memory allocation.

7. What is the difference between struct and union?


o struct stores all members separately, whereas union shares memory among
members.

8. How does malloc() differ from calloc()?

o malloc() allocates uninitialized memory, whereas calloc() allocates zero-initialized


memory.

9. What is the typedef keyword used for?

o It assigns a new name to an existing type.

10. What is the size of a structure? How many pointers does it have?

o The size depends on its data members and memory alignment. A structure may
have multiple pointer members depending on its definition.

Lab 2: Singly Linked List Implementation

Possible Viva Questions & Answers

1. What is a singly linked list?

o A dynamic data structure where each node points to the next node.

2. How many pointers does a singly linked list node have?

o It has one pointer, which points to the next node.

3. How does insertion at the beginning of a singly linked list work?

4. How to delete a node by value?

5. How to traverse a linked list?


6. What is the time complexity of inserting a node in a linked list?

o O(1) at the beginning, O(n) at the end.

7. What happens if we delete the head node?

o The second node becomes the new head.

8. What is the difference between malloc() and free() in a linked list?

o malloc() allocates memory for a node, free() deallocates it.

9. How does searching for a node in a linked list work?

10.What is the advantage of linked lists over arrays?

• Dynamic size, efficient insertion/deletion.

Lab 3: Advanced Singly Linked List

Possible Viva Questions & Answers

1. How do you reverse a linked list?


2. How many pointers does a linked list reversal algorithm use?

o Typically three: prev, current, and next.

3. How to detect a loop in a linked list?

o Use Floyd’s Cycle Detection Algorithm (slow and fast pointers).

4. How to merge two sorted linked lists?

5. What is a circular linked list?

o The last node points back to the first node.

Lab 4: Doubly Circular Linked List

Possible Viva Questions & Answers

1. What is a doubly linked list?

o Each node contains pointers to both the previous and next nodes.

2. How many pointers does a doubly linked list node have?

o It has two: prev and next.

3. How do you insert a node in a doubly linked list?


4. How do you delete the last node?

Lab 5: Stack Implementation

Possible Viva Questions & Answers

1. What is a stack?

o A LIFO data structure.

2. How many pointers does a stack have?

o One (top).

3. How to implement a stack using an array?

Lab 6: Queue Implementation

Possible Viva Questions & Answers

1. What is a queue?

o A FIFO data structure.

2. How many pointers does a queue have?

o Two (front and rear).

3. How to implement a queue using an array?


Short Theoretical Questions with Answers for Each Lab

Lab 1: Revision of Programming Concepts in C

1. What is the purpose of using struct in C?

o It is used to group related variables of different data types into a single unit.

2. How does sizeof() work with structures?

o It returns the total memory size occupied by a structure, including any padding
added by the compiler.

3. What is the difference between malloc() and calloc()?

o malloc() allocates uninitialized memory, while calloc() allocates zero-initialized


memory.

4. How do you access structure members using a pointer?

o Use the -> operator (e.g., ptr->name).

5. What is the use of typedef in C?

o It is used to create an alias for existing data types.

6. What happens if free() is not used after malloc()?

o Memory leak occurs, leading to inefficient memory usage.

7. What is the purpose of fopen() and fclose()?

o fopen() opens a file, and fclose() closes an open file to free resources.

8. Why is fprintf() used instead of printf() for file operations?

o fprintf() writes formatted output to a file instead of the console.

9. What is the difference between binary and text file handling in C?

o Binary files store data in raw form, whereas text files store human-readable data.
10. How do you check if a file opened successfully in C?

o Check if fopen() returns NULL.

Lab 2: Singly Linked List Implementation

1. What is a singly linked list?

o A dynamic data structure where each node contains data and a pointer to the
next node.

2. What are the advantages of linked lists over arrays?

o Dynamic size, efficient insertions and deletions, no memory wastage.

3. How many pointers does a node in a singly linked list have?

o One, which points to the next node.

4. What is the role of head in a linked list?

o It stores the address of the first node of the list.

5. How is dynamic memory allocated for a linked list node?

o Using malloc() to allocate memory at runtime.

6. What is the worst-case time complexity of searching in a singly linked list?

o O(n), as we have to traverse the entire list.

7. Why is it necessary to check if head == NULL before deleting a node?

o To avoid accessing memory that does not exist.

8. What happens if we try to delete a node from an empty linked list?

o The operation fails as there are no nodes to delete.

9. How do we check if a linked list is empty?

o If head == NULL, the list is empty.

10. How do you handle memory leaks in a linked list?

o By freeing each node before deleting or exiting the program.


Lab 3: Advanced Singly Linked List

1. How do you reverse a singly linked list?

o By iterating through the list and adjusting pointers in reverse order.

2. What is a circular linked list?

o A linked list where the last node points back to the first node instead of NULL.

3. How does Floyd’s Cycle Detection Algorithm work?

o It uses two pointers, slow and fast, to detect a cycle in a linked list.

4. What is the difference between iterative and recursive reversal of a linked list?

o Iterative reversal modifies pointers in a loop, while recursive reversal modifies


pointers using function calls.

5. How does merging two sorted linked lists work?

o Compare node values one by one and merge them in sorted order.

6. What are dummy nodes in linked lists, and why are they used?

o Dummy nodes simplify linked list operations by acting as placeholders.

7. What is the purpose of the tail pointer in a linked list?

o It points to the last node, making insertions at the end efficient.

8. How can a linked list be sorted?

o Using merge sort or bubble sort.

9. What happens if you try to delete a node that doesn’t exist?

o The operation fails as there is nothing to delete.

10. How is a linked list stored in memory compared to an array?

o It uses non-contiguous memory locations, unlike arrays which use contiguous


memory.

Lab 4: Doubly Circular Linked List

1. What is a doubly linked list?


o A linked list where each node has two pointers: one to the next node and one to
the previous node.

2. How many pointers does a doubly linked list node have?

o Two (prev and next).

3. How is a circular linked list different from a singly linked list?

o A circular linked list’s last node points to the first node instead of NULL.

4. What are the advantages of a doubly linked list over a singly linked list?

o Can be traversed in both directions, easier deletion.

5. How does deletion work in a circular linked list?

o The previous and next pointers are adjusted accordingly.

6. How do you traverse a doubly linked list in both directions?

o By using the next pointer to go forward and prev pointer to go backward.

Lab 5: Stack Implementation

1. What is a stack?

o A LIFO (Last In, First Out) data structure.

2. What is the difference between a stack and a queue?

o Stack follows LIFO, queue follows FIFO.

3. What are the basic operations of a stack?

o Push (insert), Pop (remove), Peek (view top element).

4. What is the purpose of the top pointer in a stack?

o It keeps track of the topmost element.

5. What happens when a stack overflows?

o It means the stack is full and cannot accept more elements.

6. How does a stack help in function calls?

o It stores return addresses and local variables.


Lab 6: Queue Implementation

1. What is a queue?

o A FIFO (First In, First Out) data structure.

2. What are the types of queues?

o Simple queue, circular queue, priority queue, deque.

3. What is the difference between a circular queue and a normal queue?

o A circular queue reuses empty spaces left by dequeued elements.

4. How does a priority queue differ from a simple queue?

o Elements in a priority queue are dequeued based on priority instead of order.

5. How are queues used in operating system process scheduling?

o They manage processes in scheduling algorithms like FCFS and Round Robin.

You might also like