Docsity

Data Structure6 Assignments, Exercises of Data Structures and Algorithms

Toggle sidebar
bg1
CCS20503
DATA STRUCTURE AND ALOGORITHM
ASSIGNMENT 1
FEBRUARY 2017
Due date: 6th March 2017, during class only (assignment hardcopy)
Weighting: Part of 10% of overall assessment.
Environment: You are required to do this assignment in C++ environment.
Assessment
Your assignment will be assessed for the following:
Correctness of the programs
Sample test data/results/output or discussion of results
No plagiarism
Submission
You are required to submit documentation in the form of printed copy of your
codes and sample test data. Your submission should bind together with a
BLACK tape with the assignment cover given at the end of this assignment
question. Use RED colour paper as your Assignment 1 cover.
Warning
1. Plagiarism or late submission will get 0 mark.
pf3
pf4

Partial preview of the text

Download Data Structure6 Assignments and more Exercises Data Structures and Algorithms in PDF only on Docsity!

CCS

DATA STRUCTURE AND ALOGORITHM

ASSIGNMENT 1

FEBRUARY 2017

Due date: 6 th^ March 2017, during class only (assignment hardcopy)

Weighting: Part of 10% of overall assessment.

Environment: You are required to do this assignment in C++ environment.

Assessment

Your assignment will be assessed for the following: Correctness of the programs Sample test data/results/output or discussion of results No plagiarism

Submission

You are required to submit documentation in the form of printed copy of your codes and sample test data. Your submission should bind together with a BLACK tape with the assignment cover given at the end of this assignment question. Use RED colour paper as your Assignment 1 cover.

Warning

1. Plagiarism or late submission will get 0 mark.

ASSIGNMENT QUESTION:

Question 1 (25 marks)

Write a program to determine the address of memory locations allocated to various variables as follows:

a. Declare two short int variables, two int variables, and long int variable

and then output the address of each variable.

b. Draw a memory map that shows the starting address of each variable.

c. Calculate the size of the memory location allocated to each type by

subtracting the address of the first variable from the address of the second variable of the same type.

d. Add statements to your program that use the sizeof operator to find the

size of the memory location allocated to each type.

Question 2 (25 marks)

Checking balanced parenthesis can be solved without using a stack; In fact a simple integer variable can be used. Describe how, and write a program that uses your method to solve the problem.

Tips! Problem Solving: To check whether a given string containing brackets is correct or not (balanced or unbalanced).

1. Do a looping from 1 to the first occurrence (Forward) of close bracket,

and then from that point, move backward to the first occurrence of open bracket, then cut that portion of string.

2. Do this until we get empty string (It's a balanced parentheses) or when

we cannot do any more search (Unbalanced parentheses).

Example of the second implementation

(()) Original string (()) First search, found ) at index 3 (()) Go back, found ( at index 2 () Delete that portion of string () Second search, found ) at index 2 () Go back, found ( at index 1

  • Empty string, it's a balanced parentheses.
  • Marks: /25+25 =