Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
31 views7 pages

DSA Lab File VIVA 1-7 Exp

Uploaded by

anshulparmar353
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)
31 views7 pages

DSA Lab File VIVA 1-7 Exp

Uploaded by

anshulparmar353
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/ 7

VIVA QUESTION

1.How do you declare an array in C?

Ans. An array in C is declared by specifying the data type, array name, and size inside square
brackets.
Example: int arr[10]; creates an integer array of size 10.
Arrays store elements of the same data type in contiguous memory locations.

2. What are the advantages of using arrays?

Ans. Advantages of Using Arrays:

 Efficient Storage: Arrays store multiple elements of the same data type in contiguous memory
locations.
 Fast Access: Elements can be accessed quickly using index values (random access).
 Code Simplicity: Using arrays reduces the need for multiple variables for similar data.
 Easy Manipulation: Arrays make it easier to perform operations like sorting, searching, and
traversal.
VIVA QUESTION

1.Difference between one-dimensional and multi-dimensional array?

Ans.

One-Dimensional Array Multi-Dimensional Array


Case

Definition An array with a single row or An array with more than one
linear elements. row (e.g., 2D, 3D).

Syntax int arr[5]; int arr[3][4];

Indexing Uses one index: arr[i] Uses multiple indices: arr[i][j],


arr[i][j][k], etc.

Representation Like a simple list or line of Like a matrix or table format


values

Usage Example Storing marks of 5 students Storing marks of students in


different subjects

2. How do you access an element in a 2D array?

Ans. In C, a 2D array stores data in a tabular form using rows and columns.
To access an element, we use two indices — the first for the row and the second for the column.
Syntax: array[row][column]
Example:

int arr[2][3] = { {1, 2, 3}, {4, 5, 6} };

printf("%d", arr[1][2]);

Output: 6

Here, arr[1][2] refers to the element in the 2nd row and 3rd column, which is 6.
VIVA QUESTION

1.What is logical representation of linked list?

Ans. A linked list is logically represented as a chain of nodes connected through pointers.
Each node contains data and a pointer to the next node (and previous in doubly list).
It allows dynamic memory allocation and flexible size changes.

2. Types of linked list?

Ans. Linked lists are linear data structures made of nodes where each node contains data and a
pointer (or link) to the next node. Based on structure and connection, there are three main types:

1. Singly Linked List

 Each node has two parts: data and a pointer to the next node.
 Traversal is possible only in one direction (forward).
 The last node’s next pointer is set to NULL.
 Example: 10 → 20 → 30 → NULL

2. Doubly Linked List

 Each node contains three parts: a pointer to the previous node, data, and a pointer to the
next node.
 Allows traversal in both forward and backward directions.
 More flexible but requires extra memory for the additional pointer.
 Example: NULL ← 10 ⇄ 20 ⇄ 30 → NULL

3. Circular Linked List

 The last node points back to the first node instead of NULL.
 Can be singly or doubly linked.
 Enables continuous traversal from any node.
 Example (Singly): 10 → 20 → 30 → 10 (back to head)
VIVA QUESTION

1. How to represent doubly linked list?

Ans. A doubly linked list is a type of linked list where each node contains three parts:

 Pointer to the previous node (prev).


 The data field (data).
 A pointer to the next node (next).

struct Node {

struct Node* prev; // Pointer to previous node

int data; // Data part

struct Node* next; // Pointer to next node

};

Example of linked nodes:


NULL ← [10] ⇄ [20] ⇄ [30] → NULL

2. Advantages of doubly linked list?

Ans. Advantages of Doubly Linked List:

 Allows traversal in both forward and backward directions.


 Easier and faster deletion of nodes since the previous node is directly accessible.
 Simplifies insertion and deletion operations at both ends and in the middle of the list.
 Provides greater flexibility compared to singly linked lists.
 Helps in implementing complex data structures like deques and navigation systems.
VIVA QUESTION

1. Explain recursion. Types of recursion?

Ans. Recursion:
A function calls itself to solve smaller parts of a problem until it reaches a base case. It simplifies
complex problems by breaking them down.

Types of Recursion:

1. Direct Recursion: Function calls itself directly.


2. Indirect Recursion: Function A calls B, and B calls A.
3. Tail Recursion: Recursive call is the last operation in the function.
4. Non-tail Recursion: Recursive call is followed by other operations.
5. Nested Recursion: Recursive calls inside other recursive calls.

2. How recursion is useful in programming?

Ans. Uses and importance of recursion in programming :

 Break complex problems into smaller, manageable parts.


 Useful in tree and graph traversals.
 Helps implement divide and conquer algorithms like quicksort and mergesort.
 Simplifies code by reducing loops and conditional statements.
 Ideal for solving mathematical problems like factorial and Fibonacci series.
VIVA QUESTION

1. Why Are Stacks Useful?

Ans. Uses and Importance of Stack:

 Follow Last-In-First-Out (LIFO) for managing data access.


 Manage function calls and recursion efficiently.
 Used in expression evaluation and syntax parsing.
 Help in implementing undo/redo features.
 Keep track of nested operations like balanced parentheses.
 Simplify memory management during program execution.

2. Why do we need Prefix and Postfix notations?

Ans. Importance of Prefix and Postfix Notations in Expression Evaluation:

 In arithmetic expressions (like infix), parentheses are required to define the order of operations.
 Prefix (operator before operands) and Postfix (operator after operands) eliminate the need for
parentheses.
 These notations make it easier for computers to evaluate expressions, especially using stacks.
 They provide a consistent and unambiguous way to represent expressions.
 Useful in compilers, interpreters, and calculators for expression evaluation and syntax parsing.
VIVA QUESTION

1. What are the types of Stack?

Ans. In data structures, a stack is a linear data structure that follows the Last-In-First-Out (LIFO)
principle. There are different types of stacks based on their implementation and use cases:

Types of Stack

a. Simple Stack (Linear Stack):


A simple stack is a linear data structure that follows the Last-In-First-Out (LIFO) order.
It allows insertion (push) and deletion (pop) only from one end, called the top.

b. Static Stack:
A static stack is implemented using arrays with a fixed size.
It has limited capacity and memory is allocated at compile time.

c. Dynamic Stack:
A dynamic stack is implemented using linked lists and can grow or shrink at runtime.
It is more flexible but uses extra memory for pointers.

d. Double-Ended Stack (Deque):


This stack allows insertion and deletion from both ends (front and rear).
It can work as both a stack and a queue depending on the operation.

e. Multiple Stacks:
Multiple stacks are implemented within a single array to save space.
They are useful when more than one stack is needed in limited memory.

2. Which principle is used in stack?

Ans. A stack follows the Last-In, First-Out (LIFO) principle, where the last element added is the first
to be removed. It works like a pile of plates, removing the top one first. This is useful for managing
function calls, expression evaluation, and undo operations.

You might also like