Solutions For Repeated Questions
Solutions For Repeated Questions
com/share/6735d8a9-0298-800e-9a84-36f951caac21
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.
o Common types include linear structures (like arrays and linked lists) and non-linear
structures (like trees and graphs).
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.
o Non-primitive data structures store multiple values and can hold complex
relationships.
o These structures depend on primitive data types but allow greater flexibility and
utility.
Linear Search: Checks each element in sequence, best for unsorted data.
Binary Search: Efficient search for sorted data by dividing the search space.
o Representation:
Arrays: Each index represents the power, and the value at the index is the
coefficient.
o Function Call Management: Used to keep track of active functions, especially for
recursion.
o A stack is a linear data structure that follows the Last In, First Out (LIFO) principle.
o Operations:
o Use Cases: Used in backtracking, function call tracking, and expression parsing.
3. What is balance factor? How is it calculated? (2 Marks)
o Definition: It’s the difference between the heights of the left and right subtrees.
o Array:
Accessed by indices.
o Structure:
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:
Compare each value; insert smaller values in the left subtree, larger values in
the right.
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.
o Conversion Process:
Infix: (A + B) * C
Postfix: A B + C *
Prefix: * + A B C
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:
Steps:
Insert 7 before 18, then 22 in the correct position, and so on until all
elements are sorted.
o Selection Sort:
Repeatedly finds the minimum element in the unsorted section and places it
at the beginning.
o Example:
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.
1. Write a function to create and display singly or doubly linked list. (4 Marks)
o Function to Create:
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:
current = current->next;
2. Write a function to delete the first node in a singly linked list. (4 Marks)
o Steps:
o Example Code:
*head = (*head)->next;
free(temp);
1. Define terms like Directed Graph, Parent Node, Subtree, Degree of Vertex, Leaf Node, etc.
(6 Marks)
o Parent Node: A node in a tree that has at least one child node connected below it.
o Leaf Node: A node in a tree with no children, often the endpoint in paths.