data structures class 12

data structures

data structures

data structures

what is data structures:-

a data structures is 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, behaviour and properties.
Simple Data Structure: These data structures are normally built from primitive data types like integers,
floats, characters. For example arrays and structure.

what is Simple Data Structure:

These data structures are normally built from primitive data types like integers,
floats, characters. For example arrays and structure.

what is Compound Data Structure:-

simple data structures can be combined in various ways to form more complex structure called compound structures. Linked Lists, Stack, Queues and Trees are examples of
compound data structure.

what is Sorting:-

The process of arranging the array elements in increasing ascending or decreasing descending order is
known as sorting. There are several sorting techniques are available e.g. selection sort, insertion sort,
bubble sort, quick sort, heap short etc. But in CBSE syllabus only selection sort, insertion sort, bubble sort
are specified.

difference between data types and data structure

data type                                              data structure

1.data types are predefined              1.created by the user
  by the compiler.
2.values and operations                     2.values and operations are
are defined by compiler.                         managed by the user.
3.example:- int, float, string                 3.example:-queue, stack, tree
list and tuple.                                            and linked list.

types of  data structure:-

data structures class 12

Q 1. binary search by function (ascending list).

ans. def   binary_search(alist,key):

                 start=0
                 end=len(alist)
                  while start<=end:
                           mid=(start+end)//2
                        if alist[mid]==key:
                                  return 1
                        if alist[mid]>key:
                                  end=mid-1
                        elif alist[mid]<key:
                                  start=mid+1
                  if start>end:
                        return  0
a=[2,4,7,9,11,14,16,18,34]
key=int(input(“the number to search for:”))
index=binary_search(a,k)
if index==0:
           print(“not found”)
else:
           print(“found”)
output
the number to search for:2
found

Q 2. insertion a list using bisect module.

ans. import bisect as bt
        def   inserting(a,k):
                  a=bt.insort(a,k)
                    return a

Q 3. find output.

ans.  a=[2,4,5,5,5,8]
          k=5
           print(bt.bisect(a,k))
         output
         4             [search and return last index number where number is found]

stack

1. how to insert stack and delete stack.        [push means insert and pop means delete]

st=[]
top=-1
def   push(st,k):
         global top
        top=top+1
        st.append(k)
************************************************
def    pop(st):
          global top
           if top==-1
                    print(“stack under flow”)
                            return -1
            k=st[top]
           top=top-1
           st.remove(k)
           return k
******************************************

application of stack

1.infix to post fix conversion
2. post-fix evaluation

incoming operator                                operation

1.higher priority                                      1.push
2.low/same priority                                2.pop
3.   (                                                        3.push
4.    )                                                       4.pop until first “(“
5.empty                                                  5. push

Q 4. convert the following expression into post-fix.
Infix Expression:- A+ (B*C-(D/E^F)*G)*H  [where ^ is an exponential operator]

 ans.
data structures class 12

Q 5. evaluate the post-fix evaluation.
post-fix expression:-  4,5,6,*,+

ans.
data structures class 12

Queue

1.how to insert in queue and delete queue.

q=[]
f=0
r=-1
limit=5
def   insert(q,k):
         global r
         if r==limit-1:
                    print(“queue is full”)
         else:
               r=r+1
             q.append(k)
*****************************
def   delete(q):
          group f
          if f==r+1:
               print(“queue is empty”)
                 return -1
          k=q[f]
          f=f+1
          return k
   ***************************

data structures important questions