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

Data Structure

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)
31 views63 pages

Data Structure

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/ 63

Q.

1 Define the following terms :


(i) Data:
Ans. Data are simply values or set of values.

(ii) Group items :


Ans. Data items which are divided into subitems are called as group items. e.g. Date may be
divided into three subitems – day, month and year. So Date becomes group item.

(iii) Elementary items :


Ans. Data items which are not divided into subitems are called as elementary items. e.g.
pincode number cannot be divided into subitems. So it is elementary item.

(iv) Entity :
Ans. An entity is something that has certain attributes or properties which may be assigned
values.
The values themselves may be numeric or non-numeric.

e.g. A Bio-data sheet mainly contains :

Asked in Board
Exam (March 2005, 2009,2016; Oct. 2007,2014) Important
(v) Field: Field is a single elementary unit of information representing an attribute of an entity.

Asked in Board Exam (March 2005, 2009,2016; Oct. 2007,2014) Important


(vi) Record: Record is a collection of field values of a given entity.

Asked in Board Exam (March 2005, 2009,2016; Oct. 2007,2014) Important


(vii) File : File is the collection of records of the entities in a given entity set.

Q. 2 What is a data structure ?


Asked in Board Exam (Mar. 2006,2015; Oct. 2002, 2004) Important
Ans : i) Data may be organized in many different ways. Data structure is the way: in which
different data elements are logically related.

ii) Collection of data elements forming an organisation characterized by the accessing


functions is called data structure.

iii) The data structure should be simple and it should show the relationship between data
elements.

iv) Types:
(i) Linear data structure (ii) Non-linear data structure.

In linear data structure, data elements are stored in consecutive memory locations or by
using linked representation. e.g. arrays, linked list.

In non-linear data structures, the linear order cannot be maintained between data elements
Generally data elements have hierarchical relationship between them. e.g. trees

v) Computer language provides different data structures like arrays, stack, queue, tree etc.

Data Structure Operations

Q. 3 Explain in brief any six data structure


operations.
Asked in Board Exam (Oct. 2002,04,06,12,15; Mar. 2002,06,12) Important
Ans. : The data appearing in data structures are processed by means of certain operations like
:
(i) Traversing :

Accessing, each record or element exactly once, so that it can be processed is called
traversing.
For e.g: multiplying each element of an array by 6.

(ii) Inserting :
Adding a new record to the existing structure is called as inserting.

(iii) Deleting :
Removing a record from the existing structure is called as deleting.

(iv) Searching :
Finding the location of a record with given key values or finding the locations of all records
which satisfy one or more conditions is called as searching.

(v) Sorting :
Arranging records in some logical order is called as sorting.

(vi) Merging :
Merging means combining the records in two different sorted files into a single sorted file.

Algorithmic Notation

Q. 4. What is an algorithm?
Ans. :
i) An algorithm is a finite step by step list of well-defined instructions for solving a particular
problem.

ii) An algorithm consists of two parts :


(a) First part is a paragraph which tells the purpose of algorithm. In this part, we define
variables in algorithm and lists the input data.

(b) The second part of algorithm consists of steps in algorithm that are executed one after
the another, generally beginning with step 1, unless stated otherwise. The control
can be transferred to step n, by the statement “go to step n”.
The algorithm is completed, when the statement ‘Exit’ or ‘Stop’ is encountered.

iii) e.g. Algorithm to find largest element in array.


Largest [DATA, N, MAX]
Here, DATA is a linear array with N elements. This algorithm finds the largest element
MAX of DATA.

Step 1: [Initialize counter]

set k: = 1 and Max: = DATA [1]

Step 2: [Compare and Update]

If MAX < DATA [k + 1],

then : MAX: = DATA [k + 1]

[End of If structure]
Step 3: [Increment counter] set k: = k + 1

Step 4: [Test counter] If k < N, then : go to step 2

[End of If structure]

Step 5: Write MAX

Step 6: Exit

Q.5 Describe sequence logic or sequential flow.


Ans :
i) In the sequence logic, modules are executed sequentially, one after the another.

ii) The Sequence may be present explicitly by means of numbered step or by the order in
which modules are written.

iii) In short in sequential logic or sequential flow, modules of an algorithm are executed one
after the another.
Q.6 Describe conditional flow or selection logic.
Ans : Selection logic uses number of conditions, which cause selection of one out of several
alternative modules. The structure which implement this type of logic is known as selection
logic, or conditional structure:

There are three types of conditional structures :

(i) Single alternative :


This has the form :

If condition, then :

[module A]

[End of If structure]

The logic of this structure is as follows : If condition is satisfied (true) then module A, which
consists of number of statements, is executed. Otherwise, module A is skipped and next
module of algorithm is executed.

ii) Double alternative :


This structure has the form :

If condition, then :

[module A]

Else :

[module B]

[End of If structure]
The logic of this structure is as follows
If the condition is satisfied, then module A will be executed otherwise module B will be
executed.

(iii) Multiple alternative :


This structure has the form :

If condition (1), then :

[module A1]

else if condition (2), then :

[module A2]

else if condition (n), then :

[module An]

else :

[module B]

[End of If structure]
The logic of this structure allows only one module to be executed. The module following the
condition, which is satisfied the condition will be executed. If no condition is satisfied, then the
module, which follows last Else statement will be executed.

Q. 7 Describe logic of Repeat-For loop.


Ans. : The repeat-for loop has the form :

Repeat for K=R ToS by T:

[module]

[End of For loop]

Here, K is called index variable, R and S are initial and final values of K and T is increment.
The logic of this structure is as follows :

At first, the body of loop i.e. module will be executed with K = R and then with K = R + T, then
with K = R + 2T and so on, until K <= S. The loop ends when K > S. If T is negative then K
decreases in value and loop ends when K < S.

Q. 8 Explain Repeat-While structure.


Ans : The repeat-while loop has the form :

Repeat While condition :


[module]

[End of loop]

Here, body of loop i.e. module is executed repeatedly, unit the condition is satisfied.

