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

Data Structure

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Data Structure

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

What is data structure?

Is a data organization , management and storage format that enable efficient access and
modification(insert , deletion , search)

What is algorithm?
Algorithm is a step by step procedure, which defines a set of instructions to be executed in
certain order to get the desired output.

Data structure type?

Why we need to do algorithm analysis?


A problem can be solved in more than one ways. So, many solution algorithms can be derived
for a given problem. We analyze available algorithms to find and implement the best suitable
algorithm.

What are the criteria of algorithm analysis?


An algorithm are generally analyzed on two factors − time and space. That is, how
much execution time and how much extra space required by the algorithm.

What is asymptotic analysis of an algorithm?


Asymptotic analysis of an algorithm, refers to defining the mathematical boundation/framing of
its run-time performance. Using asymptotic analysis, we can very well conclude the best case,
average case and worst case scenario of an algorithm.

What are asymptotic notations?


Asymptotic analysis can provide three levels of mathematical binding of execution time of an
algorithm −

Best case is represented by Ω(n) notation.


Worst case is represented by Ο(n) notation.

Average case is represented by Θ(n) notation.

What is linear data structure?


A linear data-structure has sequentially arranged data items. The next time can be
located in the next memory address. It is stored and accessed in a sequential manner.
Array and list are example of linear data structure.

What is linear and non-linear data structure?


In a linear data structure, the data elements connect to each other sequentially. A user can
transverse each element through a single run. In a non-linear data structure, the data elements
connect to each other hierarchically. Thus, they are present at various levels.

What are common operations that can be performed on a data-


structure?
The following operations are commonly performed on any data-structure −
 Insertion − adding a data item
 Deletion − removing a data item
 Traversal − accessing and/or printing all data items
 Searching − finding a particular data item
 Sorting − arranging data items in a pre-defined sequence

Briefly explain the approaches to develop algorithms.


There are three commonly used approaches to develop algorithms −
 Greedy Approach − finding solution by choosing next best option
 Divide and Conquer − diving the problem to a minimum possible sub-problem and
solving them independently
 Dynamic Programming − diving the problem to a minimum possible sub-problem
and solving them combinedly

What is the stack?


stack is an Abstract Data Type (ADT) and linear type of data structure that follows the LIFO
(Last-In-First-Out) principle and allows insertion and deletion operations from one end of the
stack data structure, that is top is takes only Ο(n) time , used commonly in recursive function
calls, expression parsing, depth first traversal of graphs etc.

What operations can be performed on stacks?


The below operations can be performed on a stack −
 push() − adds an item to stack
 pop() − removes the top stack item
 peek() − gives value of top item without removing it
 isempty() − checks if stack is empty
 isfull() − checks if stack is full

What is the linked stack?


A stack is represented using nodes of a linked list. Each node consists of two parts: data and
next(storing the address of the next node). The data part of each node contains the assigned
value, and the next points to the node containing the next item in the stack.

every new element is inserted as 'top' element. That means every newly inserted element is
pointed by 'top'. Whenever we want to remove an element from the stack, simply remove the
node which is pointed by 'top' by moving 'top' to its previous node in the list.

What is the difference between array stack and linked stack?


In array, Insertion and Deletion operation takes more time, as the memory locations are
consecutive and fixed. In case of linked list, a new element is stored at the first free and
available memory location, with only a single overhead step of storing the address of memory
location in the previous node of linked list.

What is the difference between array and linked list?


An array is a collection of elements of a similar data type. A linked list is a collection of objects
known as a node where node consists of two parts, i.e., data and address. Array elements store
in a contiguous memory location. Linked list elements can be stored anywhere in the memory or
randomly stored.

What are the main advantages of linked list over array?


In short, there are several advantages of linked list over arrays, such as dynamic size, efficient
insertion and deletion, memory efficiency, easy implementation of abstract data types, and
more efficient sorting in some cases.

What is the difference between stack and linked?


