Assignment 01 FA20

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

COMSATS University, Islamabad

Islamabad Campus
Department of Computer Science

Read before Attempt


Assignment No. 1:
Course code and Title: CSC211, Data Structure and Algorithm
Instructor: Tanveer Ahmed
Assigned Date: September 23, 2019 Due Date: October 2,2019
Total Marks: -- CLO-1:
Instructions:
1. This is an individual assignment. You will submit your work individually through your logins
(course portal)
2. Try to get the concepts, consolidate your concepts and ideas from these questions
3. You should concern recommended books for clarify your concepts as handouts are not
sufficient.
4. Try to make solution by yourself and protect your work from other
students. If I found the solution files of some students are same, then I will
reward zero marks to all those students.
5. Deadline for this assignment is October 2,2019. This deadline will not be extended.

Question # 1 ( Static List)


There are two static lists A and B containing the integer data(randomly). List A and B have 7 and 9 data items
respectively.
a) Design a new List data structure (i.e. List C) that only contains common elements of List A and B. You should
write following method for List C only using operations of List A and List B.
bool is_full() the method returns true when the List C is full and false in other case

bool is_empty() the method returns true when the List C empty and false in other case

int find_common() the method returns item x which is common in List A and List B

void insert_common_descending (int a) the method inserts common element in List C in descending order

Void show () the method displays the element of List C

Question # 2
There are two static lists A and B containing the integer data(randomly). List A contain only even numbers in
odd range and list B contain only odd numbers in even range. Write an algorithm that create a List D that
merge elements of both lists alternatively (i.e. first place even number and then odd number).

Fall 2020 Page 1


a) You should write following method for List D only using operations of List A and List B.
int size_ListA() the method returns number of elements in list A

int size_ListB() the method returns number of elements in list B

void insert_ListD (int a) the method inserts element of List A and B in List D in alternatively

Note: Let s1 and s2 be the values return by methods size_ListA() and size_ListB() respectively, then the size
of list D is s = s1 + s2.
Question # 3 (Linked List) Dynamic List
Write an algorithm that take input integer value k where k is less than the number of nodes in given linked list.
The algorithm than swap kth node from beginning with kth node from end in a given Linked List.
For example, the given list is:

7 4 9 3 11 8 N

And user input value of k = 5


Than output of your algorithm should be:

7 11 9 3 4 8 N

Question # 4 (Circular Linked List)


Let sum1 and sum2 be the sum of even and nodes in a given circular linked list. Write C++ method that
compute sum1 and sum2 and replace first and last node of given circular linked list with sum1 and sum2
respectively.
For example: Following is given input circular linked list:

7 11 9 3 4 8

Sum1 = 11+3+8 = 22
Sum2 = 7+9+4 = 20
Output is:

Question # 5 (Double Linked List)


Let k be a given integer value. Write an algorithm that search two nodes in double linked list whose sum is
equal to k without using any extra space.
Question # 6 (Double Circular Linked List)
Write an algorithm that delete duplicate node from given circular doubly linked list.

Fall 2020 Page 2

You might also like