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

ds key

Uploaded by

Nalini Bangaram
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)
31 views9 pages

ds key

Uploaded by

Nalini Bangaram
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/ 9

1.Define space and time complexity.

Time complexity refers to the amount of time required by an algorithm to run as a


function of the input size. Space complexity refers to the amount of memory required by
an algorithm to run as a function of the input size.

2. Define abstract data type .Give one example.


An Abstract Data Type in data structures is a data type whose behavior is defined with
the help of some attributes and some functions. Generally, we write these attributes and
functions inside a class or a structure to use an object of the class to use that particular
abstract data type.

Stack

queue

3.state disadvantages of linked list over arrays.


1. Random Access: Linked lists do not provide random access to elements like
arrays do. To access an element in a linked list, we have to start at the
beginning of the list and traverse the list until we find the desired element. This
makes accessing individual elements in a linked list slower than in an array.
2. Extra Memory Usage: Linked lists require extra memory compared to arrays.
Each element in a linked list requires a reference to the next element, which
takes up additional memory space. In contrast, arrays only need memory to
store the elements themselves.
3. More Complex Implementation: Implementing a linked list is more complex
than implementing an array because it requires managing pointers and dynamically
allocating memory. This complexity can lead to more bugs and errors in the code.

4.define circular double linked list.


A circular doubly linked list is a data structure that consists of a collection of nodes, where
each node contains a data element and two pointers: one that points to the next node in the
list and another that points to the previous node in the list

5.State the effect of stack overflow programs functionality?


When a stack overflow occurs, the excess data can corrupt other variables and
address data, effectively changing variable values and overwriting return
addresses. In some cases, this will cause the program to crash.
.6.mention rules for postfix expression evalution using stack data
structure.
 Create a stack to store operands (or values).
 Scan the given expression from left to right and do the following for every scanned
element.
o If the element is a number, push it into the stack.
o If the element is an operator, pop operands for the operator from the
stack. Evaluate the operator and push the result back to the stack.
 When the expression is ended, the number in the stack is the final answer.

7 Define circular queue?


A Circular Queue is an extended version of a queue where the last element of the
queue is connected to the first element of the queue forming a circle.
The operations are performed based on FIFO (First In First Out) principle. It is also
called ‘Ring Buffer’.

8.List 3 applications of queue.


1. Task Scheduling: Queues can be used to schedule tasks based on priority or the
order in which they were received.
2. Resource Allocation: Queues can be used to manage and allocate resources,
such as printers or CPU processing time.
3. Batch Processing: Queues can be used to handle batch processing jobs, such
as data analysis or image rendering.
4. Message Buffering: Queues can be used to buffer messages in communication
systems, such as message queues in messaging systems or buffers in computer
networks.
5. Event Handling: Queues can be used to handle events in event-driven systems,
such as GUI applications or simulation systems.
6. Traffic Management: Queues can be used to manage traffic flow in transportation
systems, such as airport control systems or road networks.
7. Operating systems: Operating systems often use queues to manage processes
and resources. For example, a process scheduler might use a queue to manage
the order in which processes are executed.
8. Network protocols: Network protocols like TCP and UDP use queues to manage
packets that are transmitted over the network. Queues can help to ensure that
packets are delivered in the correct order and at the appropriate rate.
9. Printer queues :In printing systems, queues are used to manage the order in
which print jobs are processed. Jobs are added to the queue as they are
submitted, and the printer processes them in the order they were received.
10.Web servers: Web servers use queues to manage incoming requests from clients.
Requests are added to the queue as they are received, and they are processed by
the server in the order they were received.
11.Breadth-first search algorithm: The breadth-first search algorithm uses a queue
to explore nodes in a graph level-by-level. The algorithm starts at a given node,
adds its neighbors to the queue, and then processes each neighbor in turn.

9. Define the terms degree, level and height of the tree.


Degree – Number of sub trees of a node

Level – The level of a node is defined by 1 + (the number of connections between the
node and. the root).

Height. In a tree data structure, the number of edges from the leaf node to the particular
node in the longest path is known as the height of that node.

10.state the differences between binary tree and general tree.

11. write insertion sort with example and write a program to


implement insertion sort.
Insertion sort is a simple sorting algorithm that works by iteratively inserting each
element of an unsorted list into its correct position in a sorted portion of the list. It is
like sorting playing cards in your hands. You split the cards into two groups: the sorted
cards and the unsorted cards. Then, you pick a card from the unsorted group and put
it in the right place in the sorted group.
 We start with second element of the array as first element in the array is assumed
to be sorted.
 Compare second element with the first element and check if the second element is
smaller then swap them.
 Move to the third element and compare it with the first two elements and put at its
correct position
 Repeat until the entire array is sorted.
// C program for implementation of Insertion Sort
#include <stdio.h>

/* Function to sort array using insertion sort */