A stack works on the principal of LIFO mechanism, in which the last element inserted will be
removed first and both insertion and deletion will took place from that one end only. whereas,
in a linked list, the elements connect to each other by references. Hence, this is another
difference between stack and linked list.

Different between array and stack?


An array is a data structure consisting of a collection of elements each identified by the array
index. In contrast, a stack is an abstract data type that serves as a collection of elements with
two principal operations: push and pop. Thus, this is the main difference between Array and
Stack.

What is a queue in data-structure?


Queue is an abstract data structure, somewhat similar to stack. In contrast to stack, queue
is opened at both end. One end is always used to insert data (enqueue) and the other is used
to remove data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data
item stored first will be accessed first.

Why do we use queues?


As queues follows FIFO method, they are used when we need to work on data-items in
exact sequence of their arrival. Every operating system maintains queues of various
processes. Priority queues and breadth first traversal of graphs are some examples of
queues.

What operations can be performed on Queues?


The below operations can be performed on a stack −
 enqueue() − adds an item to rear of the queue
 dequeue() − removes the item from front of the queue
 peek() − gives value of front item without removing it
 isempty() − checks if stack is empty
 isfull() − checks if stack is full

What is balanced parentheses in stack?


In computer science, balanced parentheses are a common requirement for many programming
languages and applications. Balanced parentheses refer to an expression in which all opening
and closing parentheses are properly matched and nested. A balanced expression ensures that
the program can be executed without any errors

What is the difference between static and dynamic array in data


structure?
A static array variable holds a value of type, array. A dynamic array variable holds a pointer to an
array value. Thanks to automatic pointer dereferencing and automatic index padding

in Dynamic data structure the size of the structure is not fixed and can be modified during the
operations performed on it. Dynamic data structures are designed to facilitate change of data
structures in the run time. Static data structures, such as arrays, have a fixed size and are
allocated at compile-time.

what is linked list in data structure ?


Linked List can be defined as collection of objects called nodes that are randomly stored in the
memory. A node contains two fields i.e. data stored at that particular address and the pointer
which contains the address of the next node in the memory. The last node of the list contains
pointer to the null.

What is type of linked list?


There are four key types of linked lists:

Singly linked lists. Doubly linked lists.

Circular linked lists. Circular doubly linked lists.

What is the difference between Array and linked list?

What is Singly linked lists?


a type of linked list that is unidirectional, that is, it can be traversed in only one direction from
head to the last node (tail). Each element in a linked list is called a node.

What is Doubly linked lists?


can be traversed in both directions, either from the first node to the last node or from the last
node to the first node and is a more complex type of linked list which contains a pointer to the
next as well as the previous node in the sequence. This solves the issue of reverse traversal that
was not possible in the singly linked list. It is also known as a two-way list.

What is Circular linked lists?


circular linked list is a linked list where all nodes are connected to form a circle. In a circular
linked list, the first node and the last node are connected to each other which forms a circle.
There is no NULL at the end.

What is Circular doubly linked lists?


A circular doubly linked list is a mixture of a doubly linked list and a circular linked list. Like the
doubly linked list, it has an extra pointer called the previous pointer, and similar to the circular
linked list, its last node points at the head node
What is the tree?
A tree is a minimally connected graph having no loops and circuits. Nodes represent value and
nodes are connected by edges. A tree has the following properties: The tree has one node called
root. The tree originates from this, and hence it does not have any parent.

What is the type of tree?

What is a binary tree and why is it used?


A binary tree is a tree data structure comprising of nodes with at most two children i.e. a right
and left child. The node at the top is referred to as the root. A node without children is known as
a leaf node. Most applications use different variants of binary trees such as tries, binary search
trees, and B-trees

What is a binary search tree?


A binary search tree is a binary tree with a special provision where a node's left child
must have value less than its parent's value and node's right child must have value greater

than it's parent value.

What is tree traversal?


