0% found this document useful (0 votes)
34 views6 pages

Solutions For Repeated Questions

Uploaded by

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

Solutions For Repeated Questions

Uploaded by

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

For Your Reference - https://chatgpt.

com/share/6735d8a9-0298-800e-9a84-36f951caac21

Definitions and Basic Concepts

1. What is pointer to pointer? (2 Marks)

o A pointer to pointer is a variable that holds the address of another pointer variable.

o It allows for multi-level indirection, meaning you can use it to access another
pointer’s memory location.

o Declaration: int **ptr; where ptr holds the address of another pointer to an integer.

o Use Case: Commonly used in dynamic memory allocation and when working with
multi-dimensional arrays.

2. What is data structure? (2 Marks)

o A data structure is a specific way to organize and store data in a computer.

o It allows efficient access and modification of data.

o Common types include linear structures (like arrays and linked lists) and non-linear
structures (like trees and graphs).

o Used in a variety of applications, from database management to algorithm design.

3. What is sorting? State the techniques of sorting. (2 Marks)

o Sorting arranges elements in a specific order, typically ascending or descending.

o It improves search efficiency by organizing data.

o Common techniques include:

 Bubble Sort: Compares adjacent elements repeatedly.

 Selection Sort: Finds the smallest element and places it at the beginning.

 Insertion Sort: Builds a sorted list by inserting elements in the correct order.

 Quick Sort and Merge Sort: Divide and conquer algorithms for faster sorting.

4. What is non-primitive data structure? (2 Marks)

o Non-primitive data structures store multiple values and can hold complex
relationships.

o Examples include arrays, stacks, queues, linked lists, and trees.

o These structures depend on primitive data types but allow greater flexibility and
utility.

o They are essential in handling large data collections efficiently in software.

5. What is searching? (2 Marks)

o Searching is the process of finding a specific element within a data structure.


o Types:

 Linear Search: Checks each element in sequence, best for unsorted data.

 Binary Search: Efficient search for sorted data by dividing the search space.

o Applications: Used in databases, search engines, and array operations.

o Crucial for retrieving data efficiently in large datasets.

6. What is polynomial? How is it represented/different from structure? (4 Marks)

o A polynomial is a mathematical expression with variables and coefficients, e.g., 3x^2


+ 2x + 1.

o Representation:

 Arrays: Each index represents the power, and the value at the index is the
coefficient.

 Linked Lists: Each node contains a coefficient and an exponent.

o Difference from Structure:

 A polynomial specifically represents mathematical terms, whereas a


structure is a data type that can store different types of data.

 Structures group unrelated fields, whereas polynomials focus on a


mathematical relationship.

Specific Data Structures

1. Applications of stack (2 Marks)

o Function Call Management: Used to keep track of active functions, especially for
recursion.

o Expression Evaluation: Crucial in evaluating postfix, infix, and prefix expressions.

o Undo Operations: Supports undo/redo in text editors and other applications.

o Syntax Parsing: Used in compilers to ensure balanced parentheses and braces.

2. What is stack? Explain different operations used in stack. (4 Marks)

o A stack is a linear data structure that follows the Last In, First Out (LIFO) principle.

o Operations:

 Push: Adds an element to the top of the stack.

 Pop: Removes the top element from the stack.

 Peek/Top: Accesses the top element without removing it.

 isEmpty: Checks if the stack contains any elements.

o Use Cases: Used in backtracking, function call tracking, and expression parsing.
3. What is balance factor? How is it calculated? (2 Marks)

o Balance Factor is used in AVL trees to maintain balance.

o Definition: It’s the difference between the heights of the left and right subtrees.

o Calculation formula: Balance Factor = Height of Left Subtree - Height of Right


Subtree.

o A tree is balanced if the balance factor is -1, 0, or +1 for each node.

4. Differentiate array and structure. (4 Marks)

o Array:

 Stores elements of the same data type.

 Accessed by indices.

 Useful for sequential data.

o Structure:

 Stores elements of different data types.

 Accessed using dot notation with field names.

 Useful for representing complex objects with related attributes.

Tree and Graph Structures

1. Construct Binary Search Tree (BST) (4 Marks)

o Binary Search Tree: A tree where each node has up to two children, with the left
child having a smaller value and the right child having a larger value.

o Insertion Steps:

 Start with the root node.

 Compare each value; insert smaller values in the left subtree, larger values in
the right.

 Follow this rule recursively for each new value.

o Example: Constructing a BST for the data 15, 30, 20, 5, 10, 2, 7 involves starting with
15 as the root and organizing subsequent values in this manner.

2. Convert an infix expression to postfix/prefix (3 Marks)

o Conversion Process:

 Use a stack to hold operators.

 Read each token (operand/operator) left to right.

 Apply precedence and associativity rules to decide when to push or pop


operators.
o Example:

 Infix: (A + B) * C

 Postfix: A B + C *

 Prefix: * + A B C

Algorithms and Sorting

1. Explain insertion sort technique with an example. (4 Marks)

o Insertion Sort:

 Begins with the second element and inserts it into the correct position in the
sorted section.

 Continues this process for each element until the list is sorted.

o Example:

 Given array: [18, 7, 22, 3, 14, 2]

 Steps:

 Insert 7 before 18, then 22 in the correct position, and so on until all
elements are sorted.

2. Selection Sort (and other sorting algorithms) (4 Marks)

o Selection Sort:

 Repeatedly finds the minimum element in the unsorted section and places it
at the beginning.

o Example:

 For [10, 5, 75, 62, 49, 58]:

 Start by finding the smallest element (5) and swapping it with the
first element (10).

 Repeat this for each unsorted section until the list is sorted.

Linked List Operations

1. Write a function to create and display singly or doubly linked list. (4 Marks)

o Function to Create:

 Initialize head to NULL.

 For each element, create a new node, link it to the previous node, and
update the head.

o Function to Display:
 Traverse from head, printing each node’s data until reaching the end.

o Example Code:

void displayList(Node* head) {

Node* current = head;

while (current != NULL) {

printf("%d ", current->data);

current = current->next;

2. Write a function to delete the first node in a singly linked list. (4 Marks)

o Steps:

 Set a temporary pointer to the current head.

 Move head to the next node.

 Free the memory of the initial node.

o Example Code:

void deleteFirstNode(Node** head) {

if (*head == NULL) return;

Node* temp = *head;

*head = (*head)->next;

free(temp);

Definitions Related to Graphs and Trees

1. Define terms like Directed Graph, Parent Node, Subtree, Degree of Vertex, Leaf Node, etc.
(6 Marks)

o Directed Graph: A graph where edges have a specific direction.

o Parent Node: A node in a tree that has at least one child node connected below it.

o Subtree: A smaller section of a tree, including a node and its descendants.

o Degree of Vertex: The number of edges connected to a vertex in a graph.

o Leaf Node: A node in a tree with no children, often the endpoint in paths.

You might also like