void insertionSort(int arr[], int n)
{
for (int i = 1; i < n; ++i) {
int key = arr[i];
int j = i - 1;

/* Move elements of arr[0..i-1], that are


greater than key, to one position ahead
of their current position */
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}

/* A utility function to print array of size n */


void printArray(int arr[], int n)
{
for (int i = 0; i < n; ++i)
printf("%d ", arr[i]);
printf("\n");
}

// Driver method
int main()
{
int arr[] = { 12, 11, 13, 5, 6 };
int n = sizeof(arr) / sizeof(arr[0]);

insertionSort(arr, n);
printArray(arr, n);

return 0;
}

12. Explain insertion is performed in doubly linked list.

Inserting a new node in a doubly linked list is very similar to inserting new node in
linked list. There is a little extra work required to maintain the link of the previous
node. In this article, we will learn about different ways to insert a node in a doubly
linked list.

To insert a new node at the front of doubly linked list,


 Create a new node, say new_node with its previous pointer as NULL.
 Set the next pointer to the current head, new_node->next = head.
 Check if the linked list is not empty then we update the previous pointer of the
current head to the new node, head->prev = new_node.
 Finally, we return the new node as the head of the linked list.

13.Explain implementation of stack using linked list.

To implement a stack using the singly linked list concept, all the singly linked
list operations should be performed based on Stack operations LIFO(last in first out)
and with the help of that knowledge, we are going to implement a stack using a singly
linked list.
So we need to follow a simple rule in the implementation of a stack which is last in
first out and all the operations can be performed with the help of a top variable. Let us
learn how to perform Pop, Push, Peek, and Display operations in.
In the stack Implementation, a stack contains a top pointer. which is the “head” of the
stack where pushing and popping items happens at the head of the list. The first node
has a null in the link field and second node-link has the first node address in the link
field and so on and the last node address is in the “top” pointer.
The main advantage of using a linked list over arrays is that it is possible to implement
a stack that can shrink or grow as much as needed. Using an array will put a
restriction on the maximum capacity of the array which can lead to stack overflow.
Here each new node will be dynamically allocated. so overflow is not possible.

14.A+[B*C-(D/E^F)*G)*H ANS: ABC*DEF^/G*-H*+


15. Explain queue using arrays.
To implement a queue using a simple array,
 create an array arr of size n and
 take two variables front and rear which are initialized as 0 and -1 respectively
 rear is the index up to which the elements are stored in the array including the rear
index itself. We mainly add an item by incrementing it.
 front is the index of the first element of the array. We mainly remove the element
at this index in Dequeue operation.
 Enqueue: Addition of an element to the queue. Adding an element will be
performed after checking whether the queue is full or not. If rear == capacity-1,
then it is said to be an Overflow condition as the array is full. If array is not full.
then store the element at arr[rear] and increment rear by 1 .
 Dequeue: Removal of an element from the queue. An element can only be deleted
when there is at least an element to delete. If rear == -1, then it is said to be an
Underflow condition as the array is empty. If the element at arr[front] can be
deleted then move all the remaining elements to the left by one position in order to
maintain the FIFO (the first element must be deleted).
 Front: Get the front element from the queue i.e. arr[front] if the queue is not empty.
 Display: Print all elements of the queue. If the queue is non-empty, traverse and
print all the elements from the index front to rear.

16. Implementation of circular queue using linked list.

Operations on Circular Queue:


 Front:Get the front item from queue.
 Rear: Get the last item from queue.
 enQueue(value) This function is used to insert an element into the circular queue.
In a circular queue, the new element is always inserted at Rear position.
1. Create a new node dynamically and insert value into it.
2. Check if front==NULL, if it is true then front = rear = (newly created node)
3. If it is false then rear=(newly created node) and rear node always contains the
address of the front node.
 deQueue() This function is used to delete an element from the circular queue. In a
queue, the element is always deleted from front position.
1. Check whether queue is empty or not means front == NULL.
2. If it is empty then display Queue is empty. If queue is not empty then step 3
3. Check if (front==rear) if it is true then set front = rear = NULL else move the
front forward in queue, update address of front in rear node and return the
element.
17.Tree representations.

Binary tree is a tree data structure (non-linear) in which each node can have at
most two children which are referred to as the left child and the right child. The
topmost node in a binary tree is called the root, and the bottom-most nodes are
called leaves. A binary tree can be visualized as a hierarchical structure with the root
at the top and the leaves at the bottom.
Binary trees can be represented in multiple ways, each with its own advantages,
depending on the use case. Let's explore the two common methods: linked node
representation and array implementation.
Representation of Binary Trees
There are two primary ways to represent binary trees:
1. Linked Node Representation
2. Array Representation
1. Linked Node Representation
This is the simplest way to represent a binary tree. Each node contains data and
pointers to its left and right children.
This representation is mostly used to represent binary tree with multiple advantages.
The most common advantages are given below.

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