There must be a statement before the structure that initializes the condition controlling the
loop and there must be a statement in the body of the loop that changes the condition.

For e.g. Find largest element in array.

Given a nonempty array DATA with N numerical values. This algorithm finds the location LOC
and the value MAX of the largest element of DATA

1. Set K := 1, LOC := 1, MAX : = DATA[1]

2. Repeat step 3 and 4 while K <= N:

3. If MAX < DATA [K], then:

set LOC := K and

set MAX := DATA[K]

[End of If structure]

4. Set K := K +1

[End of step 2 loop]


5. Write : LOC, MAX

6. Exit

Q.9 Explain with flowcharts the following control


structures :
Asked in Board Exam (Mar. 2009,12; Oct. 2003, 04, 05,11,14) Important
(i) Sequence logic, (ii) Selection logic, (iii)Iteration logic

Ans :
(i) Sequence logic :
In the sequence logic modules are executed sequentially, one after the another. The sequence
may be present explicitly by means of numbered step or by the order in which modules are
written.

(ii) Selection logic :


Selection logic uses number of conditions, which cause selection of one out of several
alternative modules.

(a) Single alternative :


If condition is satisfied then module A, which consists of number of statements, is executed.
Otherwise module A is skipped and next module is executed.
(b) Double alternative :
If the condition is satisfied, then module A will be executed otherwise module B will be
executed.

(c) Iteration logic


Here certain module is executé repeatedly until condition satisfies.
At first, the body of loop i.e. module will be executed with K=R and then with K = R + T, then
with K = R + 2T and so on until K = S. The loop ends when K > S.

Here module is executed until the condition is satisfied.

Q. 10 Write an algorithm to find solutions of


quadratic equation Ax² + Bx + C = 0 where A ≠ C
Asked in Board Exam (Oct. 2002) Important
Ans : The algorithm inputs the coefficients A, B, C of a quadratic equation and outputs the
result: solution, if any.
ARRAY

Q.11 What are linear arrays ?


Asked in Board Exam (Oct. 2006,13,14; Mar.2015) Important
Ans : A data structure is said to be linear if its elements form a sequence.
A linear array is the data structure which consists of finite, ordered set of homogeneous data
elements such that :

1. The elements of the array are referenced respectively by an index set (subscript)
consisting of ‘n’ consecutive numbers.

2. The elements of the array are stored respectively in successive memory locations.

3. The number ‘n’ of the elements is called length or size of array.

In general, the size or length of the array can be obtained from the index set by the formul:-

Length = UB - LB +1

where UB - the largest index called Upper Bound.


LB - the smallest index called Lower Bound.
e.g. Let DATA be 5 element linear array as follows :
The element of an array may be denoted by the subscript notation such that :
DATA [3] = 600
In C++, array is declared as -
int data [100]; which specify an array data of 100 integers.

Q. 12 How arrays are represented in memory ?


Asked in Board Exam (Oct.2014) Important
Ans :

i) The elements of linear array are stored in consecutive memory locations.

ii) Computer does not need to keep track of the address of every element of array. It just
requires the address of first element of array, LA, denoted by Base (LA) and called the base
address of linear array LA.

iii) Using this base address, the computer calculates address of any element of array by using
the formula.

LOC (LA[K]) = Base (LA) + W (K - LB)

where,

LOC (LA[K]) is address of Kth element of LA


W is number of words per memory location for LA
and LB is lower bound i.e, smallest index of LA.

iv) The memory representation of an array is shown in figure below :


Q. 13 Consider the array AUTO, which records
number of automobiles from 1932 through,1984.
Suppose Base (AUTO) = 200 and W = 4 words.
Then,
LOC (AUTO [1932]) = 200, LOC (AUTO [1933]) = 204
LOC (AUTO [1934]) = 208

Calculate address at which 1965's record is stored.


Ans :

Given:- K = 1965

Base address = 200

W=4

LB = 1932

The address of the array element for the year 1965 can be obtained -

LOC (AUTO [1965]) Base (AUTO) + W (1965 - LB)

200 + 4 (1965 - 1932) = 332


Q.14 What is traversing an array ? Give the
algorithm for traversing a linear array?
Asked in Board Exam (Oct. 2005,12,15; March 2006) Important
Ans : Traversing an array means accessing with each element of array only at once, so that
can be processed.

Algorithm : Traversing a linear array.

Here LA is a linear array with lower bound LB and upper bound UB. Following algorithm apply
operation PROCESS to each element of LA.

Step 1: [Initialize counter]

set K: = LB

Step 2: Repeat steps 3 and 4 while K <= UB :

Step 3: [Visit element]

Apply PROCESS to LA[K]

Step 4: [Increment counter]

set K := K + 1

[End of step 2 loop]

Step 5: Exit

OR

This algorithm traverses a linear array LA with lower bound LB and upper bound UB.
Step 1: Repeat FOR K= LB To UB:

Apply PROCESS to LA[K]

[End of loop]

Step 2: Exit

Q. 15 What is inserting ? Write an algorithm for


inserting an element to a linear array.
Asked in Board Exam (Mar. 2009,11,16) (Oct.2015) Important
Ans :
i) Inserting refers to the operation of adding an element to the existing elements of array.

ii) The element can be easily inserted at the end of array. But for insertion in the middle of
array, it is required to move the elements of array one byte forward.

iii) The following algorithm inserts a data element ITEM into the kth position in an array LA
with N elements.

Algorithm :
INSERT (LA, N, K, ITEM)

Here LA is a linear array with N elements and K is a positive integer, such that K <= N. This
algorithm inserts an element ITEM at Kthposition in LA.

Step 1: [Initialize counter]

Set J: = N

Step 2: Repeat steps 3 and 4 while J >= K:

Step 3: [Move Jth element forward ]


Set LA[J + 1]: = LA[J]

Step 4: [Decrement counter]

Set J := J - 1

[End of step 2 loop]

Step 5: [Insert the element]

Set LA[K] := ITEM

Step 6: [Reset N]

Set N := N + 1

