0% found this document useful (0 votes)
22 views5 pages

viva

The document provides an overview of data structures, including definitions and types such as primitive and non-primitive structures, arrays, stacks, queues, and linked lists. It covers key operations, memory allocation methods, and differences between data structures like singly and doubly linked lists, as well as binary trees and binary search trees. Additionally, it discusses applications of these data structures in various programming scenarios.

Uploaded by

nikilhe318
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)
22 views5 pages

viva

The document provides an overview of data structures, including definitions and types such as primitive and non-primitive structures, arrays, stacks, queues, and linked lists. It covers key operations, memory allocation methods, and differences between data structures like singly and doubly linked lists, as well as binary trees and binary search trees. Additionally, it discusses applications of these data structures in various programming scenarios.

Uploaded by

nikilhe318
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 data structure?

A data structure is a way of organizing and storing data in a computer so that it can be
accessed and modified efficiently. It is mainly 2 type:
• Primitive datastructure: Fundamental data structure, represent single values. Eg: int,
float, char
• Non- primitive datastructure: Higher level data structure built using primitive data
types. Divided into two:
Linear data structure: Data elements stored in a sequential order. Eg: Array,
queue, Stack, Linked list
Non linear data structure: Data elements are not sequentialy stored. Eg: Tree,
Graph

Static memory allocation: Has a fixed memory size. Allocate memory during compile time. Eg : array

Dynamic memory allocation: Size is not fixed. Allocate memory during run time. Eg : linked list

2. What is an array & how many types of arrays represented in memory?

Array is a collection of elements, all of the same type, that are stored in contiguous memory
locations. The elements in an array are indexed, meaning each element can be accessed
directly using its index or position in the array.
Mainly 2 types of array:
• One- dimensional array
• Multi-dimensional array

3. How can be declared an array?

Syntax for array declaration: <datatype> <array_name>[<size>];


Declaration: int arr[5]; / / Declares an integer array of size 5
Initialization: int arr[5] = {1,2,3,4,5}; // Array of integers initialized with values

4. What are the operations of array?

Traversal: Access and process each element in the array.


Insertion: Insert an element at a specific position in the array, shifting other elements if
necessary.
Deletion: Remove an element from a specific position, shifting other elements to fill the
gap.
Searching: Find the index of an element (e.g., linear search or binary search).
Updating: Modify the value of an existing element at a specific index.
Sorting: Arrange elements in a particular order (ascending or descending).
Merging: Combine two arrays into a single array.

5. How can be insert an element in an array?

int main()
{
int arr[6] = {1, 2, 3, 4, 5}; // Array of size 5
int newElement = 10;
int position = 2; // Insert at position 2 (0-based index)
// Shift elements to the right to make space for the new element
for (int i = 4; i >= position; i--)
{
arr[i + 1] = arr[i];
}
// Insert the new element
arr[position] = newElement;
}

6. How can be delete an element in an array?

int arr[5] = {1, 2, 3, 4, 5};


int position = 2;
for (int i = position; i < 4; i++)
{
arr[i] = arr[i + 1]; // Shift elements to the left
}

7. How many types of implementations of a two-dimensional array?

The two most common ways to implement a 2D array are:

1. Contiguous Memory Allocation


2. Linked List Representation

8. What is array of pointers?


Array of pointers is a type of array where each element in the array is a pointer that points
to a memory location (which may be the address of another variable, array, or data
structure).
9. What are limitations of array?
• The size of the array is fixed at the time of declaration, which means you cannot
change the size dynamically once the array is created.
• Since arrays allocate memory contiguously, there might be unused space in the
array if not all elements are used.
• Inserting or deleting elements in the middle of an array requires shifting the
remaining elements. This operation is O(n) in time complexity, making it inefficient
for large arrays.
10. Where the elements of the array are stored respectively in successive?
stored in contiguous memory locations (i.e., one after the other) in successive memory
locations.
11. What is stack?
A stack is a linear data structure that follows the Last In, First Out (LIFO) principle.
Operations:
• Push: add an element to the top of the stack.
• Pop: remove an element from the top of the stack.
• Peek: operation to look at the top element without removing it.
• IsEmpty: Checks whether the stack is empty or not.
• IsFull: Checks whether the stack is full (in the case of a fixed-size stack).
Top of Stack refers to the element that is currently at the top of the stack. It is the last
element that was pushed onto the stack and the first element that will be popped off
the stack.

