Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

1.Define data structure. List out any two operations of data structure.

The organized collection of data is known as data structure


In other words, the possible way in which the data values such as integers, floats, chars are logically
Related among themselves are defined by data structures.
EX: Inserting, deleting, shorting, merging

2. White ADT of an array.


An array is a fixed-size sequence of elements of the same type. An array is a fundamental Abstract Data
Type (ADT).The basic operations include direct access to each element in the array by specifying its
position so that values can be retrieved from or stored in that position.

3. What is queue? And mention its types.

A queue is an important data structure which is extensively used in computer applications. In this
chapter we will study the operations that can be performed on a queue. The chapter will also discuss
the implementation of a queue by using both arrays as well as linked lists.
Simple Queue or Linear Queue
Circular Queue
Priority Queue
Double Ended Queue (or Deque)

4. Mention the different ways of tree traversal.

the tree traversal in the data structure. The term 'tree traversal' means traversing or visiting each node of a
tree.
Preorder traversal
Inorder traversal
Postorder traversal

5. What is B Tree ? Mention its operation.

A B-tree is a sort of self-balancing search tree whereby each node could have more than two children and
hold multiple keys. It's a broader version of the binary search tree. It is also usually called a height-
balanced m-way tree.
Deletion
Inserting
Searching and sorting
Traversal
Finding maximum value in BST
Finding minimum value in BST

6. Define any two collision resolution in Hashing.


The collisions occur when the hash function maps two different keys to the same location. Obviously,
two records cannot be stored in the same location.
Open addressing: Once a collision takes place, open addressing or closed hashing computes new positions
using a problem seauence and the next record is stored in that position.
2. Chaining: the hash table has a technique known as separate chaining. Separate chaining is defined as a
method by which linked lists of values are built in association with each location within the hash table
when a collision occurs.

7. Define hashing
Hashing is a technique or process of mapping keys, and values into the hash table by using a hash
function. It is done for faster access to elements. The efficiency of mapping depends on the efficiency of
the hash function used.

Part c
explain Asymptotic Notation with example

Following are the commonly used asymptotic notations to calculate the running time
complexity of an algorithm.
Ο Notation
Ω Notation
θ Notation
1. Big Oh Notation, Ο
The notation Ο(n) is the formal way to express the upper bound of an algorithm's running
time. It measures the worst case time complexity or the longest amount of time an algorithm
can possibly take to complete.

For example, for a function f(n)


Ο(f(n)) = { g(n) : there exists c > 0 and n0 such that f(n) ≤ c.g(n) for all n > n0. }

2. Omega Notation, Ω
The notation Ω(n) is the formal way to express the lower bound of an algorithm's running
time. It measures the best case time complexity or the best amount of time an algorithm can
possibly take to complete.

For example, for a function f(n)


Ω(f(n)) ≥ { g(n) : there exists c > 0 and n0 such that g(n) ≤ c.f(n) for all n > n0. }

3. Theta Notation, θ
The notation θ(n) is the formal way to express both the lower bound and the upper bound of
an algorithm's running time. It is represented as follows
θ(f(n)) = { g(n) if and only if g(n) = Ο(f(n)) and g(n) = Ω(f(n)) for all n > n0. }

2 .What is algorithm ? Explain time and space complexity of algorithm.

Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a


certain order to get the desired output. Algorithms are generally created independent of
underlying languages, i.e. an algorithm can be implemented in more than one programming
language.

Time complexity of an algorithm refers to the amount of time an algorithm takes to run as a function of
the size of the input data. It is expressed in terms of the number of basic operations performed by the
algorithm.
Space complexity of an algorithm refers to the amount of memory or storage space required to solve a
problem. It is expressed in terms of the size of the input data.

Explain AVL tree with its operation.


In this section, we will discuss various operations which are performed on the AVL trees. These are
Searching a node in an AVL Tree
Inserting a new node in an AVL Tree
Deleting a node from an AVL Tree
Searching a node in an AVL Tree:
The process of searching a node in an AVL tree is the same as for a binary search tree. Due to the
height-balancing of the tree, the search operation takes o(log n) time to complete. Since the operation
does not modify the structure of the tree, no special provisions are required.
Inserting a new node in an AVL Tree:
Insertion in an AVL tree is same as in binary search tree. Le, firstly, we will search for the position
where the new node is to be inserted and then insert the node. But AVL. tree has a property that the
height of left and right sub tree will be with maximum difference of 1

3. explain quick sort algorithm

The quick sort algorithm attempts to separate the list of elements into two parts and then sort each part
recursively. That means it use divide and conquer strategy. In quick sort, the partition of the list is
performed based on the element called pivot. Here pivot element is one of the elements in the list.
The list is divided into two partitions such that "all elements to the left of pivot are smaller than the pivot
and all elements to the right of pivot are greater than or equal to the pivot".

Step by Step Process


In Quick sort algorithm, partitioning of the list is performed using following steps...

Step 1 - Consider the first element of the list as pivot (i.e., Element at first position in the list).
Step 2 - Define two variables i and j. Set i and j to first and last elements of the list respectively.
Step 3 - Increment i until list[i] > pivot then stop.
Step 4 - Decrement j until list[j] < pivot then stop.
Step 5 - If i < j then exchange list[i] and list[j].
Step 6 - Repeat steps 3,4 & 5 until i > j.
Step 7 - Exchange the pivot element with list[j] element.

4.Write C program for Linear search.


#include <stdio.h>
int main()
{
int array[100], search, c, n;

printf("Enter number of elements in array\n");


scanf("%d", &n);

printf("Enter %d integer(s)\n", n);

for (c = 0; c < n; c++)


scanf("%d", &array[c]);

printf("Enter a number to search\n");


scanf("%d", &search);
for (c = 0; c < n; c++)
{
if (array[c] == search) /* If required element is found */
{
printf("%d is present at location %d.\n", search, c+1);
break;
}
}
if (c == n)
printf("%d isn't present in the array.\n", search);

return 0;
}

5. what is Binary search tree?


Binary Search Tree is a node-based binary tree data structure which has the following properties:

The left subtree of a node contains only nodes with keys lesser than the node’s key.
The right subtree of a node contains only nodes with keys greater than the node’s key.
The left and right subtree each must also be a binary search tree.
6. construct a bst for the given list

refer from question 5

You might also like