Step 7: Exit

Q. 16 What is deleting ? Write an algorithm for


deletion of an element from an array.
Asked in Board Exam (Oct. 07) Important

Ans :

i) Deleting means removing an element from the existing elements of an array.

ii) Deletion at the end of an array is easier. But, if to delete an element from mid of array. then
to move the elements of array one location upward.

iii) Algorithm : DELETE (LA, N, K, ITEM)


Here LA is a linear array with N elements and K is . a positive be Mean integer, 2 such that K =
N. This algorithm deletes Kth element from LA and assigns it i M. to variable ITEM

Step 1: Set ITEM := LA[K]

Step 2: Repeat For J = K to N - 1:


[Move (J + 1)ˢᵗ element backward]

Set LA[J] := LA[J + 1]

[End of loop]

Step 3: [Reset number Nof elements in [LA]

Set N := N - 1

Step 4: Exit

Q.17 Suppose a company keeps a linear array year,


such that year [K] contains number of employees
in year K. Write a module for each of the following
tasks
(a) To print each of the years in which no employee was born.
(b) To find the number N of years in which no employee was born.
(c) To find the number NL of employees, who will be atleast L years old at
the end of year 1984.

Linear array year contain elements from 1920 to 1970.

Ans :

(a) To print each of the years in which no employee was born.

1. Repeat for K := 1920 to 1970:

if year [K] = 0, then:

write : K

[End of If structure]
[End of loop]

2. Exit

(b) To find number N of years, in which no employee was born.

1. Set N := 0

2. Repeat for K = 1920 To 1970 :

If year [K] = 0, then:

N := N+1

[End of If structure]

[End of loop]

3. Write : N

4. Exit

(c) To find number of employees NL, who will be at least L years old at the end of year 1984
we want the number of employees born in ye ar 1984-L, or earlier.

1. Set NL = 0

2. Set X := 1984 - L

3. Repeat For K = 1920 To X :

Set NL := NL + year [K]

[End of loop]

4. Write : NL

5. Exit
Q. 18 Explain Bubble sort algorithm with suitable
example.
Asked in Board Exam (March 2002, 05, 08,12; Oct. 2005, 2008) Important

Ans:

Algorithm :

Bubble Sort (DATA, N)


Here DATA is a linear array with N elements. This algorithm sorts elements of DATA in
ascending order.

Step 1: Repeat steps 2 and 3 for K :=1 To N-1:

Step 2: Set Ptr := 1

Step 3: Repeat While Ptr <= N-K:

(a) If DATA [Ptr] > DATA [Ptr + 1], then interchange

DATA [Ptr] and DATA [Ptr + 1]

[End of lf structure]

(b) [increment pointer]

Set ptr = pir+1

[End of inner loop]

[End of outer loop]

Step 4: Exit

Explanation :
Suppose DATA is an array of N elements. Sorting these elements in ascending order means
arranging the elements such that :
DATA [1] < = DATA [2] <= …. <= DATA [N] In Bubble sort, compare DATA[1] with DATA[2]} and
exchange them it DATA[1] > DATA[2].

Next DATA[2] is compare with DATA[3]. They are exchanged if necessary. This process is
repeated till DATA [N – 1] is compared with DATA[N].

One makes N – 1 comparisons, this is called a pass.

After the first pass the largest element is sink to the last position.

During the next pass, compare elements upto the last but one and second largest element
moves to the (N – 1)ˢᵗ position.
After N- 1 passes, all elements are sorted.
Pass 4:
In this way after complete execution of this algorithm, the array gets sorted in ascending
order as follows :

Q. 19 What do you understand by the term


searching ? Which are the different types of
searching algorithms? Explain the linear searching
algorithm.
Asked in Board Exam (March 2004, Oct. 2004, 2010) Important

Ans :

Searching : Searching means to find out particular element from a given list of elements or
check whether required element is present or not in an array. There are two types of
searching algorithms as follows :

(1) Linear search

(2) Binary search

Linear searching algorithm :


In linear search the given element is compared with each element of list one by one.
For algorithm, refer to Q. No. 20.
Q. 20 Write an algorithm for linear search
technique with suitable example.
Asked in Board Exam (March 2003, 2007, 2009; Oct. 2007, 2010) Important

Ans :

Algorithm Linear Search


LINEAR(DATA, N, ITEM, LOC)
Here DATA is a linear array with N elements and ITEM is given element. This algorithm finds
the location LOC of ITEM in DATA or sets LOC = 0, if search is unsuccessful.

Step 1: [Insert ITEM at the end of DATA]

Set DATA [N + 1] := ITEM

Step 2: [Initialize counter]

Set LOC = 1

Step 3: [Search for item]

Repeat While DATA [LOC] ≠ ITEM :

Set LOC := LOC + 1

[End of loop]

Step 4: If LOC = N +1, then:

Set LOC = 0

Step 5: Exit

For example; Given DATA array with following 5 elements


11 22 33 44 55

Suppose ITEM = 33

Step 1: Set DATA [6] = 33, - List becomes

11 22 33 44 55 33

Step 2; LOC = 1

Step 3: Since DATA [1] = 11 ≠ 33 LOC = 2

Since DATA [2] = 22 ≠ 33 . LOC = 3

Here DATA [3] = 33 = 33 = ITEM

Step 4: Hence ITEM = 33 found at position, LOC = 3.

Q. 21 Write an algorithm for binary search


technique with example.
Asked in Board Exam (Oct. 2002,06,11,12,13) (Mar.2013, 14, 15,22) Important

Ans :

Binary search is used to search an element from sorted array.


Algorithm : Binary search

Binary (DATA, LB, UB, ITEM, LOC)

Here DATA is a sorted array with lower bound LB and upper bound UB. ITEM is given element.
BEG denotes beginning, MID denotes middle and END denotes end location of DATA.

This algorithm finds the location LOC of ITEM in DATA or sets LOC = NULL,
search is unsuccessful.
Step 1: [Initialize Variables]

Set BEG : = LB, END = UB and MID := INT ((BEG + END)/2)

