Data Structure
Data Structure
Data Structure
INTRODUCTION
We know that computers store and process data with an extra ordinary speed and
accuracy. So, it is highly essential that the data is stored efficiently and can be
accessed fast. Also, the processing of data should happen in the smallest possible
time but without losing the accuracy.
Data structures deal with how the data is organized and held in the memory when a program
processes it.
• Data structures are fundamental concepts of computer science which helps in writing
efficient programs in any language.
• A data structure is a named group of data of different data types which is stored in a specific
way and can be processed as a single unit.
• A data structure has well-defined operations, behavior and properties.
• A data type defines a set of values along with well-defined operations stating its input-output
behavior.
• A data structure is a physical implementation that clearly defines a way of storing, accessing,
manipulating data stored in a data structure.
For example, List as a data type which can store heterogeneous data type of elements,
but when implemented as data structure its behavior is clearly prescribed (searching,
sorting etc.)
List
Stack
A stack is a container of objects that are inserted and removed according to the Last-InFirst-
Out (LIFO) concept.
Linear List
• A linear data structure is that those elements form a
sequence.
• When elements of linear structure are homogeneous and
are represented in memory by means of sequential memory
locations, these linear structures are called arrays. Linear
List size: Length=UB-LB+1
Stack
Stack is a linear/sequence structure in which insertion and deletion can take place only at
one end, i.e., stack’s top. Because of this, stack is called LIFO (Last in First out) data
structure. For example, a pile of books, a stack of coins where you can remove only the
top book or the coin placed at the top.
2.The compilers use stacks to store the previous state of a program when a function is
called during recursion.
2. Backtracking is a form of recursion. But it involves choosing only one option out of
possibilities. Used in solving Puzzle Sudoku.
3. Undo mechanism in Text editors by keeping all the text changes in a stack.
1. Choose the correct output for the following stack operation(* top position)
(a) 8 5 2 5
1* (b) 8 5
5 2 1*
(c) 2 5 5 1*
(d) 5 2 1*
(e) Which list method can be used to perform Push operation in a stack implemented by list?
(f) append()
(g) extend()
(h) push()
(i) insert()
(a) overflow
(b) underflow
(c) 10 20 30 40 50*
(d) 10 20 40 50*
5. Based on the below given code, Write answer to the following questions i to v
(i) Identify the suitable code for statement 1?
a) colour.insert(len(colour),n)
b) colour.append(len(colour),n)
c) colour.append()
d) colour.extend()
a) push(colour,c[i])
b) push(colour)
c) push(c[i])
d) push(colour,i)
(iii) Identify the suitable code for statement 3?
a) colour==[]:
b) colour.isEmpty():
c) len(colour)=0:
d) None of the above
a) colour.pop(1)
b) colour.pop()
c) del colour[1]
d) colour.delete(1)
12. Write a program to implement a stack for the students(studentno, name). Just implement
Push.
13. Write a program to implement a stack for the students(studentno, name). Just implement Pop
and display.
14. If
L=["Python", "is", "a", ["modern", "programming"], "language", "that", "we", "use"] ,
then find the output:
(a) L[0][0]
(b) L[3][0][2]
(c) L[3:4][0]
(d) L[3:4][0][1]
(e) L[3:4][0][1][3]
(f) L[0:9][0]
(g) L[0:9][0][3]
(h) L[3:4][1]
ANSWER KEY
I. MCQ/ Very Short Answer Type Questions(1-mark)
1. (d) 5 2 1*
2. (a) append()
3. (a) pop() 4. (a) overflow
5.
(i). a colour.insert(len(colour),n)
(ii). a push(colour,c[i]) (iii).a colour==[]
(iv). b colour.pop()
(v). b pop(colour)
6. Data Structure means organization of data. A data structure has well defined operations or
behaviour.
7. STACK
8. Yes
9. Lists
10. Graphs
11 PUSH
12 pop
13. len()
14. 0
6.#stack operation-Pop
9.
10.
11.
12
13