Tree traversal is a process to visit all the nodes of a tree. Because, all nodes are connected via
edges (links) we always start from the root (head) node. There are three ways which we use to
traverse a tree −

In-order Traversal Pre-order Traversal Post-order Traversal


What is an AVL Tree?
AVL trees are height balancing binary search tree. AVL tree checks the height of left and right
sub-trees and assures that the difference is not more than 1. This difference is called Balance
Factor.

BalanceFactor = height(left-sutree) − height(right-sutree)

What is Huffman coding in C code?


Huffman coding is lossless data compression algorithm. In this algorithm a variable-length code
is assigned to input different characters. The code length is related with how frequently
characters are used. Most frequent characters have smallest codes, and longer codes for least
frequent characters
What is selection sort?
Selection sort is in-place sorting technique. It divides the data set into two sub-lists: sorted and
unsorted. Then it selects the minimum element from unsorted sub-list and places it into the
sorted list. This iterates unless all the elements from unsorted sub-list are consumed into sorted
sub-list.

What is bubble sort and how bubble sort works?


Bubble sort is comparison based algorithm in which each pair of adjacent elements is compared
and elements are swapped if they are not in order. Because the time complexity is Ο(n2), it is
not suitable for large set of data.

Tell me something about 'insertion sort'?


Insertion sort divides the list into two sub-list, sorted and unsorted. It takes one element at time
and finds it appropriate location in sorted sub-list and insert there. The output after insertion is
a sorted sub-list. It iteratively works on all the elements of unsorted sub-list and inserts them to
sorted sub-list in order.

How insertion sort and selection sorts are different?


Both sorting techniques maintains two sub-lists, sorted and unsorted and both take one
element at a time and places it into sorted sub-list. Insertion sort works on the current element
in hand and places it in the sorted array at appropriate location maintaining the properties of
insertion sort. Whereas, selection sort searches the minimum from the unsorted sub-list and
replaces it with the current element in hand.

What is merge sort and how it works?


Merge sort is sorting algorithm based on divide and conquer programming approach. It keeps
on dividing the list into smaller sub-list until all sub-list has only 1 element. And then it merges
them in a sorted way until all sub-lists are consumed. It has run-time complexity of Ο(n log n)
and it needs Ο(n) auxiliary space.
What is shell sort?
Shell sort can be said a variant of insertion sort. Shell sort divides the list into smaller sublist
based on some gap variable and then each sub-list is sorted using insertion sort. In best cases, it
can perform upto Ο(n log n).

How quick sort works?


Quick sort uses divide and conquer approach. It divides the list in smaller 'partitions' using
'pivot'. The values which are smaller than the pivot are arranged in the left partition and greater
values are arranged in the right partition. Each partition is recursively sorted using quick sort.

How heap sort works?


Heap is a special balanced binary tree data structure where root-node key is compared with its
children and arranged accordingly. A min-heap, a parent node has key value less than its childs
and a max-heap parent node has value greater than its childs.

How linear search works?


A linear search is the simplest approach employed to search for an element in a data set. It
examines each element until it finds a match, starting at the beginning of the data set, until the
end. The search is finished and terminated once the target element is located.

What is binary search?


A binary search works only on sorted lists or arrays. This search selects the middle which splits
the entire list into two parts. First the middle is compared.

This search first compares the target value to the mid of the list. If it is not found, then it takes
decision on whether.
What is 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.

What is a graph?
A graph is a pictorial representation of a set of objects where some pairs of objects are
connected by links. The interconnected objects are represented by points termed as vertices,
and the links that connect the vertices are called edges.

How depth first traversal works?


Depth First Search algorithm(DFS) traverses a graph in a depthward motion and uses a stack to
remember to get the next vertex to start a search when a dead end occurs in any iteration.

How breadth first traversal works?


Breadth First Search algorithm(BFS) traverses a graph in a breadth wards motion and uses a
queue to remember to get the next vertex to start a search when a dead end occurs in any
iteration.

You might also like