Data structures complete notes, Lecture notes of Data Structures and Algorithms

C programming and its data structures and algorithms notes in detail

Typology: Lecture notes

2018/2019

Uploaded on 12/09/2019

Lala.mosa
Lala.mosa 🇵🇰

5 documents

1 / 36

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lab Manual
CS301 – Data Structures
Department of Computer Science, Virtual University of Pakistan
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24

Partial preview of the text

Download Data structures complete notes and more Lecture notes Data Structures and Algorithms in PDF only on Docsity!

Lab Manual

CS301 – Data Structures

Department of Computer Science, Virtual University of Pakistan

Week No. Lab Topic Page No. 1 Lab 1: Learn to implement linked list data structure 2 2 Lab 2: Learn to implement stack data structure using array 3 3 Lab 3: Learn to implement queue data structure using link list 4 4 Lab 4: Learn to draw binary search tree and implement in-order traversal 5 5 Lab 5: Learn to implement binary search tree for string type data (^7) 6 Lab 6: Learn to understand and implement function call by value, reference and pointer

7 Lab 7: Learn to understand and implement function call by value, reference and pointer

8 Lab 8: Learn to delete nodes from BST 19 Midterm Exams 9 Learn to delete nodes from AVL tree 20 10 Learn to build frequency table and Huffman encoding tree 22 11 Lab 11: Learn to implement min heap using insert( ) method 24 12 Lab 12: Learn to implement min heap using buildHeap( ) method 29 13 Lab 13: Learn to build union tree 30 14 Lab 14: Learn to implement binary search algorithm 31 15 Lab 15: Build Hash table using linear probing collision resolution technique

16 Lab 16: Learn to sort array using bubble sort algorithm 34

Lab 2

Lab Title: Learn to implement stack data structure using array

Objectives: Get the knowledge of implementing stack list data structure using array in C++

programming language

Tool: Dev C++

Description:

Write a C++ program to implement data structure Stack. You have to write all the stack functions and using those functions insert the numbers 1 to 10 into the stack. The stack should be able to show the error messages if the push( ) operation is initiated but the stack is full or the pop( ) operation is initiated but the stack is empty.

Lab 3

Lab Title: Learn to implement queue data structure using link list

Objectives: Get the knowledge of implementing queue data structure using link list in C++

programming language.

Tool: Dev C++

Description:

Write the C++ Code for the enqueue( ), dequeue( ), front( ) and the rear( ) functions of the class queue.

int main() { int Array[]={14, 15, 4, 9, 7, 18, 3, 5, 16, 4, 20, 17, 9, 14, 5,-1}; TreeNode * root = new TreeNode(); root->set(&Array[0]); for (int i = 1; Array[i] > 0; i++) { insert(root, &Array[i]); } cout << "\ninorder: "; inOrder( root ); } // end of main void inOrder(TreeNode* treeNode) { if( treeNode != NULL ) { inOrder(treeNode->getLeft()); cout << *(treeNode->get())<<" "; inOrder(treeNode->getRight()); } } //End of inOrder.

Lab 5

Lab Title: Learn to implement binary search tree for string type data

Objectives: Get the knowledge of implementing binary search tree for string data type using

C++ programming language.

Tool: Dev C++

Description:

Write C++ code that will draw BST using string type of data: "babble", "fable", "jacket","backup", "eagle","daily","gain","bandit","abandon", "abash","accuse","economy","adhere","advise","cease","debunk","feeder","genius","fetch","chai n", NULL Note: Template_BSTNode.cpp Template_Node_SLL.cpp and Template_Queue_LinkedList.cpp files will students search from CS301 handouts or may be provided by the tutor/Instructor. #include #include #include "Template_BSTNode.cpp" #include "Template_Queue_LinkedList.cpp" using namespace std; template void insert(BSTNode * , T); template void insertChar(BSTNode * , T); template void inOrderTraverse(BSTNode * ); template void preOrderTraverse(BSTNode * ); template

void insert(BSTNode * node, T x) { BSTNode * newNode = new BSTNode(x); BSTNode * tempRoot, * tempLeaf; tempRoot = tempLeaf = node; while(x !=tempRoot->getData() && tempLeaf != NULL) { tempRoot = tempLeaf; if(x< tempRoot->getData()) tempLeaf = tempRoot->getLeft(); else tempLeaf = tempRoot->getRight(); } // end of while , this loops only break when x = data hold by current node or it is leaf; if(x == tempRoot->getData()) { cout << "\nDuplicate element entry !!! "<< x << endl; delete newNode; } else if(x< tempRoot->getData()) tempRoot->setLeft(newNode); else tempRoot->setRight(newNode); }

template void insertChar(BSTNode * node, T x) // OverLoaded Insert Funciton { BSTNode * newNode = new BSTNode(x); BSTNode * tempRoot, * tempLeaf; tempRoot = tempLeaf = node; while(strcmp(x, tempRoot->getData())!=0 && tempLeaf != NULL) { tempRoot = tempLeaf; if(strcmp(x, tempRoot->getData())<0 ) tempLeaf = tempRoot->getLeft(); else tempLeaf = tempRoot->getRight(); } // end of while , this loops only break when x = data hold by current node or it is leaf; if(strcmp(x, tempRoot->getData())==0 ) { cout << "\nDuplicate element entry !!! "<< x << endl; delete newNode; } else if(strcmp(x, tempRoot->getData())< 0 ) tempRoot->setLeft(newNode);

template void postOrderTraverse(BSTNode * node ) { if(node!=NULL) { postOrderTraverse(node->getLeft() ); // it will keep caling function till reaches node reach end postOrderTraverse(node->getRight() ); cout << endl<<node->getData(); } } template void levelOrderTraverse(BSTNode * node ) { queue <BSTNode *> myQueue; if (node == NULL) return; myQueue.push(node); while (!myQueue.isEmpty()) { node = myQueue.peak(); myQueue.pop(); cout << endl<< node->getData(); if(node->getLeft() != NULL) myQueue.push(node->getLeft()); if(node->getRight() != NULL)

myQueue.push(node->getRight()); } system("pause"); }

myInt = 31 ; retVal = intMinus2( &myInt ); //call by passing a pointer cout << “After returning from the called function intMinus2” << endl; cout << ”The value returned by the called function (retVal) is : ” << retVal ; cout << endl; cout << ”The value of the calling function’s variable (myInt) is : ” << myInt ; cout << endl << endl; // now pass the argument by as reference, also initialize the value of myInt myInt = 31 ; retVal = intMinus3( myInt ); //call by passing a reference cout << “After returning from the called function intMinus3” << endl; cout << ”The value returned by the called function (retVal) is : ” << retVal ; cout << endl; cout << ”The value of the calling function’s variable (myInt) is : ” << myInt ; }

Lab 7

Lab Title: Learn to delete nodes from BST

Objectives: Understand to deletion process of nodes in BST

Tool: MS Word, MS Visio

Description:

Draw Binary Search Tree from the given data. Also draw Binary Search Tree after removal of value ‘9’. 9 4 6 17 2 8 4 15 41 47 29

Lab 8

Lab Title: Learn to draw AVL

Objectives: Learn to build/draw AVL tree and understand different types of rotations

Tool: MS Word, MS Visio

Description:

Build AVL tree from the given Data: 3 5 6 7 9 10 11 21 20 18 19 Note : You have to show only final AVL tree after insertion of each node value.