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

MSC f10 1st LAB DSA - New

1) The document provides instructions for a lab assignment on data structures and algorithms. It contains 5 problems in Section A and 3 problems in Section B to attempt. 2) For Section A, the problems include printing the sum of an array except for numbers following 13, checking if an array contains consecutive 3s, checking if the sum of 2s in an array is 8, combining characters from two strings alternately, and checking for three increasing adjacent numbers. 3) For Section B, the problems are rearranging an array with odd numbers before evens, removing all 10s from an array and shifting others left, and finding the difference between the largest and smallest number in an array.

Uploaded by

Kul King
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views

MSC f10 1st LAB DSA - New

1) The document provides instructions for a lab assignment on data structures and algorithms. It contains 5 problems in Section A and 3 problems in Section B to attempt. 2) For Section A, the problems include printing the sum of an array except for numbers following 13, checking if an array contains consecutive 3s, checking if the sum of 2s in an array is 8, combining characters from two strings alternately, and checking for three increasing adjacent numbers. 3) For Section B, the problems are rearranging an array with odd numbers before evens, removing all 10s from an array and shifting others left, and finding the difference between the largest and smallest number in an array.

Uploaded by

Kul King
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

DATE: 4 / 3 / 11

Data Structure & Algorithm

M.Sc IT Lab 1
Note: Print every Array before and after modification.

*Attempt at least two problems from Section A and two from section B in lab.

Section A
Problem 1: Print the sum of the numbers in the array. Except the number 13
which is very unlucky, so it does not count and numbers that come immediately
after a 13 also do not count.

Sample example:

{1, 2, 2, 1} → 6
{1, 1} → 2

{1, 2, 2, 1, 13,1} → 6
{1, 2, 2, 1, 13, 675,1}→ 7

Problem 2: Given an array of integers, print “Good” if the array contains two
consecutive 3’s and Print “Bad” otherwise.

Sample example:

{1, 3, 3} → Good
{1, 3, 1, 3} → Bad
{3, 1, 3} → Bad

Problem 3: Given an array of integers, Print “Good” if the sum of all the 2's in the
array is exactly 8 and print “Bad” otherwise.

{2, 3, 2, 2, 4, 2}) → Good


{2, 3, 2, 2, 4, 2, 2} → Bad

Punjab University College of Information Technology.


Problem 4: Given two strings, A and B, create a bigger string made of the first
char of A, the first char of B, the second char of A, the second char of B, and so
on. Any leftover chars go at the end of the result.

Sample example:

"abc", "xyz"→ "axbycz"


"Hi", "There" → "HTihere"
"xxxx", "There" → "xTxhxexre"

Problem 5: Print “true” if the array contains, somewhere, three increasing


adjacent numbers like .... 4, 5, 6, ... or 23, 24, 25 etc. print “False” otherwise.

Sample example:

{1, 4, 5, 6, 2} → true
{1, 2, 3} → true
{1, 2, 4} → false

Section B
Problem 1: You have an array having some numbers (1-9) even & odd mixed
up. Print this array. Now your task is that to rearrange this array or create a new
array contains the exact same numbers as the given array, but rearranged so
that all the odd numbers come before all the even numbers. Other than that, the
numbers can be in any order. You may modify array, or make a new array. Now
print this array. (Best practice is to modify existing array in this scenario).
*Order doesn’t matter.

Sample example:

Test array : {1, 2, 1, 8, 0, 1,4,2, 9,7,1,6}


A possible outcome: {1, 1, 1, 9, 7, 1, 2,8,0,4,2,6}

Problem 2: Create new or modify given array where all the 10's have been
removed. The remaining elements should shift left towards the start of the array
as needed, and the empty spaces at the end of the array should be replaced with
0. So {5, 10, 10, 9} goes to {5, 9, 0, 0}. You may modify and or make a new
array.

Punjab University College of Information Technology.


Problem 3: Given an array length 1 or more of integers, Print the difference
between the largest and smallest values in the array.

Sample example:

{7, 6, 8, 5}  3

{7, 7, 6, 8, 5, 4, 6}4

Do your best and leave the rest… Good Luck

Punjab University College of Information Technology.

You might also like