HW1
.pdf
keyboard_arrow_up
School
Purdue University *
*We aren’t endorsed by this school
Course
252
Subject
Computer Science
Date
Apr 3, 2024
Type
Pages
14
Uploaded by AmbassadorOyster2629
CS252 Homework 1 (ver2)
1. Given we have an arena size of 128, what would be the correct memory diagram from the
following code snippet if we are using the myMalloc library from lab1. Assume that when an
object is split, the left part is returned by malloc and the right part stays in the free list.
char * ptr1 = malloc(14)
char * ptr2 = malloc(42)
char * ptr3 = malloc(6)
free(ptr2)
free(ptr1)
char * ptr4 = malloc(79)
Here is a blank diagram for your work:
2. In the following program, which memory section does the address &p reside in:
int a = 5;
int b[20];
int main() {
int x;
int *p =(int*) malloc(sizeof(int));
}
Answer: _______________
3. According to the memory configuration represented in the diagram below: if the user makes a
call to
malloc(num_of_bytes)
, what is the smallest value
num_of_bytes
can be to trigger a
call to
sbrk()
. The shaded area indicates the allocated memory.
Answer: _______________
4. Dark shaded blocks are allocated, white blocks are unallocated, and fence posts are
indicated by "F".
Assume block A was allocated and then freed. After block A is freed, what memory address
points to the header associated with the memory that will contain A, and what is the size of the
block?
Answer:_____________
5. Dark shaded blocks are allocated, white blocks are unallocated, and fence posts are
indicated by "F".
The user calls free on block A. After block A is freed, what memory address points to the header
associated with the memory that contains A, and what is the size of the block? Assume block A
was allocated before being freed.
Answer:____________
6. Dark shaded blocks are allocated, white blocks are unallocated, and fence posts are
indicated by "F". Assume a 64-bit architecture.
The user calls free on block A. After block A is freed, what memory address points to the header
associated with the memory that contains A, and what is the size of the block? Assume block A
was allocated before being freed.
Answer:________
7. In the malloc implementation, we had a global variable: "header * lastFencePost", What was
this variable used for?
Answer:
8. What are the benefits of using boundary tags as a data structure for memory allocation.
Answer:
9. The following code is an example of
int main()
{
int *p = ( int * ) malloc ( 100 );
p = p + 1;
free(p);
return 0;
}
Answer:
10. Use this simplified diagram of the free lists as reference. The numbered blocks are
sentinels, the lettered blocks indicate free blocks. Use the segregated free list indexing from the
lab1 handout.
Which block would be chosen to satisfy a malloc of size 8?
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
- Access to all documents
- Unlimited textbook solutions
- 24/7 expert homework help
Related Questions
In this assignment, you will create a Linked List data structure variant called a “Circular Linked List”. The Node structure is the same as discussed in the slides and defined as follows (we will use integers for data elements):
public class Node
{
public int data;
public Node next;
}
For the Circular Linked List, its class definition is as follows:
public class CircularLinkedList
{
public int currentSize;
public Node current;
}
In this Circular Linked List (CLL), each node has a reference to an existing next node. When Node elements are added to the CLL, the structure looks like a standard linked list with the last node’s next pointer always pointing to the first. In this way, there is no Node with a “next” pointer in the CLL that is ever pointing to null.
For example, if a CLL has elements “5”, “3” and “4” and “current” is pointing to “3”, the CLL should look like:
Key observations with this structure:
The currentSize is 3 meaning there…
arrow_forward
Please show an example of how or how to solve coding the problem from Starting out with Java from control structures through data structures 4th edition: chapter 19 programming challenge 4
arrow_forward
Java Programming
Define a class CollectionBooks. This class has a data member list of type Book using the ArrayList collection.
Define method add. This method add the any object to list.
Define printAll. This method display all the added object in the list.
Define printAll. This method display all the added object in the list. · Define int count. This method returns the number of objects added in the list.
Define Book search(Object e). This method returns the object being search if not found return null.
Define void remove(int index). This method remove the object in a list
Add a main method with the following menu:1 – Add 2 – Count 3 – Print4 – Search 5 – Delete 6 - Exit
arrow_forward
2
//please write it in java
This is a circular doubly linked list. It starts at the head pointer (Head). Write a function that adds a node (P) at the nth location away from the Head keeping the circle connected.
For example, based on the image, the list is: C, D, B, A
After calling addNthNode(Head, P, 2), the list becomes C, F, D, B, A
Note that if the position is 1 then the Head should be updated. Your code should validate parameters, and handle edge cases.
void addNthNode (Node Head, Node P, int position){
// your code goes here
}
arrow_forward
data structures in java
arrow_forward
1. Create a doubly-linked list of string and add the following
methods
Add at the head
b. Add at the tail
Remove from head
4. Remove from tail
arrow_forward
Unique Words
Summary Specifications:You are tasked to implement an abstract data type class which takes in a given input file called input.txt, and processes, identifies and sorts all unique word instances found in the file.
Sample InputHi hello hi good bye goodbye Bye bye good say
Sample OutputBye Hi bye hello hi say
The input.txt file is found along with the zip folder where this instructions file also came along with.
Note: you are not allowed to use pythonic lists, and its methods and functions, and string methods.
However the use of the file handling methods (read readlines and readline) are allowed for this project.
arrow_forward
C++
A queue is essentially a waiting list. It’s a sequence of elements with a front and a back. Elements can only be added to the back of the queue and they can only be removed from the front of the queue. Elements are kept in order so that the first element to enter the queue is the first one to leave it.
arrow_forward
Reference-based Linked Lists: Select all of the following statements that are true.
As a singly linked list's node references both its predecessor and its successor, it
is easily possible to traverse such a list in both directions.
According to the terminology introduced in class, the head reference variable in
a singly linked list object references the list's first node.
According to the terminology introduced in class, in a doubly linked list, each
node references both the head and tail node.
In a double-ended singly linked list, the tail reference variable provides access to
the entire list.
In a circular linked list, the last node references the first node.
arrow_forward
Question 20
A list is a collection with additional index- and iteration- related operations.
True
False
Question 21
O(N) is the order of growth execution time of the size operation when using the SortedArrayCollection class, assuming a collection size of N.
True
False
Question 22
If N represents the number of elements in the list, then the index-based set method of the ABList class is O(1).
True
False
Question 23
O(N) is the order of growth execution time of the remove operation when using the LinkedCollection class, assuming a collection size of N.
True
False
Question 24
It is not possible to use an array to implement a linked list.
True
False
Question 25
O(N) is the order of growth execution time of the remove operation when using the ArrayCollection class, assuming a collection size of N.
True
False
Question 26
Our linked implementation of lists implements a bounded list.
True
False
Question 27
O(N) is the order of growth execution time of the contains operation…
arrow_forward
Exercise 1• Create a class that sorts a list in ascending order. Make use of the Collections method sort• The list should be a list of Strings.• Test your code with {“Hearts”, “Diamonds”, “Clubs”, “Spades”}• Before and after the sort, use the implicit call to the list’s toString method to output the list contents.
Exercise 2• Create a class with the same requirement as in Exercise 1, but the sort should be in descending order• Make use of the Comparator interface• Make use of the static collection method reverseOrder
java
arrow_forward
PYTHON:
Given a base Plant class and a derived Flower class, write a program to create a list called my_garden. Store objects that belong to the Plant class or the Flower class in the list. Create a function called print_list(), that uses the print_info() instance methods defined in the respective classes and prints each element in my_garden. The program should read plants or flowers from input (ending with -1), add each Plant or Flower to the my_garden list, and output each element in my_garden using the print_info() function.
arrow_forward
Course: Data Structure and Algorithims
Language: Java
Kindly make the program in 2 hours.
Task is well explained.
You have to make the proogram properly in Java:
Restriction: Prototype cannot be change you have to make program by using given prototype.
TAsk:
Create a class Node having two data members
int data;
Node next;
Write the parametrized constructor of the class Node which contain one parameter int value assign this value to data and assign next to null
Create class LinkList having one data members of type Node.
Node head
Write the following function in the LinkList class
publicvoidinsertAtLast(int data);//this function add node at the end of the list
publicvoid insertAthead(int data);//this function add node at the head of the list
publicvoid deleteNode(int key);//this function find a node containing "key" and delete it
publicvoid printLinkList();//this function print all the values in the Linklist
public LinkListmergeList(LinkList l1,LinkList l2);// this function…
arrow_forward
Tour.java
Create a Tour data type that represents the sequence of points visited in a TSP tour. Represent the
tour as a circular linked list of nodes, one for each point in the tour. Each Node contains two
references: one to the associated Point and the other to the next Node in the tour. Each
constructor must take constant time. All instance methods must take time linear (or better) in the
number of points currently in the tour.
To represent a node, within Tour.java, define a nested class Node:
private class Node {
private Point p;
private Node next;
}
Your Tour data type must implement the following API. You must not add public methods to the
API; however, you may add private instance variables or methods (which are only accessible in the
class in which they are declared).
public class Tour
// Creates an empty tour.
public Tour()
// Creates the 4-point tour a→b→c→d→a (for debugging).
public Tour(Point a, Point b, Point c, Point d)
// Returns the number of points in this tour.
public…
arrow_forward
P1.
arrow_forward
Computer Science
//iterator() creates a new Iterator over this list. It will//initially be referring to the first value in the list, unless the//list is empty, in which case it will be considered both "past start"//and "past end".
template <typename ValueType>typename DoublyLinkedList<ValueType>::Iterator DoublyLinkedList<ValueType>::iterator(){//return iterator(head);}
//constIterator() creates a new ConstIterator over this list. It will//initially be referring to the first value in the list, unless the//list is empty, in which case it will be considered both "past start"//and "past end".
template <typename ValueType>typename DoublyLinkedList<ValueType>::ConstIterator DoublyLinkedList<ValueType>::constIterator() const{//return constIterator(head);}
//Initializes a newly-constructed IteratorBase to operate on//the given list. It will initially be referring to the first//value in the list, unless the list is empty, in which case//it will be…
arrow_forward
Need help only part 2. Thank you!
In this assignment, you will create a Linked List data structure variant called a “Circular Linked List”. The Node structure is the same as discussed in the slides and defined as follows (we will use integers for data elements):
public class Node
{
public int data;
public Node next;
}
For the Circular Linked List, its class definition is as follows:
public class CircularLinkedList
{
public int currentSize;
public Node current;
}
In this Circular Linked List (CLL), each node has a reference to an existing next node. When Node elements are added to the CLL, the structure looks like a standard linked list with the last node’s next pointer always pointing to the first. In this way, there is no Node with a “next” pointer in the CLL that is ever pointing to null.
For example, if a CLL has elements “5”, “3” and “4” and “current” is pointing to “3”, the CLL should look like:
Key observations with this structure:…
arrow_forward
A business that sells dog food keeps information about its dog food products in a linked list. The list is named dogFoodList. (This means dogFoodList points to the first node in the list.) A node in the list contains the name of the dog food (a String), a dog food ID (also a String) and the price (a double.)
a.) Create a class for a node in the list.
b.) Use this class to write pseudocode or Java for a public method that prints the name of all dog foods in the list where the price is more than $20.00.
arrow_forward
java method :
Write a method called prioritizeQueue to give priority for vaccination for elderly persons. The method is to be in a class called VaccinationQueue and has two parameters q1 and q2 type ArrayQueue. The q1 and q2 data are of type Integer. Assume that initially q1 is not empty and q2 is empty. The method will insert from q1 those elements towards the beginning of the queue (front) q2 whose data is greater than or equal to 45 and will insert those elements whose data is less than 45 and greater than or equal to 18 towards the end (rear) of q2. Any data item less than 18 of q1 will not be inserted in q2. It returns the number of elements added to q2.
Class ArrayQueue and all its methods including iterator are available for use. You can also create temporary queues. You are not allowed to use arrays or any other data structure.
Example:
Before method call:
front rear
q1: 14 25 50 70 35 45 19 10 21…
arrow_forward
JAVA LANGUAGE
arrow_forward
Assume you have a class SLNode representing a node in a singly-linked list and a
variable called list referencing the first element on a list of integers, as shown below:
public class SLNode {
private E data;
private SLNode next;
public SLNode( E e){ data = e; next = null; }
public SLNode getNext() { return next; }
public void setNext( SLNoden){ next = n; }
}
SLNode list;
Write a fragment of Java code that would append a new node with data value 21 at
the end of the list. Assume that you don't know if the list has any elements in it or
not (i.e., it may be empty). Do not write a complete method, but just show a
necessary fragment of code.
arrow_forward
Assignment1: Analyse the case study given in chapter 3 Linked listAnswer the following questions from Library.java1. Write the different class names with class keyword
chapter 3 Linked list :
https://drive.google.com/file/d/1NRN_3Fx3smkjwv1jgG8hzaiGfnNfeeDb/view?usp=sharing
arrow_forward
data structure-JAVA
arrow_forward
JAVA CODE
arrow_forward
SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Related Questions
- In this assignment, you will create a Linked List data structure variant called a “Circular Linked List”. The Node structure is the same as discussed in the slides and defined as follows (we will use integers for data elements): public class Node { public int data; public Node next; } For the Circular Linked List, its class definition is as follows: public class CircularLinkedList { public int currentSize; public Node current; } In this Circular Linked List (CLL), each node has a reference to an existing next node. When Node elements are added to the CLL, the structure looks like a standard linked list with the last node’s next pointer always pointing to the first. In this way, there is no Node with a “next” pointer in the CLL that is ever pointing to null. For example, if a CLL has elements “5”, “3” and “4” and “current” is pointing to “3”, the CLL should look like: Key observations with this structure: The currentSize is 3 meaning there…arrow_forwardPlease show an example of how or how to solve coding the problem from Starting out with Java from control structures through data structures 4th edition: chapter 19 programming challenge 4arrow_forwardJava Programming Define a class CollectionBooks. This class has a data member list of type Book using the ArrayList collection. Define method add. This method add the any object to list. Define printAll. This method display all the added object in the list. Define printAll. This method display all the added object in the list. · Define int count. This method returns the number of objects added in the list. Define Book search(Object e). This method returns the object being search if not found return null. Define void remove(int index). This method remove the object in a list Add a main method with the following menu:1 – Add 2 – Count 3 – Print4 – Search 5 – Delete 6 - Exitarrow_forward
- 2 //please write it in java This is a circular doubly linked list. It starts at the head pointer (Head). Write a function that adds a node (P) at the nth location away from the Head keeping the circle connected. For example, based on the image, the list is: C, D, B, A After calling addNthNode(Head, P, 2), the list becomes C, F, D, B, A Note that if the position is 1 then the Head should be updated. Your code should validate parameters, and handle edge cases. void addNthNode (Node Head, Node P, int position){ // your code goes here }arrow_forwarddata structures in javaarrow_forward1. Create a doubly-linked list of string and add the following methods Add at the head b. Add at the tail Remove from head 4. Remove from tailarrow_forwardUnique Words Summary Specifications:You are tasked to implement an abstract data type class which takes in a given input file called input.txt, and processes, identifies and sorts all unique word instances found in the file. Sample InputHi hello hi good bye goodbye Bye bye good say Sample OutputBye Hi bye hello hi say The input.txt file is found along with the zip folder where this instructions file also came along with. Note: you are not allowed to use pythonic lists, and its methods and functions, and string methods. However the use of the file handling methods (read readlines and readline) are allowed for this project.arrow_forwardC++ A queue is essentially a waiting list. It’s a sequence of elements with a front and a back. Elements can only be added to the back of the queue and they can only be removed from the front of the queue. Elements are kept in order so that the first element to enter the queue is the first one to leave it.arrow_forwardReference-based Linked Lists: Select all of the following statements that are true. As a singly linked list's node references both its predecessor and its successor, it is easily possible to traverse such a list in both directions. According to the terminology introduced in class, the head reference variable in a singly linked list object references the list's first node. According to the terminology introduced in class, in a doubly linked list, each node references both the head and tail node. In a double-ended singly linked list, the tail reference variable provides access to the entire list. In a circular linked list, the last node references the first node.arrow_forwardQuestion 20 A list is a collection with additional index- and iteration- related operations. True False Question 21 O(N) is the order of growth execution time of the size operation when using the SortedArrayCollection class, assuming a collection size of N. True False Question 22 If N represents the number of elements in the list, then the index-based set method of the ABList class is O(1). True False Question 23 O(N) is the order of growth execution time of the remove operation when using the LinkedCollection class, assuming a collection size of N. True False Question 24 It is not possible to use an array to implement a linked list. True False Question 25 O(N) is the order of growth execution time of the remove operation when using the ArrayCollection class, assuming a collection size of N. True False Question 26 Our linked implementation of lists implements a bounded list. True False Question 27 O(N) is the order of growth execution time of the contains operation…arrow_forwardExercise 1• Create a class that sorts a list in ascending order. Make use of the Collections method sort• The list should be a list of Strings.• Test your code with {“Hearts”, “Diamonds”, “Clubs”, “Spades”}• Before and after the sort, use the implicit call to the list’s toString method to output the list contents. Exercise 2• Create a class with the same requirement as in Exercise 1, but the sort should be in descending order• Make use of the Comparator interface• Make use of the static collection method reverseOrder javaarrow_forwardPYTHON: Given a base Plant class and a derived Flower class, write a program to create a list called my_garden. Store objects that belong to the Plant class or the Flower class in the list. Create a function called print_list(), that uses the print_info() instance methods defined in the respective classes and prints each element in my_garden. The program should read plants or flowers from input (ending with -1), add each Plant or Flower to the my_garden list, and output each element in my_garden using the print_info() function.arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education