Step 2: Repeat steps 3 and 4

while BEG = END AND DATA[MID] ≠ ITEM

Step 3: If ITEM < DATA[MID], then :

set END := MID - 1

Else :

Set BEG := MID + 1

[End of If structure]

Step 4: Set MID := INT ((BEG + END)/2)

[End of step 2 loop]

Step 5: If DATA[MID] = ITEM, then :

set LOC := MID

Else :

LOC := NULL

[End of If structure]

Step 6: Exit

e.g. Given DATA be the following sorted 13 element array :

11 22 30 33 40 44 55
60 66 77 80 88 99

Suppose ITEM = 40

Step 1: Initially BEG = 1 and END = 13

Hence MID = INT[(1 + 13)/2] = 7

and so DATA[MID] = DATA [7] = 55

Step 2: Since 40 < 55, END has its value changed by

END = MID - 1 = 7 - 1 = 6

Hence MID = INT [(1 + 6)/2] =3

and so DATA[MID] = DATA[3] = 30

Step 3: Since 40 > 30, BEG has its value changed by

BEG = MID + 1 = 3 + 1 = 4

Hence MID = INT [(4 + 6)/2] = 5

and so DATA[MID] = DATA[5] = 40

Found ITEM in location LOC = MID = 5

Q. 22 Explain the advantages of binary search


algorithm with a suitable example. State any two
disadvantages or limitations of binary search.
Asked in Board Exam (March 2007; Oct. 2003) Important
Ans : Advantages of binary search algorithm :

(1) Binary search algorithm is efficient as the search scope gets reduced to half the size of the
array, with each iteration.
(2) The number of comparisons required are approximately equal to log2, n which are less
than linear search.

(3) For example :


Given array data with 7-sorted elements :

11 22 30 33 40 44 55

Suppose ITEM = 40

Step I: Initially BEG = 1 and END =7

MID = (BEG + END) /2=(1+7)/2=4

DATA [MID] = DATA [4] = 33

Step II: Since 33 < 40, BEG is changed as BEG = MID+1=4+1=5

MID =(5+7)/2=6

DATA [MID] = DATA [6] = 44

Step III: Since 44 > 40, END has its value changed by END = MID - 1 = 6 - 1 = 5

MID =(5+5)/2 = 5

DATA [MID] = DATA [5] = 40

ITEM found at location 5 in array.

In above example, only two comparisons are required because at each iteration MID is
calculated, only one half is checked.
In the same example, for linear search, 5 comparison are required.

Disadvantages :
1) The given list must be sorted.
2) The access of list must be random means the middle element can be accessed.
3) At each iteration, middle entry calculation is required.

Q 23. Write difference between Linear search and


Binary search.
Ans : Linear Search

1. Linear search performs on unsorted list of elements as well as sorted list.

2. Compare the desired element with all elements in an array until the match is found.

3. Insertion of an element in an array can be performed very efficiently when array is not
ordered.

4. For large size of array, time required for this search is very large.

5. Time complexity is as follows :


worst case : N comparison
Best Case : 1 comparison

Binary search

1. For binary search, the elements in array are stored in alphabetically or numerically in some
manner.

2. Compare the value of midpoint with desire value. If the value is greater than midpoint
value.the first half is checked, otherwise second half checked until search is successful or
interval empty.

3. An insertion of a new element requires that many elements be physically moved to


preserved order.

4. For large size of array, comparatively time required is less.


5. Time complexity as follows :
worst case : log, N comparison
Best case : 1 comparison

Q. 24 What are pointer arrays ?


Asked in Board Exam (Oct. 2003,06; Mar. 2011, 21) Important
Ans:

i) An array is called pointer array, if each element of that array is a pointer.

ii) The variable is called as pointer variable, if it points to ariother variable i.e. it contains
memory address of other variable.

iii) Consider an organization, which divides its employee lisit into four groups, depending
certain conditions. Following figure shows the list of 4 groups. There are 15 employes groups
contain 2, 5, 4 and 4 employes respectively as

iv) If these groups are to be represented in memory, the most efficient way is to use 2 arrays.
The first is Employee array, which contains list of employees in all four groups sequentially,
while the second array is Group array, which is a pointer array, which contains the starting
address of each group in the Employee array, respectively.

v) It is shown in figure :
vi) Each element of Group array is a pointer, which holds the starting addresses of different
groups. Hence,it is called as pointer array.

Q. 25 What is a record ?
Asked in Board Exam (March-2011) Important
Ans :
i) A record is a collection of relative data items, each of which is called as field or attribute.

ii) Collection of records is known as files. Collection of data is frequently organized into a
hierarchy of fields, records and files.

iii) A record may contain non-homogeneous data i.e. data items of record need not to be of
same data type. In a record, natural ordering of elements is not possible. The elements in
record can be described by level number.

iv) e.g. An organization keeps records of its Employees. It contains following, data items-
Name, gender, Salary, Birthday, Address.

Name is group item consisting of First name, Middle name and Last name. Also, Birth date
and Address are group items,

The structure of this record is shown in figure below.

1. Employee
 Name
 First Name
 Middle Name
 Last Name
 Sex
 Salary
 Birth date
 Date
 Month
 year
 Address
 City
 Pincode
v) The number to the left of each variable indicates level number.
vi) Employee (30)
vii) This indicates a file of 30 records.

viii) To access first name of 3 rd employee, we should write Employee (3).Name.First name. In
this way, we can access variables in records.

Q. 26 What is a record ? How it differs from a linear


array ?
Asked in Board Exam (March 2002, 05, 07, 08,14,16; Oct.2010,11) Important
Ans : A record is a collection of fields or attributes i.e. relative data items.

Collection of data is frequently organized into hierarchy of fields i.e. records. A file is nothing
but collection of records.

Difference between records and linear arrays :

(i) A record is a collection of fields, while an array is list of homogeneous data elements.

(ii) A record may contain non-homogeneous data i.e. data elements may be of different data
types.
An array always contains homogeneous data.

