CS301 Assignment No 3 Solution Spring 2018 | Virtual Study Solutions

Adsetra Ads

 

CS301 Assignment No 3 Spring 2018

Dear Students, Here you can read or Download CS301 - Data Structures Assignment No 3 Solution of Semester Spring 2018. Assignment Due Date is 26 July, 2018. Total Marks are 20. This assignment covers lesson no. 23 to 33. We are here to facilitate your learning and we do not appreciate the idea of copying or replicating solutions. CS301 Assignment Solution File has been added. Previously we shared CS201 Assignment No 3 Solution Spring 2018.

cs301 assignment no 3 Solution Spring 2018
CS301 assignment no 3 Solution Spring 2018

CS301 Assignment Instructions

Please read the following instructions carefully before solving & submitting assignment:
It should be clear that your assignment will not get any credit (marks) if:

  • The assignment is submitted after due date.
  • The submitted assignment file is not in .cpp format.
  • The submitted assignment file does not open or corrupted.
  • The assignment is copied (from other student or ditto copy from handouts or internet).

CS301 Assignment Uploading instructions

  • Do not wait for grace day. Grace Day is given only if there is problem with LMS on due date. Submit your solution within due date. 
  • Note that no assignment will be accepted through email if there is any problem in LMS on grace day.

CS301 Assignment Objective

The objective of this assignment is to make you familiar with working and implementation of heap data structure.

CS301 Assignment Question:

Write C++ program to implement min heap. Your program should fulfill requirements given below in points a) and b).

Data: 18, 31, 82, 85, 37, 20, 23, 79, 47, 51, 96, 97, 42, 94, 57, 29

  1. Consider the data given above and build min heap of odd nodes/values only using insert method you learned in handouts/video lectures. 
  2. Consider the data given above and build min heap of all nodes/values in data using buildHeap method given in handouts/video lectures.

 [ Marks = 20 ] 

CS301 Assignment solution instructions:

  • Graphical representation of odd min heap using insert() method and min using buildHeap() method is given below for your understanding. 
  • Given data should be used for input to heap in the form of array. 
  • For Odd min heap construction use data given above while constructing min heap, check if the number/node is odd then use it for heap construction. In case of even discard it and move to next number. 
Data after extracting odd nodes/values : 31, 85, 37, 23, 79, 47, 51, 97, 57, 29

CS301 Assignment solution graphical representation - 1
CS301 Assignment solution graphical representation - 1


Data: 18, 31, 82, 85, 37, 20, 23, 79, 47, 51, 96, 97, 42, 94, 57, 29

CS301 Assignment solution graphical representation - 2
CS301 Assignment solution graphical representation - 2

Sample Output:

CS301 Assignment Sample output
CS301 Assignment Sample output

CS301 Assignment No 3 Solution Spring 2018

You can see the Sample Preview of CS301 Assignment No 3 Solution provided by (Virtual Study Solutions) below. Click on Download Button to Download Solution File in Your PC. Please Share it with your friends. You can also like our Facebook Page or Subscribe Us below for Updates.

CS301 Assignment Solution Sample Preview

Solution File Sample Page Preview has been added below with Solution File in .docx format and .cpp format.

Solution Code - 1 Preview:

#include <iostream>
#include <conio.h>
using namespace std;
void min_heapify(int *a,int i,int n)
{
    int j, temp;
    temp = a[i];
    j = 2 * i;
    while (j <= n)
    {
        if (j < n && a[j+1] < a[j])
            j = j + 1;
        if (temp < a[j])
            break;
        else if (temp >= a[j])
        {
            a[j/2] = a[j];
            j = 2 * j;
        }
    }
    a[j/2] = temp;
    return;
}
void build_minheap(int *a, int n)
{
    int i;
    for(i = n/2; i >= 1; i--)
    {
        min_heapify(a,i,n);
    }
}
int main()
{
    int n, i, x;
    cout<<"enter no of elements of array\n";
    cin>>n;
    int a[20];
    for (i = 1; i <= n; i++)
    {
        cout<<"enter element"<<(i)<<endl;
        cin>>a[i];
    }
    build_minheap(a, n);
    cout<<"Min Heap\n";
    for (i = 1; i <= n; i++)
    {
        cout<<a[i]<<endl;
    }
    getch();
}

Solution Code - 2 Preview:

#include <iostream>
#include <conio.h>
using namespace std;
void min_heapify(int *a,int i,int n)
{
int j, temp;
temp = a[i];
j = 2 * i;
while (j <= n)
{
if (j < n && a[j+1] < a[j])
j = j + 1;
if (temp < a[j])
break;
else if (temp >= a[j])
{
a[j/2] = a[j];
j = 2 * j;
}
}
a[j/2] = temp;
return;
}
void build_minheap(int *a, int n)
{
int i;
for(i = n/2; i >= 1; i--)
{
min_heapify(a,i,n);
}
}
int main()
{
int n, i, x;
cout<<"enter no of elements of array\n";
cin>>n;
int a[20];
for (i = 1; i <= n; i++)
{
cout<<"enter element"<<(i)<<endl;
cin>>a[i];
}
build_minheap(a, n);
cout<<"Min Heap\n";
for (i = 1; i <= n; i++)
{
cout<<a[i]<<endl;
}
getch();
}

Assignment Solution Download Link

Download  [ Solution Code 1 .cpp File Upload Status : Done ]

Download  [ Solution Code 2 .cpp File Upload Status : Done ]

Post a Comment

  1. sir this solution is not fully complete. plz can you provide full solution?/

    ReplyDelete
  2. Dear its just to build min heap of an array of given data...
    actual assignment is to create min heap of odd values of given data using insert method ... this sample code in not a complete solution

    ReplyDelete
  3. kon sy software man y code write krna h

    ReplyDelete

 

Top