0% found this document useful (0 votes)
66 views

Assignment No 1

This document contains 8 problems related to data structures and algorithms involving linked lists. The problems cover calculating employee wages from a text file using a single linked list, merging two sorted linked lists, implementing functions for a single linked list, analyzing time complexity of code snippets, sorting nodes of a double linked list, taking the union and intersection of linked lists containing words, finding pairs in a doubly linked list whose product equals a given value, and checking if a singly linked list is a palindrome. The document provides notes for some problems specifying the data structure to use or expected output format.

Uploaded by

Joshua
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

Assignment No 1

This document contains 8 problems related to data structures and algorithms involving linked lists. The problems cover calculating employee wages from a text file using a single linked list, merging two sorted linked lists, implementing functions for a single linked list, analyzing time complexity of code snippets, sorting nodes of a double linked list, taking the union and intersection of linked lists containing words, finding pairs in a doubly linked list whose product equals a given value, and checking if a singly linked list is a palindrome. The document provides notes for some problems specifying the data structure to use or expected output format.

Uploaded by

Joshua
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignment # 1

Data Structure and Algorithm

Asma Sattar

Section A

Last Date: 11th Sep,2019(01:15-pm)

No assignment will be entertained(accepted) after due date.

Problem 1
Write a program for a company where they need help to calculate the monthly wages of their
employees depending upon the number of hours they work in the organization. Your program should
be generic for any number of employees. Load the names and working hours of the employees from
“Employees.txt” file. Wage Criteria is: (50 x number of hours they’ve worked in a month)

At the end, show all the employee names and their wages on the screen an also save them in a file
namely “Wages.txt”.

Note: Use Single linked list.

Problem 2:
Note: Merge two sorted linked lists.

You’re given the pointer to the head nodes of two sorted linked lists. Change the next pointers to
obtain a single, merged linked list which also has data in ascending order. Input the link list data from
the user.

Problem 3:
Note: Use Single linked list.

Implement singly linked list having following functions:


 Insert
 delete-specific-element(delete specific digit entered)
 delete-all(delete all list)
 search(searches if an element prompt is present or not and tells at which point it is present (if
present))
 is-empty(tells if LL is empty or not)

Problem 4:
Note: analyse for time complexity. Big O

Write big O for each of the following code. Also write number of operations for mentioned values of
n

a. (3 points)
int main()

int n;

cin >> n;

int i = 1;

while (i <= n)

// The numbers 1..i-1 have been written

cout << i << endl; i = i + 1;

b. (3 points)

int main()

char input, alphabet = 'A';


cout << "Enter the uppercase character you want to print in the last row: ";

cin >> input;

for(int i = 1; i <= (input-'A'+1); ++i)

for(int j = 1; j <= i; ++j)

cout << alphabet << " ";

++alphabet;

cout << endl;

return 0;

c. (4 points)

#include<iostream.h>

int main()

int a=1;

while(a<3)

cout<<"Cat"<<endl;

a=a+1;

int b=0;
while(b<2)

cout<<"Dog"<<endl;

b=b+1;

};

system("pause");

return 0;

};

Problem 5:
You have to take input from the file input.txt and do double linked list insertion on it. After that you
have to sort the nodes in a way that data on odd nodes should come first and data on even nodes
should be on end. For example 5->6->8->9->14->12->19 after sorting the result should be 6->9->12->5-
>8->14->19.(Note: There are multiple solution of this problem you must use efficient one and you
have to do sorting on nodes not on the data.)

Problem 6:
Write a code to Take Union And Intersection of three singly linked-list containing WORDS .

 The final linked list should be sorted in ascending order according to first alphabet of WORD
 The output should be proper.
 Do the same task with doubly circular linked list

Problem 7:
Given a sorted doubly linked list of positive distinct elements, the task is to find pairs in the
doubly linked list whose product is equal to given value x, without using any extra space.
Problem 8:
Write a Program to check if the singly linked- list is palindrome .

 If the linked list is not palindrome then sort the list in ascending and descending order .

Note: Output should be proper

You might also like