(iii) In a record, netural ordering of elements is not possible. Array elements can be naturally
ordered.

(iv) Elements of record are referenced by level number, while those of array can be
referenced by an index set consisting of n consecutive numbers.
Q. 27 How records are represented in memory
using array ?
Asked in Board Exam (Oct. 2002, March 2004) Important
Ans: i) Consider a record, whose structure is given below.

1. Employee
 Name
 First Name
 Last Name
 Sex
 Address
 City
 Pincode
 Phone Number
ii) To represent this record in memory, linear arrays are used.

iii) One separate linear array is used for each elementary item of record such as First name,
Last name, gender, City, Pincode, Phone no.
Following figure shows representation of above record using parallel linear arrays.

iv) The records are stored in memory using parallel linear arrays, such that for an index K of
all records, First name [K], Last name [K], Gender [K], …. belong to the same record in a file.(ie.
Kth record in the file)

Q. 28 Show representation of records in memory


considering suitable example of three records and
three fields.
Asked in Board Exam (Mar. 2003,11,13; Oct.2011,13) Important
Ans :
1) Records contain non-homogeneous data, so it cannot be stored in array.

2) But in entire file of records, all data elements belonging to the same identifier will be of
same type. So a file may be stored in memory as collection of arrays.

3) One array for each of data item. All the arrays should be parallel.

4) For eg.
A student file consisting three records and three fields.

Name Address Phone

Lokesh 11, J.M. Road 5662000

Q. 29 What are linked lists ? Show a liked list with


suitable example having six nodes with
properly labelled diagram.
Asked in Board Exam (Mar. 2002,04,05,06,07,08,13,14,15; Oct. 2003,07) Important

OR

With suitable example, show labelled diagram for


link between two nodes having the information
part and next pointer field.
Ans :
i) A linked list is a linear collection of data elements, called nodes, where the linear order
maintained with the help of pointers.

ii) Linked list is also called as one-way list.

iii) Each node in the linked list is divided into two parts. First part is called as INFO per which
contains the information about the element or actual element and second par called as LINK
part, which is next pointers field i.e. it contains the address of next node the list.

(a) The above figure shows a linked list having six nodes.

(b) The left part of the node is the Info part, which contains information of the element, With
the right part is Link part, which is next pointers field ie. it points to next node.

(c) An arrow is drawn from Link part of one node to the next node to indicate link

(d) The address of the list is stored in Start or Name of the list.

(e) The Link part of last node is NULL pointer ie. it contains nothing.

(f) To trace the linked list, we Just equine the address ot Start or Name.

Q. 30 ) What are the advantages of linked lists over


linear arrays ?
Ans : Advantages of linked lists over arrays :

i) To store arrays in memory, require consecutive memory locations, while to store linked lists.
consecutive memorv locations are not required.

ii) Arrays can not be easily extended, while linked list can be easily extended.

ii) There is very complicated procedure to insert an element in an array. One can easily insert
an element in an linked list.

(iv) Similary, deletion of an element from array is very complicated, while deletion from
linkedlist is easy.
(v) Linked lists can be easily implemented and maintained in computer memory.

Q. 31 How linked lists are represented in memory ?


Asked in Board Exam (March 2003,12,14; Oct. 2006, 07,13) Important

OR

With suitable example show the representation of


linked list in memory.

Ans :
i) Linked lists can be represented in memory by using two arrays respectively known as INFO
and LINK, such that INFO[K] and LINK[K] contains information of element and next node
address respectively.

ii) The list also requires a variable ‘Name’ or ‘Start’, which contains address of first node.
Pointer field of last node denoted by NULL which indicates the end of list. e.g. Consider a
linked list given below :

iii) The linked list can be represented in memory as –


Above figure shows linked list. It indicates that the node of a list need not occupy adjacent
elements in the array INFO and LINK.

Q. 32 Explain insertion and deletion from linked


list with example.
Ans :

It is easier to insert an element into or delete an element from a linked list than arrays.

(i) Insertion into a linked list :


For insertion of an element into a linked list, the only requirement is that free memory space
is available to store a node.
e.g. Consider a linked list having four nodes as follows.

This list can be represented in memory as :


Now, to insert an element on second position of the list, the content of AVAIL are stored in
LINK part of first node (since, AVAIL points to the memory location where new node can be
inserted) and LINK part of the first node is transferred to LINK part of new node. Then the list
can be represented as follows.

This list can be represented in memory as :

(ii) Deletion from linked list :


To delete a node from a linked list, the LINK part of that node is given to the LINK part of the
previous node.
e.g. Consider a linked list as follows :
This list can be represented in memory as :

Now, to delete second node from the list, then just transfer the LINK part of second node to
the LINK part of the first node.

This list can be represented in memory as


Q. 33 There is a list of 5 hospital patients and their
corresponding room numbers. Fill the values of N
start and N link so that they form an alphabetical
link of patient names. Also fill the values of R start
and R link so that they form an ordering of room
numbers.

Q. 34 The following figure pictures a linked list in


memory.
(i) Find the sequence of characters in the list.

(ii) Suppose F and then C are deleted from the list. After that G is inserted at
the beginning of the list. Find the final structure of the list.

(iii) Suppose G is inserted at the beginning of the list and then F after that C
is deleted from the list. Find the final structure of the list.

Ans:
i) Linear order of characters

START = 4 so INFO [4] = C is the first character


LINK [4] = 7 so INFO [7] = E is the second character
LINK [7] = 1 so INFO [1] = A is the third character
..
..
..
LINK [5] = 0, the NULL value so the list is ended.
C E A B F D is the character string. Hence sequence is C, E, A, B, F, D.

Q. 35 Let LIST be a linked list in memory. Write an


algorithm for traversing the linked list following
purposes :
(i) Find the number of times given ITEM occurs in the list.
(ii) Find number of non-zero elements in the list.
(iii) Add given value K to each element of the list.

Ans : Algorithm : Traversing a linked list

1. Set Ptr = START

2. Repeat While Ptr ≠ NULL :

