0% found this document useful (0 votes)
32 views26 pages

Dsa Merged

JSS DSA file

Uploaded by

meritation99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
32 views26 pages

Dsa Merged

JSS DSA file

Uploaded by

meritation99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 26
JSS MAHAVIDYAPEETHA LABORATORY MANUAL Subject Name: Data Structure Lab Subject Code: BCS 351 COURSE: B.Tech. SEMESTER: IIT. SEM. Name Roll No. Section-Batch Department of Computer Science and Engineering JSS ACADEMY OF TECHNICAL EDUCATION C-20/1, SECTOR-62, NOIDA JSS Academy of Technical Education— NOIDA Department of Computer Science and Engineering VISION OF THE INSTITUTE ISS Academy of Technical Education, Noida aims to become an Institution of excellence in imparting quality Outcome Based Education that empowers the young generation with Knowledge, Skills, Research, Aptitude and Ethical values to solve Contemporary Challenging Problems. MISSION OF THE INSTITUTE ‘© Develop a platform for achieving globally acceptable level of intellectual acumen and technological competence. ‘© Create an inspiring anibience'that raises the motivation level for conducting quality research, * Provide an environment for acquiring ethical values and positive attitude. VISION OF THE DEPARTMENT To spark the imagination of the Computer Science Engineers with values, skills and éreativity to solve the real world problems. MISSION OF THE DEPARTMENT ‘+ Tojinculeate creative thinking and problenrsolving skills through effective teaching, learning and research. ‘+ To empower professionals with core competency in the field of Computer Science and Engineering. ‘© To foster independent and lifelong learning with ethical and social responsibilities. PROGRAM EDUCATIONAL OUTCOMES (PEOs) PEO1: To apply computational skills necessary to analyze, formulate and solve engineering problems. PEO2: To establish as entrepreneurs, and work in interdiseiplinary research and development organizations as an individual or in a team. PEOS: To inculcate ethical values and leadership qualities in students to have a successful career. PEO4: To develop analytical thinking that helps them to comprehend and solve real-world problems and inherit the attitude of lifelong learning for pursuing higher education. Data Structure Lab (BCS 351) Manual (CS, III Sem) Page |2 JSS Academy of Technical Education— NOIDA. Department of Computer Science and Engineering PROGRAM OUTCOMES (POs) Engineering Graduates will be able to: Engineering knowledge: Apply the knowledge of mathematic: nce, engineering fundamentals, and an engineering specialization to the solution of complex engineering problems. Problem analysis: Identify, formulate, review research literature, and analyze complex engineering problems reaching'substantiated conclusions using first principles of mathematics, natural sciences, and engineering sciences. Design/development of solutions: Design"solitions for complex: engineeting problems and design system componénis or” processes “that-meet the specified needs with appropriate consideration for the public health and safety, and thé cultural, societal, and environmental considerations. Conduct inyestigations of complex problems: Use research-based knowledge and research methods inéhiding design of experiments, analysis and interpretation of data, and synthesis of the information to provide valid conclusions. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering and IT tools inéluding prediction and modeling 6 coniplex engineering activities with an understanding of the limitations. ‘The engineer and society: Apply-reasoning informed by the contextual knowledge to assess societal, health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional engineering practice. Environment and sustainability: Understand the-impact of the professional engineering solutions in societal'and environmental contexts, and demonstrate the knowledge of, and need for sustainable development: Ethies: Apply ethical principles and commit to”professional ethics and responsibilities and norms of the engineering practice. Individual and team work: Function effectively as an individual, and as a member or leader in diverse teams, and in multidisciplinary settings. Communication: Communicate effectively on complex engineering activities with the engineering community and with society at large, such as, being able to comprehend and Data Structure Lab (BCS 351) Manual (CS, III Sem) Page [3 JSS Academy of Technical Education— NOIDA. Department of Computer Science and Engineering write effective reports and design documentation, make effective presentations, and give and receive clear instructions. Project management and finance: Demonstrate knowledge and understanding of the engineering and management principles and apply these to one’s own work, as a member and leader in a team, to manage projects and in multidisciplinary environments. Life-long learning: Recognize the need for, and have the preparation and ability to engage in independent and life-long learning in the broadest context of technological change. Data Structure Lab (BCS 351) Manual (CS, III Sem) Page |4 JSS Academy of Technical Education— NOIDA. Department of Computer Science and Engineering PROGRAM SPECIFIC OUTCOMES (PSOs) PSO1: Acquiring in-depth knowledge of theoretical foundations and issues in Computer Science to induce learning abilities for developing computational skills. PSO2: Ability to analyse, design, develop, test and manage complex software system and applications using advanced tools and techniques. Data Structure Lab (BCS 351) Manual ( Page |5 JSS Academy of Technical Education— NOIDA Department of Computer Science and Engineering COURSE OUTCOMES (COs) ‘Students be capable to identity the appropriate data structure for given problem 209.1 ‘Students will be able to understand various data structure such as stacks, queues, trees, igraphs, cte. to solve various computing problems €209.2 ‘Students will be able to implement various kinds of searching and sorting techniques, and €209.3 now when to choose which techniques. Students will be able to learn implementation different operations on BST. 209.4 CO-PO MAPPING POI | PO2] PO3 | PO4 | POS | POG | PO7| POS | POY | POI0 | POIT | POI2 Fr a 1 0 2 €209.1 | Da) | eee lead, Oe | T T 0 z €209.2 { 2 sa 3 | 26) sto | Oa ela T 0 2 209.3 7 b=] aay |? | 2 | hl OL T 0 a €209.4 | 2.25 | 275 | 2.75 | 1.75 | 3.00 | 0.00] 0.00 [1.00 [00 [1.00 | 0.00] 2.00 C209 CO-PSO MAPPING: PSO1| PSO2 2 2 209.2 2 2 C2093, 2 2 209.4 2.00 | 2.00 209 Data Structure Lab (BCS 351) Manual (CS, III Sem) Page | 6 Program 1: Write a Program to implement Bubble Sort. include using namespace std; void bubbleSort(int arr{], int n) { for(inti=O;1 arth +14 swap(arri)}, arti + 1D; swapped = true;} if (swapped) break:} ) void printArray(int arr(), int m){ for(int i= 0;1-<1n; 144) cout << arti} <<" cout << endl; , int maing){ int arr{)= (184, 134, 225, 212,322, 311, 390}; int n= sizeoffar)/ sizeof(arr[0); cout << "Original array: printArray(arr, n); bubbleSort(arr, n}; cout << "Sorted array printArray(arr, n); return 0; OUTPUT: Original array: 164 134 225 212322 311 390 Sorted array: 134 164 212 225 311 322 390 Program 2 : Write a Program to implement Selection Sort. include using namespace std; void selectionSortint are), int n){ for(int i= 0:5 using namespace std; void insertionSort(int arr(}, int n){ for(int while (j >= 0 && arr{j]> key) { arr{j +11 aril; is » arr) +1]= key; int main0{ int are{]= (164, 134, 225, 212,322, 311, 390); int n= sizeof{art) / sizeot{arr[o)); InsertionSort(arr, n)s return 0; OUTPUT: Original array: 164 134 225 212.922 311.390 Sorted array: 134 164 212 225 311 322390 Program 7: Write a Program to implement Linear Search. #include using namespace std; int linearSearch(int arr(], int n, int target) { for (int i= 051 <5 i+#){ if (arrfi] == target) return i; y return 1; ) int main0{ int are[] = (164, 134, 225, 212,322, 311, 390}; Int n= sizeot{art) / sizeot{arr[o)); Int target =212; int result = tinearSearch(arr, n, target); if (result cout << "Found at index: "<< result << endl; else cout << "Not found” << endl; return 0; OUTPUT: Found at index: 3 Program 8: Write a Program to implement Binary Search. include using namespace std; int binarySearch(int art[}, int n, int target) { int toft sright=n 15 while (left <= right) { Int mid = left + (right - Left) /2; if (arr{midy carget) return mid; else if (arrimid] > target; int result = binarySearch(arr, n, target); if (result !=-1) cout << "Found at index: "<< result << endl; alse cout << "Not found” << endl; return 0; ) ouTPUT: Enter number to search: 34 Found at index: 4 Program 11: Write a Program to implement Stack using Array. finclude using namespace std; class Stack { private: int* arr; int top; int capacity; public: Stack{int size) { capacit; arr = new int{eap: top =-1; // Stacks i y Stack) ( dotete(] arr; » void push(int x){ if (top = sapacity -1){ cout << "Stack Overflow" << endl; return; , arr[++top] = x; pushed to stack” << endl; int pop(){ if (top == -1){ ‘cout << "Stack Underflow" << endl; returnt; return arr[top—}; } int peek(){ if (top == -1) ‘cout << "Stack is Empty" << endl; return -4; // Indicating that the stack is empty , return arr[toph; d bool isEmpty) { return top. y bool isFulld { return top == capacity - 1; int main0){ Stack stack(5); // Stack of size stack push(10}; stack.push(20); stack.push(30); stack.push(40); stack.push(50}; cout << "Top element is "<< stack.peok() << endl; ‘cout << stack.pop() <<" popped from stack” << endl; cout << "Top element is " << stack.peek() << endl; stack.push(60}; cout <<"Top element << stack.peek() << endl; return 0; OUTPUT: 10 pushed to stack 20 pushed to stack 30 pushed to stack 40 pushed to stack 50 pushed to stack Top element is 50 50 popped from stack Top element is 40 60 pushed to stack Top element is 60 Program 12: Write a Program to implement Queue using Array. #inctude using namespace std; class Queue{ private: int* arr; int front; int rear; int capacity: public: Queuotint size) { capacity = size; arr = new int{capacity; front y ~Queuel){ detetef] arr; y void enqueuetint x){ if (rea sapacity « 1) { ‘cout << "Queue Overflow" << endl; return; arr[++rear] =x; cout << x <<" enqueued to queue" << en y int dequeue(){ if (front -1 [I front > rear){ ‘cout << "Queue Underflow" << endl; return -1; » return arr[front++]; 1 [| front > rear) { ‘cout << "Queue is Empty" << endl; return -1; ) return arr{tronty; ? boot isEmpty) { return front 1] front > rear; y boot isFulld { return ret sapacity - 1; int main0{ Queue q(4); q.enqueue(10}; q.enqueue(20}; qeenqueue(3 q-enqueue(4o); ‘cout << "Front element is "<< q.peek() << endl; cout << q.dequeue() <<" dequeued from queue" << endl; cout << "Front element is "<< q.pesk() << endl; q.enqueue(60}; ‘cout << "Front element is "<< q.peek() << endl; return 0; ) output: 10 enqueued to queue 20 enqueued to queue 30 enqueued to queue 40 enqueued to queue Front element is 10 10 dequeued from queue Front element is 20 60 enqueued to queue Front element is 20 Program 13: Write a Program to implement Circular Queue using Array. include using namespace std; class CircularQueue { private: int* arts int front; int rear; int capacity; public: CircularQueue(int size) { capacity = size; arr = new int[capacity}; ~CircularQueue() { detete[] arr} boot isFull){ return (rear + 1) % capacity: y boot isEmpty(){ return front y void enqueuetint x){ if (isFulUQ){ cout << "Queue Overflow" << endl return; , it front ==-1){ front = 0;) rear= (rear +1) % capacity; arr{rear] cout < using namespace std; class Node { public: int date; Node* next; class Stack ( private: Node* top; public: Stack) { top =nullptr; y Stack!) { while (top != nulipte) { Node* temp = top; top = top->next; dotete temp; y void pusi 1) { Node* newNode = new Node(}; newNode->dat newNode->next ‘top = newNode; cout << x<<" pushed to stack" << endl; y int pop { if (top == nullpte){ cout << "Stack Underflow" << endl; return -1; , int value = top->data; Node* temp = top; top = top->next; delete temp; return value; y int peek(){ if (top == nullptr) { ‘cout << "Stack is Empty” << endl; return -1; , return top>data; y bool isEmpty) { return top ullptr; Fi int main0{ Stack stack; stack.push(10); stack.push(20); stack.push(30}; cout << "Top element is "<< stack.peek{) << endl; ‘cout << stack.pop() <<" popped from stack" << endl; cout << "Top element is "<< stack.p: 3k) << endl; stack.push(60); ‘cout << "Top element is" return 0; ) OUTPUT: 10 pushed to stack 20 pushed to stack 30 pushed to stack Top element is 30 30 popped from stack Top element is 20 60 pushed to stack Top element is 60 Program 15: Write a Program to implement Queue using LinkedList. #include using namespace std; class Node { public: int data; Node* next; class Queue{ private: Node* front; Node* rear; public: Queuet){ front = nullptr; rear=nullptr;) while (front != nultptr) { Node* temp = front; front = front >next; delete temp:}) void enqueuetint x) { Node* newNode = new Node(); newNode->dat newNode->next = nullptr; it (res == nullptr){ front = rear = newNode; pelse{ rear>next = newNode; rear= newNode;} cout << x<<" enqueued to queue" << endl; y int dequeue) { if (front == nuliptr) { ‘cout << "Queue Underflow" << endl; return 13} int value = front->data; Node* tem; ront; front = front>next; nullptr){ rear=nullptr;} delete temp; return value;) int peek(){ if (front nullptr){ ‘cout << "Queue is Empty" << endl; return 4; return front>d y boot isEmpty0){ return front nullpte Int maing Queue qi; enqueue(30); q-enqueue(40o}; q.enqueue(50}; ‘cout << "Front element is " << q.peek() << endl; cout << .dequeue() << lequeued trom queue" << endl; ‘cout << "Front element is "<< q.peek() << endl; q.enqueue(60}; cout << "Front element is "<< q.peok() << endl; return 0; ) OUTPUT: 30 enqueued to queue 40 enqueued to queue 50 enqueued to queue Front element is 10 10 dequeued from queue Front element is 20 60 enqueued to queue Front element is 20 Program 16: Write a Program to implement Circular Queue using LinkedList. #inelude using namespace std; class Node { public: int data; Node* next; class CircularQueue { private: Node* front; Node* rear; public: CircutarQueue() { front = nullptr: ullptrs » ~CircularQueue(){ white (fro nultptr) { Node* temp = front; front = front >next; delete temp; y bool isEmpty(){ return front == nullptr; y void enqueuetint x){ Node* newNode = new Node(); newNode->d hewNode->next = nullptr; if (isEmpty) { front = rear = newNode; rear>next =front; // Making it circular pelset rearone = newNode; rear = newNode; rearonext ont; } cout << x <<" enquoued to queue" << en y int dequeue) { isEmpty) ( cout << "Queue Underflow" << endl; return -1; » int value = front >data; if (front == rear){ delete front; front = rear = nullpte; pelse{ Node* temp = front; front = front->next; rear next = front; delete temp; » return value; y int peek(){ if (isEmpty) { ‘cout << "Queue is Empty" << endl; return -4 int maing){ CircularQueue q; aeenqueue(10}; a.enqueue(20}; a.enqueue(30); a.enqueue(40); q.enqueue(50}; ‘cout << "Front element is "<< q.pook() << endl; cout << q.dequeue() <<" dequeued from queue" << endl; cout << "Front element is " << q.peek() << endl; q-enqueue(60}; ‘cout << "Front element is "<< q.peok() << endl; return 0; ) OUTPUT: 10 enqueued to queue 20 enqueued to queue 30 enqueued to queue 40 enqueued to queue 50 enqueued to queue Front element is 10 10 dequeued from queue Front element is 20 60 enqueued toqueue Front element is 20

You might also like