2025 数据结构 选择题
第 2 题

对于括号匹配问题,符号栈初始为空,容量为 3,下列表达式不能实现的是( )。

A. (a+[b+(c+d)e]+f)+g-h B. [a*((b+c)/(d-e)+f/g)]-h C. [a*(b-(c-d)*e/(f+g))-h] D. [a-(b+[c*(d+e)-f]+g+h)]

[tag_link]

正确答案:D

栈的容量为 3,意味着在任何时候,栈中的元素数量不能超过 3。需要选择一个在某些时刻栈的深度超过 3 的表达式。通过分析各个选项的嵌套深度,可以发现:

  • A. (a+[b+(c+d)e]+f)+g-h
  • 最深嵌套:([(+)]),最多 3 个未匹配括号,正确。
  • B. [a*((b+c)/(d-e)+f/g)]-h
  • 最深嵌套:[(())],最多 3 个未匹配括号,正确。
  • C. [a*(b-(c-d)*e/(f+g))-h]
  • 最深嵌套:[()()],最多 3 个未匹配括号,正确。
  • D. [a-(b+[c*(d+e)-f]+g+h)]
  • 最深嵌套:[([])],最多 4 个未匹配括号,错误。