Apply process to INFO[Ptr]

Set ptr := LINK [ptr]

[End of loop]

3. Exit

(i) 1. Set Ptr = START

2. Set N = 0

3. Repeat steps 4 and 5 While Ptr ≠ NULL :

4. If INFO [ptr] = ITEM, Then :

set N = N + 1

[End of If structure]
5. Set Ptr = LINK [ptr]

[End of step 3 loop]

6. Write : N

7.Exit

(ii) 1. Set Ptr := START

2. Set N := 0

3. Repeat steps 4 and 5 While Ptr # NULL :

4. If INFO [Ptr] ≠ 0, Then :

Set N:=N+1

[End of If structure]

5. Set Ptr := LINK [Ptr]

[End of step 3 loop]

6. Write : N

7. Exit
(iii) 1. Set Ptr := START

2. Repeat While Ptr ≠ NULL :

Set INFO [Ptr] := INFO [Ptr] + K

Set Ptr := LINK [Ptr]

[End of loop]

3. Exit

Q. 36 Explain Stack and Queue with suitable


examples.
OR

Asked in Board Exam (Mar.2013) (Oct. 2005, 2010) Important

Q.36 Explain LIFO and FIFO Systems with suitable


examples.
Ans. : LIFO System :

(i) LIFO system is last-in-first-out system. In this type of system, the element which is inserted
at last, will be deleted first.

(ii) Stack is an example of LIFO system. It is a linear system in which insertion and deletion
takes place only at one end i.e. top of the list.

(iii) The insertion operation is referred to as push and deletion operation as pop.

e.g. consider a stack of dishes. If we want to add a new dish to this stack then it is added at the
top of stack also deletion takes place from the top.

FIFO System :

(i) A FIFO system is first-in-first-out system. In this type of system, the element which is
inserted first in the list will also be deleted first.
(ii) Queue is an example of FIFO system, A queue is a linear list, in which insertion takes
place only at one end of the list known as ‘rear’ of the list and deletion takes place at the other
end, called as ‘front’ of the list.

e.g. A queue for tickets in a cinema hall.

Tree

Q. 37 What is a tree ? What do you mean by root,


leaf, siblings and child about tree.
Asked in Board Exam (Oct. 2006, 2010) Important
Ans : Tree :
Tree is a non-linear hierarchical data structure which consists of finite set of one Or more
nodes (i.e. collected data items) such that :

a) There is specially designated node called the root.

b) The remaining nodes are partitioned into n² 0 finite disjoint sets


T1, T2…… Tn where each of these set is tree.
T1, T2, …., In are called ‘subtrees’ of the root.
For e.g. figure shows tree which has 11 nodes, each item of data being a single letter.

Root :
A node which has no parent. Generally first node is called as ‘root node’. In figure, a the node
A is the root of the tree.

Leaf :
The node which has no child or children. Such nodes have degree zero. In figure a D, I, F, J, K
are the leaf nodes. Also called as terminal node.

Child :
The nodes which are reachable from a node, say u, through a single edge are called the
children of u. e.g In figure a, the children of node C are F, G, and H.
Sibling :
Children of the same parent are said to be siblings. e.g. The nodes D and E are both children
of node B. So D and E are siblings.

Q. 38 Explain the following terms :


Ans. : 1. Level of tree:
Each node in a tree is assigned a level number. Generally, the level number of root ‘R’ of the
tree is zero and every other node is assigned to level number which is one more than the level
number of its parent.

It is distance from the root

2. Depth / Height :
Depth of the tree as maximum level of any node in a tree. If root is level 0 than
depth or height of tree is equal to 1+ largest level number.
e.g. Depth of above tree is 3.

3. Degree :
The number of subtrees of a node is called degree of a node.
The degree of a tree is the maximum degree of the node in tree.
e.g. the degree of each node in figure is as

The tree has degree 3.

Q. 39 What is a binary tree ?


Asked in Board Exam (March 2002,04,05,14,15; Oct. 2004,06,11,12,13) Important
Ans. : Binary tree is a finite set of elements called nodes such that is
(1) It may be empty or

(2) It is partitioned into three disjoint subsets :

(a) there is a single distinguished element called the root of tree.

(b) other two subsets are themselves binary tree called left subtree and right subtree of the
original tree.

A left and right subtree can be empty.


In binary tree, there is no node with degree greater than two.
e.g.

Q. 40 What is a binary tree ? With a suitable


example, explain the terminology describing
family relationship between the elements of a
binary tree.
Asked in Board Exam (March 2005, 2011) Important
Ans :

Binary tree : Please refer Q. No. 39.


Basic terminology : Consider the example :

The binary tree contains 8 nodes (A to H). Root A is at the top of tree.

(1) Left successor : B is left successor of node A.

(2) Right successor : C is right successor of node A.

(3) Left subtree : Left subtree consists of nodes B, D and E.

(4) Right subtree : Right subtree consists of nodes C, F, G and H.


(5) Terminal node : The node with no successors are is called terminal node D. E, H and G are
terminal nodes.

(6) Binary tree T1 and T2 are similar if they have same structure.
Any node N ina binary tree T has either 0, 1 or 2 successors.

Q. 41 What is a binary tree ? With a suitable


example show the relationship between to,
numbers of nodes and depth of a tree.
Asked in Board Exam (Oct. 2003,15, March 2006) Important
Ans. : Binary tree : Please refer Q. No. 39.

(i) Relationship between total number of nodes and depth of a tree :

Depth of a tree means maximum level of any node in a tree. Maximum number of node or
binary tree with depth n are 2n – 1.

For example :
(ii) Consider the following tree with depth 3.
So with depth 3, the total number of nodes in a given tree is

2n – 1 = 23 -1
= 8-1
=7
The tree with depth n having 2n – 1 number of total nodes.
Q. 42 Define the following :
Ans :

1. Complete Binary Tree : If all leaf nodes of a binary tree have same level number and every
non-leaf node has non-empty left and right subtrees then the tree is called as complete binary
tree. All nodes at the last level appears as far left as possible.

