DataStructure LMN PDF
DataStructure LMN PDF
DataStructure LMN PDF
An array is collection of items stored at continuous memory locations. The idea is to declare
multiple items of same type together.
Array declaration:
Formulas:
Length of Array = UB - LB + 1
Given the address of first element, address of any other element is calculated using the
formula:-
Column major order: Elements are stored column by column, i.e. all elements of first
column are stored, and then all elements of second column stored and so on.
Loc(arr[i][j]) = base(arr) + w (m *j + i)
Row major order: Elements are stored row by row, i.e. all elements of first row are
stored, and then all elements of second row stored and so on.
Stack is a linear data structure which follows a particular order in which the operations are
performed. The order may be LIFO (Last in First Out) or FILO (First in Last Out).
Basic operations
1. Push: Adds an item in the stack. If the stack is full, then it is said to be an Overflow
condition. (Top=Top+1).
2. Pop: Removes an item from the stack. The items are popped in the reversed order in
which they are pushed. If the stack is empty, then it is said to be an Underflow
condition.
(Top=Top-1).
3. Peek: Get the topmost item.
1. Infix notation: “X + Y” Operators are written in-between their operands. This is the
usual way we write expressions. An expression such as
A * (B + C) / D
A B C + * D/
/ * A + B C D
Tower of Hanoi
Tower of Hanoi is a mathematical puzzle where we have three rods and n disks. The
objective of the puzzle is to move the entire stack to another rod, obeying the following
simple rules:
Queue is a linear structure which follows a particular order in which the operations are
performed. The order is First in First out (FIFO). A good example of queue is any queue of
consumers for a resource where the consumer that came first is served first.
Operations on Queue
1. Enqueue: Adds an item to the queue. If the queue is full, then it is said to be an
Overflow condition.
2. Dequeue: Removes an item from the queue. The items are popped in the same order in
which they are pushed. If the queue is empty, then it is said to be an Underflow
condition.
3. Front: Get the front item from queue.
4. Rear: Get the last item from queue.
1. Dynamic size
2. Ease of insertion/deletion
Drawbacks
1. Data
2. Pointer to the next node In C, we can represent a node using structures. Below is an
example of a linked list node with an integer data.
Long Questions
1. Differentiate List and Array.
2. Define Algorithm. Explain Key features of and algorithm.
3. Write a short note of Doubly Linked List.
4. Write a short note on Circular Linked List.
Algorithm
1. Write and algorithm to compare two strings without using library function
‘strcmp’.
2. Write and explain POP and PUSH operation algorithm of stack.
3. Write an algorithm to insert an element in Queue.
4. Write an algorithm to insert new node at the starting of singly linked list.
5. Write an algorithm of Bubble sort, Merge Sort, Quick Sort, Insertion Sort, and
Selection sort.
6. Write an algorithm for inserting and deleting a node from circular queue.
7. Write an algorithm for connate two strings.
8. Write an algorithm for compare two strings.
9. Write an algorithm to insert a node in singly linked list.
10. Write an algorithm to delete a node from beginning in doubly linked list.
11. Write an algorithm to find length of given string without using library function.
12. Write an algorithm for Binary search.
13. Write an algorithm to search a node in singly linked list.
14. Write an algorithm to count the number of nodes in singly linked list.
15. Write an algorithm for post order tree traversal method.
16. Write an algorithm for in-order tree traversal method.
Short Questions
1. Define Time and Space complexity.
2. List out applications of data structure and explain any one.
3. Explain puts() and putchar() with an example.