Condition check before push an element: Stack overflow (stack is full) (top>= max)
Condition check before pop an element: Stack underflow (stack is empty) (top<0)

12. How stacks are implemented?


Stacks can be implemented in two ways:
• Using array
• Using linked list
13. What are the applications of stack?
• Stacks are used to evaluate mathematical expressions (infix, postfix, and prefix
notation)
• Stacks are used in backtracking algorithms (such as solving mazes) to keep track of
choices and explore alternative paths.
• In text editors and other applications, stacks can be used to implement the undo
functionality.
14. What is recursion?
It is a programming technique where a function calls itself in order to solve a problem.
15. Explain infix, postfix, prefix
• Infix expression: operators are in between the two operands . Example a+b
• Prefix expression: operators are present before the operands. Example +ab
• Postfix expression: operators are present after the operands. Example ab+

Data structure used for infix to postfix conversion and evaluation of postfix expression: Stack

16. What is queue?


Ordered collection of elements that has 2 ends front and rear. It follows FIFO (First in first
out)
From the front end we delete elements.
From the rear end we insert elements.
Operations:
• Enqueue: insert element in queue from rear end. Before insertion you must check
whether queue is full or not. If it is full, insertion not possible.
• Dequeue: delete element from front end. Before deletion you must check whether
queue is empty or not. If it empty deletion not possible.
• Que_full(): check whether queue is full or not. (rear>= size-1)
• Que_empty(): check whether queue is empty or not (front = = -1)

17. What is Circular Queue? Why use of Circular Queue?

Circular Queue is a type of queue data structure that uses a circular array to efficiently manage
elements in a queue, allowing both ends (front and rear) to be connected in a loop.
• In a regular queue, once elements are dequeued and the front pointer moves, there may be
unused space at the beginning of the array. This is inefficient as new elements cannot be
added until the front pointer reaches the rear pointer again. In a circular queue, the unused
spaces are reused.
18. What is Priority Queue?
A Priority Queue is a type of abstract data structure that operates similarly to a regular
queue, but with one key difference: each element in a priority queue has a priority
associated with it. Elements with higher priority are dequeued before those with lower
priority, regardless of their position in the queue.
Two types:
o Max-Priority Queue: In a max-priority queue, the element with the highest
priority is always dequeued first.
o Min-Priority Queue: In a min-priority queue, the element with the lowest
priority is dequeued first.

19. Application of Queue?


• Job Scheduling in Operating Systems
• In multi-user systems where multiple print jobs are sent to a single printer, a queue
helps in organizing the print jobs.
• Breadth-First Search (BFS) in Graph Traversal
20. what is Linked lists?
• Linear data structure
• Elements not stored in contiguous memory location
• Elements are linked using pointers
• Linked list made up of nodes that consist of 2 parts: data and link
• Data contain the actual data and link contain the address of next node
• Types of linked list:
▪ Singly linked list
▪ Doubly linked list
▪ Circular linked list
▪ Circular doubly linked list

21. what is the difference between singly and doubly linked lists?
Feature Singly linked list Doubly linked list

Pointers in Node 1 pointer (next) 2 pointers (next, prev)

Traversal Unidirectional (from head to Bidirectional (both directions)


tail)

Memory Usage Less memory (1 pointer per More memory (2 pointers per
node) node)

Insertion/Deletion More complex (requires More efficient (direct access


traversal) to previous node)
Use cases Simple data structures like
stacks, queues Advanced operations,
navigation systems,
deques

22. what are the applications of Linked Lists?


❖ Representation of polynomial and performing various operations such as addition,
multiplication and evaluation on it.
❖ Performing addition of long positive integers.
❖ Representing non- integer and non- homogeneous list.

23. What is binary search tree?

A Binary Search Tree (BST) is a type of binary tree in which each node has at most two
children, typically referred to as the left and right child. For any node in the BST:

o All the nodes in the left subtree have values less than the node's value.
o All the nodes in the right subtree have values greater than the node's value.

24. What is binary tree?


Tree consist of atmost 2 children. Two types:
Complete binary tree: contains maximum possible number of nodes at all levels. All
levels are at same depth.
Almost complete binary tree: each node has a left child whenever it has a right child.

You might also like