2. Extended binary tree or 2-tree:

Asked in Board Exam (Mar.2015) Important


A binary tree T is said to be a 2-tree or an extended binary tree if each node N has either 0 or
2 children. The nodes with 2 children are called internal node and the nodes with 0 children
are called external nodes.

3. Binary Search Tree :


It is a binary tree in which each node N of tree has the property that the value at N is greater
than every node value in the left subtree of N and is less than or equal to every node value in
the right subtree of N.

Q. 43 How binary trees are represented in memory


?
Asked in Board Exam (Mar.2015) (March 2003, 2009) Important

With suitable example and labelled diagram, show


the representation of binary tree in memory.
Ans : A binary tree T can be represented in memory by two types of representation :
(i) Linked representation
(ii) Sequential representation.

(i) Linked representation :

Asked in Board Exam (Oct. 2008,15) Important

Linked representation uses three parallel arrays INFO and, LEFT and RIGHT and a pointer
variable ROOT such that for an index K, INFO [K] contains actual element, LEFT [K] contains
address of the Jeft child and RIGHT [K] contains address of right child.

e.g. Consider a binary tree as below :


The ROOT stores address of first node of tree T.

AVAL stores address of first null node. To insert another node to tree T, it is inserted memory
location pointed by AVAIL.

Note : In above example, to insert an element K, then it will be inserted at INFO [10]. After
insertion LEFT [10] and RIGHT [10] will contain zero (null pointer) and AVAIL will contain 8 i.e.
next element is to be inserted at 8.

(ii) Sequential representation :


For sequential representation, only one linear array is used. This array is generally known as
TREE such that :

(a) The root R of the tree is stored in TREE [1].

(b) If a node N of tree stored in TREE [K], then, its left successor is stored in TREE [2*K] and
right successor is stored in TREE [(2*K) +1]
e.g. Consider a binary tree as follows :

This tree can be represented in memory as,


In general, the sequential representation of a tree with depth d will require an array with
approximately 2d+1 elements

Q. 44 Each store in a chain sends in a weekly


record of its sales according to the following
structure 01 Store, 02 Hardware, 02 Clothing, 03
Men, 03 Women, 03 Children 04 Boys, 04 Girls, 02
Drugs, 03 Prescription, 03 Nonprescription, 02
Stationary.
1. Draw the appropriate tree diagram.
2. How many elementary items are there ?
3. How many group items.are there ?
Ans : 1. The tree diagram is as follows :
Elementary items are those all nodes which have no children under given group. The above
tree has 8 elementary items as :

Hardware, Men, Women, Boys, Girls, Prescription, Nonprescription, Stationary.

Group items are those all nodes having children excluding root.

The above tree has 3 group items as –


Clothing
Children
Drugs.

Q 45. Explain the following data structures with


suitable diagram.
(a) Linear array (b) Linked list (c) Tree
Asked in Board Exam (March 2003,08,11,12,15; Oct. 2006) Important

Ans. : (a) Linear array :

A linear array is the data structure which consists of finite ordered set of homogeneous data
elements such that :

(i) The elements of the array are referenced respectively by an index set consisting or
consecutive numbers.

(ii) The elements of the array are stored respectively in successive memory locations.

(ii) The number n of the elements is called length of size or array.


For e.g. let DATA be 5 elements linear array as follows :

(b) Linked list

(i) A linked list is a linear collection of data elements called nodes where the linear order’s
maintained with the help of pointers.

(ii) Each node in the linked list is divided into two parts. First part is called as INFO part which
contains the information about the element or actual element and second part is called as
LINK part which is next pointer field i.e, it contains the address of next node in the list.

(iii)

(c) Tree:

Asked in Board Exam (Oct. 2006) Important

