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

dsa 2nd internal

Uploaded by

avni
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)
3 views

dsa 2nd internal

Uploaded by

avni
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/ 5

1. What is heap tree?

A Heap is a complete binary tree data structure that satisfies the heap
property: for every node, the value of its children is greater than or equal
to its own value. Heaps are usually used to implement priority queues,
where the smallest (or largest) element is always at the root of the tree.

2. Binary search tree?


A Binary Search Tree (or BST) is a data structure used in computer science
for organizing and storing data in a sorted manner. Each node in a Binary
Search Tree has at most two children, a left child and a right child, with
the left child containing values less than the parent node and the right
child containing values greater than the parent node

3.algo of merge sort


Step 1: Create two pointers, one for each sorted half.
Step 2: Initialize an empty temporary array to hold the merged result.
Step 3: Compare the elements at the pointers of the two halves:
Copy the smaller element into the temporary array.
Move the pointer of the sublist with the smaller element forward.
Step 4: Repeat step 3 until one of the sublists is empty.
Step 5: Copy the remaining elements from the non-empty sublist to the temporary
array.
Step 6: Copy the elements back from the temporary array to the original list.

4.conversion of postfix from any infix

I Initialize:

 Create an empty stack for operators (op_stack).


 Create an empty list for the output (output).

II Iterate over the tokens of the infix expression:

 If the token is an operand (number or variable):


o Add it directly to the output.
 If the token is an operator (e.g., +, -, *, /):
o While there is an operator at the top of the op_stack with greater or equal
precedence, and the operator at the top of the stack is left-associative:
 Pop operators from the op_stack to the output.
o Push the current operator onto the op_stack.
 If the token is an open parenthesis (:
o Push it onto the op_stack.
 If the token is a closing parenthesis ):
o Pop from the op_stack to the output until an open parenthesis ( is
encountered.
o Discard the open parenthesis.

III After the loop:

 Pop all remaining operators from the op_stack to the output.

IV Output:

 The output list now contains the postfix expression.

5.What is linera Quee?


A Linear Queue is a type of data structure that follows the First In, First Out (FIFO)
principle, where the element added first is removed first. It can be visualized as a straight line
where elements enter from one end (the rear) and exit from the other end (the front).

6. What is linklist?
A Linked List is a dynamic data structure that consists of nodes, where each node
contains two parts:

1. Data: The value or information stored in the node.


2. Pointer (or Reference): A link to the next node in the sequence.

7.Algo of search Element (linear search)


 Input:

 An array/list arr of size n.


 The target value target to search for.

 Steps:

 Start from the first element of the array.


 Compare the current element with the target:
o If it matches, return the index of the current element (or "found").
o If it doesn’t match, move to the next element.
 Repeat until:
o The target is found, or
o The end of the list is reached.

 Output:

 Return the index of the target if found.


 Otherwise, return an indication that the target is not in the list (e.g., -1).

8.algo of convert infix to postfix


Algorithm: Infix to Postfix Conversion

1. Input: An infix expression (e.g., A + B * C)


2. Output: The equivalent postfix expression (e.g., A B C * +)

Steps:

1. Initialize:
o Create an empty stack for operators.
o Initialize an empty string for the postfix expression.
2. Read the Expression:
o Scan the infix expression from left to right.
3. Handle Each Token:
o If the token is an operand (e.g., A, B, 1, 2):
 Append it directly to the postfix expression.
o If the token is an opening parenthesis (():
 Push it onto the stack.
o If the token is a closing parenthesis ()):
 Pop from the stack and append to the postfix expression until an
opening parenthesis is encountered.
 Discard the opening parenthesis.
o If the token is an operator (e.g., +, -, *, /):
 While the stack is not empty and the top of the stack has higher or
equal precedence than the current operator:
 Pop from the stack and append to the postfix expression.
 Push the current operator onto the stack.
4. After Scanning:
o If there are any operators left in the stack, pop them and append to the postfix
expression.
5. Return:
o The resulting postfix expression.

9.construct binary tree


Construct a binary tree using:

 Preorder Traversal: A B D E C F
 Inorder Traversal: D B E A F C

Step-by-Step Solution:

Step 1: Identify the root

 The first element of the preorder traversal is the root.


o Root: A

Step 2: Split the inorder traversal

 Find the position of the root (A) in the inorder traversal:


o Inorder: D B E | A | F C
 Left subtree: D B E
 Right subtree: F C

Step 3: Recur for left and right subtrees

10.Algo of insert Quee


 Check if the queue is full:

 If rear == size - 1, output an "Overflow" message and stop.

 Otherwise:

 Increment the rear pointer: rear = rear + 1.


 Add the element at queue[rear].

 If this is the first element (queue was empty), set front = 0.

11.Algo of stack pop


 Check if the stack is empty:

 If top == -1, output "Underflow" and terminate.

 Remove the top element:

 Retrieve the value at stack[top] (to return it if needed).

 Update the top pointer:

 Decrement top: top = top - 1.


12.priority Quee?
A Priority Queue is a type of queue where each element has a priority associated with it. Elements
are dequeued in order of their priority, with higher priority elements being dequeued before lower
priority ones, regardless of their arrival order. If two elements have the same priority, they are
dequeued according to their arrival order (FIFO) — this is known as a stable priority queue.

13. algo of post order travel


 Start at the root node.
 Recursively traverse the left subtree (visit left child first).
 Recursively traverse the right subtree (visit right child next).
 Visit the current node (after visiting both subtrees).

14.Sparx Array
A sparse matrix is a two-dimensional array (matrix) where most of the elements are zero. It is often
represented in a more compact form to save memory and computational resources.

15.hashing?
Hashing is a technique used to uniquely identify a value or object from a collection of values. It
transforms data (such as a string, number, or object) into a fixed-size value, typically a hash code.
This transformation is done using a function called a hash function. Hashing is commonly used in
data structures like hash tables, sets, and caches to quickly access and store data.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy