Data Structure Fin
Data Structure Fin
Data Structure
Which of the following data structure is non-linear type? [Combined(O-IT/ICT)-2019]
a) Strings b) Lists c) Stacks d) None of these Ans. d
Explanation: Data structures refers to the way data is organized and manipulated. It helps to find
ways to make data access more efficient. When dealing with data structure, we not only focus on
one piece of data, but rather different set of data and how they can relate to one another in an
organized manner.
Linear Data Structures: The data structure where data items are organized sequentially or
linearly where data elements attached one after another is called linear data structure. Data
elements in a liner data structure are traversed one after the other and only one element can be
directly reached while traversing. All the data items in linear data structure can be traversed in
single run.
Non Linear Data Structures: The data structure where data items are not organized sequentially
is called non linear data structure. In other words, A data elements of the non linear data structure
could be connected to more than one elements to reflect a special relationship among them. All
the data elements in non linear data structure can not be traversed in single run.
list,
arrays,
Cloud IT Online Page22 Data Structure
stack,
queues,
graph,
Tree.
Explanation:
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.
Explanation:
List out a few areas in which data structures are applied extensively?
Compiler Design,
Operating System,
Database Management System,
Statistical analysis package,
Numerical Analysis,
Graphics,
Artificial Intelligence,
and Simulation.
int a = 0, i = N;
while (i > 0) {
a += i;
i /= 2;
}
Introduction
In computer science, the time complexity of an algorithm quantifies the amount of time taken by
an algorithm to run as a function of the length of the string representing the input.
Big O notation
The time complexity of an algorithm is commonly expressed using big O notation, which
excludes coefficients and lower order terms. When expressed this way, the time complexity
is said to be described asymptotically, i.e as the input size goes to infinity.
For example, if the time required by an algorithm on all inputs of size n is at most 5n3 + 3n,
the asymptotic time complexity is O(n3). More on that later.
Few more Examples:
1 = O(n)
n = O(n2)
Cloud IT Online Page44 Data Structure
log(n) = O(n)
2 n + 1 = O(n)
O(1) Constant Time:
An algorithm is said to run in constant time if it requires the same amount of time regardless
of the input size.
Examples array: accessing any element
fixed-size stack: push and pop methods
fixed-size queue: enqueue and dequeue methods
O(n) Linear Time
An algorithm is said to run in linear time if its time execution is directly proportional to the
input size, i.e. time grows linearly as input size increases.Consider the following examples,
below I am linearly searching for an element, this has a time complexity of O(n).
More Examples:
Array: Linear Search, Traversing, Find minimum etc
ArrayList: contains method
Queue: contains method
O(log n) Logarithmic Time:
An algorithm is said to run in logarithmic time if it’s time execution is proportional to the
logarithm of the input size.
Example: Binary Search
Recall the twenty question game - the task is to guess the value of a hidden number in an
interval. Each time you make a guess, you are told whether your guess is too high or too low.
Twenty questions game implies a strategy that uses your guess number to halve the interval
size. This is an example of the general problem-solving method known as binary search
O(n2) Quadratic Time
An algorithm is said to run in quadratic time if it’s time execution is proportional to the
square of the input size.
Examples:
Bubble Sort
Selection Sort
Insertion Sort
A linear collection of data elements where the linear node is given by means of pointer is
called?
a) Linked list
b) Node list
c) Primitive list
d) Unordered list
Ans.: a
Explanation: In Linked list each node has its own data and the address of next node. These nodes
are linked by using pointers. Node list is an object that consists of a list of all nodes in a
document with in a particular selected set of nodes.
In linked list each node contain minimum of two fields. One field is data field to store the
data second field is?
a) Pointer to character
b) Pointer to integer
c) Pointer to node
d) Node
Ans.: c
Explanation: Each node in a linked list contains data and a pointer (reference) to the next node.
Second field contains pointer to node.
What would be the asymptotic time complexity to add a node at the end of singly linked list,
if the pointer is initially pointing to the head of the list?
a) O(1)
Cloud IT Online Page66 Data Structure
b) O(n)
c) θ(n)
d) θ(1)
Ans.: c
Explanation: In case of a linked list having n elements, we need to travel through every node of
the list to add the element at the end of the list. Thus asymptotic time complexity is θ(n).
There are many types of algorithm but the most fundamental types of algorithm are:
1. Recursive algorithms
2. Dynamic programming algorithm
3. Backtracking algorithm
4. Divide and conquer algorithm
5. Greedy algorithm
6. Brute Force algorithm
7. Randomized algorithm
Some Algorithms:
Dynamic Programming:
Divide-and-conquer approach:
Greedy algorithm:
Cloud IT Online Page1010 Data Structure
A greedy algorithm always makes the choice that looks best at the moment
The hope is : a locally optimal choice will lead to a globally optimal solution
For some problems, it works.
Everyday examples:
Playing cards
Choosing a university
1. Which data structure allow deleting data elements front and inserting at Ans. b
rear?[Assistant programmer (ICB)- 2017]
a) Stack b) Queue c) Dequeue d) Binary search tree
3. Which of the following name does not related to stacks?[AP(ICB)- 2017, Ans. a
AP(HBFC, KB)-2018]
a) FIFO List b) LIFO List c)Piles d) Push Down List
Explanation: FIFO is related to Queue.
5. Which of these data types is used by operating system to manage the Ans. b
Recursion in Java?[Combined(IT/ICT-2018)]
a)Array b) Stack c) Queue d) Tree
6. Pushing an element into stack already having five elements and stack size Ans. a
of 5. Result in [Combined (AP)-2018]
a) Overflow b) Crash c) Underflow d) User flow
8. Find the correct arranged data after stack operation? [BB (AP)-2016] Ans. a
push(1), push(2), pop, push(1), push(2), pop, pop, pop, push(2)
(a) 2 2 1 1 2 (b) 2 2 1 2 1 (c) 2 2 2 2 1 (d) 2 2 2 1 2
Cloud IT Online Page11
11 Data Structure
TREE
Tree is non-linear data structu
structure designated at a special node calledroot and elements
el are
arranged in levels withoutt conta
containing cycles.
Or
The tree is
Rooted at one vertex
Contains no cycles
There is a sequence ce of eedges from any vertex to any other
Any number of elementements may connect to any node (includingroot)
A unique path traverses
verses from root to any node of tree
The elements are arrang
arranged in layers
BINARY TREE
It is a special type of tree where each node of tree contains either0 or 1 or 2 children.
Or
Binary Thee is either empty, or it consists of a root with two binarytrees called left-sub tree
and right sub-tree of root (left or right orboth the sub trees may be empty)
3. What happens when you push a new node onto a stack? Ans. a
a) The new node is placed at the front of the linked list
b) The new node is placed at the back of the linked list
c) The new node is placed at the middle of the linked list
d) No Changes happens
5. Entries in a stack are “ordered”. What is the meaning of this statement? Ans. d
a) A collection of stacks is sortable
b) Stack entries may be compared with the ‘<‘ operation
c) The entries are stored in a linked list
d) There is a Sequential entry that is one by one