Tree is a non-linear hierarchical data structure which consists of finite set of one or more
nodes (i.e. collected data items such that :

(i) There is specially designated node called the root.


(ii) The remaining nodes are partitioned into n Z 0 finite disjoint sets T1, T2, …., In where each
of these set is tree.

T1, T2, ……. , In are called ‘subtree’ of the root.


Q. 51 Select the correct alternative and rewrite the
following statements
1. Finding location of given element is called as ___________ (March 2005)
(i) Traversing
(ii) Insertion
(iii) Searching
(iv) None of the above
Ans. : (iii) Searching

2. Data items that are divided into subitems are called as ___________
(i) Group items
(ii) Elementary items
(iii) Nodes
(iv) Arrays
Ans. : (i) Group items

3. In LINKED LIST, Link field contains ___________


(1) Value of next node
(ii) Address of next node
(iti) Value of previous node
(iv) None of these
Ans. : (ii) Address of next node

4. A record is a collection of ___________


(i) Files
(ii) Arrays
(iii) Fields
(iv) Maps
Ans. : (iii) Fields

5. The time required to execute bubble sort algorithm having ‘n’ input items is directly
proportional to ___________
(i) n²
(ii) n
(iii) Log2n
(iv) Logen²
Ans.: (i) n²

6. Maximum number of nodes of symmetric binary tree with depth 5 are___________ (March
2002)
(i) 5
(ii) 25
(iii) 31
(iv) 32
Ans. : (iii) 31

8. Accessing each element in an array only once is called ___________ (Oct. 2002, March 2003)
(i) Searching
(ii) Inserting
(iii) Deleting
(iv) Traversing
Ans. : (iv) Traversing

9. The elements of record are ___________ (Oct. 2003, March 2009)


(i) Homogeneous
(ii) Similar
(iii) Non-homogeneous
(iv) Identical
Ans. : (iii) Non-homogeneous

10. The most efficient search algorithm is___________ (March 2004)


(i) Binary search
(ii) Reverse search
(iii) Linear search
(iv) Pointer search
Ans: (i) Binary search

11. The number of comparisons required for bubble sorting of an array of n elements
is_________(March 2004)
(i) n(n-1)/2
(ii)n/2
(iii) log2n
(iv) logign
Ans:(i) n(n – 1)/2

12. Finding the location of record with a given key value is known as ____________ (March 05,
Oct.11)
(i) Traversing
(ii) Searching
(iii) Sorting
(iv) Inserting
Ans : (ii) Searching

13. Maximum number of nodes ina symmetric binary tree with depth four are
________________ (March 2006)
(i) 4
(ii) 15
(iii) 16
(iv) 5
Ans: (ii) 15

14. In___________data structure, an element may be inserted or deleted only at one end called
Top.
(i) Queue
(ii) Array
(iii) Stack
(iv) Tree
Ans: (iii) Stack

15. Maximum number of nodes of symmetric binary tree with depth of 6 is ____________
(i) 64
(ii) 6
(iii) 63
(iv) 36
Ans: (iii) 63

16. ________________ is the only non-linear data structure from the following list. (March 2007)
(i) Array
(ii) Stack
(iii) Tree
(iv) Linked List
Ans:(iii) Tree

17. __________ is the operation of rearranging the elements of an array either in increasing and
decreasing order. (Oct 2007)
(i) Sorting
(ii) Searching
(iii) DMS
(iv) DBMS
Ans: (i) Sorting

18. The complete binary tree (Tn) has n= 15 nodes then its depth (dn) is ____________
(i) 2
(ii) 3
(iii) 4
(iv) 5
Ans: (iii)

29. ________________ data structure dove 29. Not require contiguous memory
allocation. (March 2015)
(i) Array
(ii) String
(ii) Pointer array
(iv) Linked list
Ans: (iv) Linked list

30. Tree is a _______________ collection of Nodes. (Oct 2015)


(1) Hierarchical
(ii) Linear
(iii) Relational
(iv) Graphical
Ans: (i) Hierarchical

31.If a complete binary tree (Tn) has n = 1000 nodes, then its depth (Dn) is ____________ (July
2016)
(i) 10
(ii) 20
(iii) 50
(iv) 109
Ans: (i) 10

32. _______________ is the only non-linear data structure from the following list. (July 2017)
(i) Array
(ii) Stack
(iii) Tree
(iv) Linked List
Ans: (iii) Tree

33.If lower bound = 0 and upper bound = 15, then midterm is _______________ in binary, search
method. (July 2018)
(i) 6
(ii) 7
(iii) 8
(iv) 9
Ans.: (iii) 8

34. _________________ is very useful in situation when data is to be stored and retrieved in
reverse order. (March 2019)
(i) Stack
(ii) Queue
(iii) Linked List
(iv) Tree
Ans: (i) Stack

35.Record contains ________________ data. (July 2019)


(i) Homogenous
(ii) Non-homogenous
(iii) Same
(iv) None of these
Ans: (ii) Non-homogeneous

36. ____________ is collection of fields. (March 2020)


(1) File
(ii) Record
(iii) Array
(iv) Queue
Ans: (ii) Record

OPERATING SYSTEM MCQ


1.Operating system is_______

1. Hardware
2. Software
3. Input Device
4. Output Device
Ans: Software

2. ____________is service in operating system.

1) Information management
2) Process
3) G.U.I.
4) None of these
Ans.: (1) Information management

3. Windows NT is __________ operating system.

1) Single user multitasking


2) Multiuser multitasking
3) Time sharing
4) None of these
Ans. : (2) Multiuser multitasking

4. Linux is a __________ software

1) public domain
2) free
3) paid
4) private
Ans.: (2) free

5. Windows 98 is ____________ operating system


1) Single user multitasking
2) Multiuser
3) Time sharing
4) Multithreading
Ans.: (1) single user multitasking

6. The time required for read-write head to move to the correct track is (March 2009)

1) Seek time
2) Rotational delay
3) Latency time
4) None of these
Ans. (1) Seek time

7. Termination of a process is done by ___________

1) Memory management
2) Process management
3) Device driver
4) Information management
Ans. : (2) Process management

8. The time lost in turning the attention of processor from one process to other is called
as__________

1) Circuit switching
2) Band width
3) Context switching
4) None of these
Ans.: (3) Context switching

9.__________is a function of memory management.

1) Creation of file
2) Halting process
3) Paging
4) None of these
Ans.: (3) Paging

10. If the page size for 2 MB memory is 2 kB, then the number of higher order bits on address
bus, used to denote page number is___________

1) 11
2) 10
3) 9
4) 8
Ans:(2) 10

11. Wastage of memory space within the partition is called as _____________

1) Internal fragmentation
2) External fragmentation
3) Compaction
4) None of these
Ans. (1) Internal fragmentation

12. If a page is modified after it is loaded in main memory, then it is called as___________

1) Page fault
2) Dirty page
3) Paging
4) Locality of reference
Ans.: (2) Dirty page

13. Pages are physical in nature, while segments are___________

1) logical
2) Virtual
3) Either physical or logical
4) Either virtual or physical
Ans.: (1) logical

14. Following is not a process state____________

1) ready
2) blocked
3) resumed
4) running
Ans. (3) resumed

15. Windows NT is __________ operating system.

1) Multiuser
2) Multitasking
3) Multithreading
4) All of the above
Ans.: (4) All of the above

16. ________ is not an operating system.

1) UNIX
2) LINUX
3) MS-DOS
4) C++
Ans.: (4) C++

17. _______spread more rapidly but causes less damage to computer networks.

1) Virus
2) Worms
3) Bombs
4) None of these
Ans. (2) Worms

18. ____________are the operating system programs.

1) Application program
2) User program
3) Process management program
4) Antivirus program
Ans. (3) Process management program

19. ___________ is given to each process so that a process does not use the CUP indefinitely.
1) Context Switching
2) Time Slice
3) Token Time
4) Purchased Priority
Ans. (2) Time Slice

20. In Information Management _____________ service is provided by operating system. (Oct.


2006)

(i) Change the priority of process


(ii) To allocate a chunk of memory to process
(ii) Open a file (for read, write or both)
(iv) Wait for a child process to terminate
Ans.: (iii) Open a file (for read, write or both)

You might also like