1.
Stack dapat disajikan dalam program menggunakan
Correct Answer(s)
A. Array
B. Linked list
Explanation
Stack dapat disajikan dalam program menggunakan Array dan Linked list. Array adalah struktur data yang dapat menyimpan elemen-elemen dalam urutan yang terdefinisi. Dalam implementasi stack menggunakan array, elemen-elemen stack disimpan dalam array dan operasi push dan pop dilakukan dengan memanipulasi indeks array. Linked list adalah struktur data yang terdiri dari node-node yang saling terhubung melalui pointer. Dalam implementasi stack menggunakan linked list, setiap elemen stack direpresentasikan sebagai node dan operasi push dan pop dilakukan dengan mengubah pointer yang menghubungkan node-node tersebut. Queue dan Tree bukanlah struktur data yang digunakan untuk merepresentasikan stack.
2.
Prinsip dari stack
Correct Answer(s)
A. Last in first out
D. First in last out
Explanation
The principle of a stack is based on the concept of "last in, first out" (LIFO). This means that the last item added to the stack will be the first one to be removed. On the other hand, "first in, last out" (FILO) is the opposite principle, where the first item added to the stack will be the last one to be removed. Therefore, the correct answer is Last in first out, as it accurately describes the behavior of a stack.
3.
Jika terdapat tumpukan 3 elemen, elemen tumpukan pertama adalah A, kedua B, ketiga C
Correct Answer(s)
C. Yang dapat diambil terlebih dahulu adalah C
D. Elemen A terakhir diambil
Explanation
The given correct answer states that the element that can be taken first is C, and the last element to be taken is A. This is because in a stack, the last element that is added is the first one to be removed (LIFO - Last In First Out). Since A was the first element to be added, it will be the last one to be removed. Therefore, C can be taken first before A.
4.
Operasi stack yang harus disiapkan jika diimplementasikan dalam array
Correct Answer(s)
A. Push
B. Pop
Explanation
The correct answer is "Push, Pop" because these operations are commonly used in a stack data structure. Push is used to add an element to the top of the stack, while Pop is used to remove the top element from the stack. These operations can be easily implemented using an array by keeping track of the index of the top element and updating it accordingly when performing push and pop operations.
5.
Operasi push yaitu
Correct Answer(s)
B. Operasi menambah elemen ke tumpukan
D. Dalam python dapat menggunakan fungsi append
Explanation
The correct answer is "operasi menambah elemen ke tumpukan, Dalam python dapat menggunakan fungsi append". This is because the operation of pushing refers to adding elements to a stack. In Python, the append() function can be used to add elements to a stack.
6.
Operasi pop yaitu
Correct Answer(s)
B. Menghapus elemen pada tumpukan
C. Dalam python menggunakan fungsi pop
Explanation
The given answer is correct because it accurately explains that the operation of "pop" in Python is used to remove an element from the stack. The explanation also mentions that this operation is performed by assigning the value of "top" to -1.
7.
Operasi isempty dalam stack adalah
Correct Answer(s)
A. Untuk memeriksa apakah stack kosong atau tidak
D. Jika kosong maka isempty = true
Explanation
The correct answer is "untuk memeriksa apakah stack kosong atau tidak, Jika kosong maka isempty = true". This is because the operation "isempty" in a stack is used to check whether the stack is empty or not. If the stack is empty, the value of "isempty" will be true.
8.
Diberikan variabel untuk menumpuk data yaitu x = [ ] pernyataan yang benar terkait operasi stack yaitu
Correct Answer(s)
A. Perintah menambah data ke dalam tumpukan yaitu x.append('A')
D. Perintah menambah data ke dalam tumpukan yaitu x.pop()
Explanation
The correct answer is "perintah menambah data ke dalam tumpukan yaitu x.append('A'), perintah menambah data ke dalam tumpukan yaitu x.pop()". This is because the append() function is used to add data to the top of the stack, while the pop() function is used to remove and return the topmost data from the stack. The statement "perintah menambah data ke dalam tumpukan yaitu push.append('A')" is incorrect because there is no variable named "push" mentioned in the given code. The statement "perintah menambah data ke dalam tumpukan yaitu x.pop('P')" is also incorrect because the pop() function does not take any arguments.
9.
Diberikan
tumpukan = [ ]
def tambah(nilai):
tumpukan.append(nilai)
def ambil():
tumpukan.pop()
def tampil(..?..):
print(..?..)
jika kita ingin menampilkan isi tumpukan maka titik-titik di atas diisi dengan
Correct Answer
B. Tumpukan
Explanation
The given program defines three functions: tambah, ambil, and tampil. The tambah function appends a value to the stack, the ambil function removes the top value from the stack, and the tampil function is used to display the contents of the stack. Therefore, if we want to display the contents of the stack, we need to fill in the blank with "tumpukan". This indicates that the correct answer is "tumpukan".
10.
Diberikan program berikut
tumpukan = [ ]
def tambah(nilai):
tumpukan.append(nilai)
def ambil():
tumpukan.pop()
jika kita ingin menambah isi tumpukan dengan nilai/data 'A' maka perintahnya
Correct Answer
C. Tambah('A')
Explanation
The correct answer is "tambah('A')". This is because the function "tambah(nilai)" is defined to add a value to the stack, and the parameter "nilai" represents the value to be added. Therefore, to add the value 'A' to the stack, we need to call the function "tambah('A')". The other options are incorrect because "tambah" is a function, not a list, so we cannot use the dot notation to call it.
11.
Jika top=len(tumpukan)-1 maka if top < 0 berarti
Correct Answer
A. Stack kosong
Explanation
If the top variable is equal to the length of the stack minus one, and if the top variable is less than zero, it means that the stack is empty.
12.
Class stack():
def __init__(self):
self.tumpukan = [ ]
def tambah(self, data):
self.tumpukan.append(data)
def tampil(self):
print(self.tumpukan)
membuat objek yang benar yaitu
Correct Answer
B. Objek = stack()
Explanation
The correct answer is "objek = stack()". This is because the given code defines a class named "stack" and the correct way to create an object of that class is by using the syntax "objek = stack()". This will create a new instance of the "stack" class and assign it to the variable "objek".
13.
Diketahui
tumpukan = [ ]
tumpukan.append('h')
tumpukan.append('i')
tumpukan.append('j')
maka len(tumpukan) = ...
Correct Answer
C. 3
Explanation
The given code initializes an empty stack called "tumpukan" and then appends three elements ('h', 'i', 'j') to the stack. The len() function is used to find the length of the stack, which is the number of elements in it. Since there are three elements in the stack, the correct answer is 3.
14.
Diberikan
tumpukan = [ ]
tumpukan.append('h')
tumpukan.append('i')
tumpukan.append('j')
print(tumpukan[1]) akan menghasilkan output ...
Correct Answer
B. I
Explanation
The given code creates a list called "tumpukan" and appends the elements 'h', 'i', and 'j' to it. The line "print(tumpukan[1])" prints the element at index 1 of the list, which is 'i'. Therefore, the output of the code will be "i".
15.
Pernyataan yang salah yaitu stack menggunakan python
Correct Answer
C. Elemen paling bawah dalam tumpukan yaitu stack[1]
Explanation
The given answer is incorrect because the statement "elemen paling bawah dalam tumpukan yaitu stack[1]" is wrong. In Python, the index of the first element in a list or stack is 0, not 1. Therefore, the correct statement should be "elemen paling bawah dalam tumpukan yaitu stack[0]".